Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
QQmlJS::Dom::ErrorMessage Class Reference

Represents an error message connected to the dom. More...

#include <qqmldomerrormessage_p.h>

+ Collaboration diagram for QQmlJS::Dom::ErrorMessage:

Public Types

using Level = ErrorLevel
 

Public Member Functions

 ErrorMessage (QString message, ErrorGroups errorGroups, Level level=Level::Warning, Path path=Path(), QString file=QString(), SourceLocation location=SourceLocation(), QLatin1String errorId=QLatin1String(""))
 
 ErrorMessage (ErrorGroups errorGroups, const DiagnosticMessage &msg, Path path=Path(), QString file=QString(), QLatin1String errorId=QLatin1String(""))
 
ErrorMessagewithErrorId (QLatin1String errorId)
 
ErrorMessagewithPath (const Path &)
 
ErrorMessagewithFile (QString)
 
ErrorMessagewithFile (QStringView)
 
ErrorMessagewithLocation (SourceLocation)
 
ErrorMessagewithItem (DomItem)
 
ErrorMessage handle (const ErrorHandler &errorHandler=nullptr)
 
void dump (Sink s) const
 
QString toString () const
 
QCborMap toCbor () const
 

Static Public Member Functions

static QLatin1String msg (const char *errorId, ErrorMessage err)
 
static QLatin1String msg (QLatin1String errorId, ErrorMessage err)
 
static void visitRegisteredMessages (function_ref< bool(ErrorMessage)> visitor)
 
static ErrorMessage load (QLatin1String errorId)
 
static ErrorMessage load (const char *errorId)
 
template<typename... T>
static ErrorMessage load (QLatin1String errorId, T... args)
 

Public Attributes

QLatin1String errorId
 
QString message
 
ErrorGroups errorGroups
 
Level level
 
Path path
 
QString file
 
SourceLocation location
 

Friends

int compare (const ErrorMessage &msg1, const ErrorMessage &msg2)
 

Detailed Description

Represents an error message connected to the dom.

The error messages should be translated, but they do not need to be pre registered. To give a meaningful handling of error messages ErrorMessages have "tags" (ErrorGroup) that are grouped toghether in ErrorGroups.

To create an ErrorMessage from scratch the best way is to use one of the methods provided by an ErrorGroups object. For example create an ErrorGroups called myErrors and use it to create all your errors.

static ErrorGroups res({NewErrorGroup("StaticAnalysis"), NewErrorGroup("FancyDetector")});
return res;
}
Represents a set of tags grouping a set of related error messages.
static ErrorGroups myErrors()
GLuint res
#define NewErrorGroup(name)

You can preregister the errors giving them a unique name (reverse dns notation is encouraged) with the msg function. This unique name (errorId) is a const char* (QLatin1String) to integrate better with the tr function. Ideally you create variables to store the errorId either by creating variables with plain strings that you use to initialize the error messages

// in .h file
constexpr const char *myError0 = "my.company.error0";
// in some initialization function
ErrorMessage::msg(myError0, myErrors().warning(tr("Error number 0")));
static QLatin1String msg(const char *errorId, ErrorMessage err)
#define tr(X)

or using the result of the msg function

// in cpp file
static auto myError1 = ErrorMessage::msg("my.company.error1", myErrors().warning(tr("Error number 1")));
static auto myError2 = ErrorMessage::msg("my.company.error2", myErrors().error(tr("Error number 2 on %1")));
DBusConnection const char DBusError * error

and then use them like this

ErrorMessage::load(myError2, QLatin1String("extra info")).handle(errorHandler);
ErrorMessage handle(const ErrorHandler &errorHandler=nullptr)
static ErrorMessage load(QLatin1String errorId)
QLatin1StringView QLatin1String
Definition qstringfwd.h:31

or using directly the string (more error prone)

errorHandler(ErrorMessage::load(QLatin1String("my.company.error1")));

The \l{withItem} method can be used to set the path file and location if not aready set.

Definition at line 96 of file qqmldomerrormessage_p.h.

Member Typedef Documentation

◆ Level

Constructor & Destructor Documentation

◆ ErrorMessage() [1/2]

QQmlJS::Dom::ErrorMessage::ErrorMessage ( QString  message,
ErrorGroups  errorGroups,
Level  level = Level::Warning,
Path  path = Path(),
QString  file = QString(),
SourceLocation  location = SourceLocation(),
QLatin1String  errorId = QLatin1String("") 
)

Definition at line 251 of file qqmldomerrormessage.cpp.

References errorGroups, QQmlJS::Dom::ErrorGroups::fatal(), and msg().

+ Here is the call graph for this function:

◆ ErrorMessage() [2/2]

QQmlJS::Dom::ErrorMessage::ErrorMessage ( ErrorGroups  errorGroups,
const DiagnosticMessage msg,
Path  path = Path(),
QString  file = QString(),
QLatin1String  errorId = QLatin1String("") 
)

Definition at line 258 of file qqmldomerrormessage.cpp.

References errorGroups, QQmlJS::Dom::ErrorGroups::fatal(), and msg().

+ Here is the call graph for this function:

Member Function Documentation

◆ dump()

void QQmlJS::Dom::ErrorMessage::dump ( Sink  s) const

Definition at line 407 of file qqmldomerrormessage.cpp.

References QQmlJS::Dom::ErrorGroups::dump(), QQmlJS::Dom::dumpErrorLevel(), errorGroups, errorId, file, QString::isEmpty(), QLatin1StringView::isEmpty(), and QQmlJS::Dom::sinkInt().

Referenced by toString().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handle()

ErrorMessage QQmlJS::Dom::ErrorMessage::handle ( const ErrorHandler errorHandler = nullptr)

Definition at line 398 of file qqmldomerrormessage.cpp.

References QQmlJS::Dom::defaultErrorHandler().

Referenced by QQmlJS::Dom::DomUniverse::execQueue(), QQmlJS::Dom::Path::fromString(), QQmlJS::Dom::Paths::moduleIndexPath(), and QQmlJS::Dom::Paths::moduleScopePath().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ load() [1/3]

ErrorMessage QQmlJS::Dom::ErrorMessage::load ( const char *  errorId)
static

Definition at line 349 of file qqmldomerrormessage.cpp.

References errorId, and load().

+ Here is the call graph for this function:

◆ load() [2/3]

ErrorMessage QQmlJS::Dom::ErrorMessage::load ( QLatin1String  errorId)
static

Definition at line 337 of file qqmldomerrormessage.cpp.

References QQmlJS::Dom::ErrorGroups::error(), errorId, QQmlJS::Dom::myErrors(), QQmlJS::Dom::registry(), and QQmlJS::Dom::registryMutex().

Referenced by load().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ load() [3/3]

template<typename... T>
static ErrorMessage QQmlJS::Dom::ErrorMessage::load ( QLatin1String  errorId,
T...  args 
)
inlinestatic

Definition at line 108 of file qqmldomerrormessage_p.h.

References args, and load().

+ Here is the call graph for this function:

◆ msg() [1/2]

QLatin1String QQmlJS::Dom::ErrorMessage::msg ( const char *  errorId,
ErrorMessage  err 
)
static

Definition at line 299 of file qqmldomerrormessage.cpp.

References errorId, and msg().

Referenced by ErrorMessage(), ErrorMessage(), msg(), and msg().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ msg() [2/2]

QLatin1String QQmlJS::Dom::ErrorMessage::msg ( QLatin1String  errorId,
ErrorMessage  err 
)
static

Definition at line 304 of file qqmldomerrormessage.cpp.

References arg, QQmlJS::Dom::ErrorGroups::debug(), QQmlJS::Dom::defaultErrorHandler(), errorId, msg(), QQmlJS::Dom::myErrors(), QQmlJS::Dom::registry(), QQmlJS::Dom::registryMutex(), toString(), tr, and withErrorId().

+ Here is the call graph for this function:

◆ toCbor()

QCborMap QQmlJS::Dom::ErrorMessage::toCbor ( ) const

Definition at line 442 of file qqmldomerrormessage.cpp.

References errorGroups, errorId, file, QStringLiteral, and QQmlJS::Dom::ErrorGroups::toCbor().

+ Here is the call graph for this function:

◆ toString()

QString QQmlJS::Dom::ErrorMessage::toString ( ) const

Definition at line 437 of file qqmldomerrormessage.cpp.

References dump(), and QQmlJS::Dom::dumperToString().

Referenced by msg().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ visitRegisteredMessages()

void QQmlJS::Dom::ErrorMessage::visitRegisteredMessages ( function_ref< bool(ErrorMessage)>  visitor)
static

Definition at line 322 of file qqmldomerrormessage.cpp.

References QSet< T >::cbegin(), it, QQmlJS::Dom::registry(), and QQmlJS::Dom::registryMutex().

+ Here is the call graph for this function:

◆ withErrorId()

ErrorMessage & QQmlJS::Dom::ErrorMessage::withErrorId ( QLatin1String  errorId)

Definition at line 354 of file qqmldomerrormessage.cpp.

References errorId.

Referenced by msg().

+ Here is the caller graph for this function:

◆ withFile() [1/2]

ErrorMessage & QQmlJS::Dom::ErrorMessage::withFile ( QString  f)

Definition at line 366 of file qqmldomerrormessage.cpp.

References file.

Referenced by QQmlJS::Dom::QmlFile::QmlFile().

+ Here is the caller graph for this function:

◆ withFile() [2/2]

ErrorMessage & QQmlJS::Dom::ErrorMessage::withFile ( QStringView  f)

Definition at line 372 of file qqmldomerrormessage.cpp.

References file.

◆ withItem()

ErrorMessage & QQmlJS::Dom::ErrorMessage::withItem ( DomItem  el)

Definition at line 384 of file qqmldomerrormessage.cpp.

References el, file, QQmlJS::Dom::FileLocations::fileLocationsOf(), and QString::isEmpty().

+ Here is the call graph for this function:

◆ withLocation()

ErrorMessage & QQmlJS::Dom::ErrorMessage::withLocation ( SourceLocation  loc)

Definition at line 378 of file qqmldomerrormessage.cpp.

◆ withPath()

ErrorMessage & QQmlJS::Dom::ErrorMessage::withPath ( const Path path)

Definition at line 360 of file qqmldomerrormessage.cpp.

References path.

Referenced by QQmlJS::Dom::QmlFile::QmlFile(), and QQmlJS::Dom::ModuleIndex::exportsWithNameAndMinorVersion().

+ Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ compare

int compare ( const ErrorMessage msg1,
const ErrorMessage msg2 
)
friend

Definition at line 129 of file qqmldomerrormessage_p.h.

Member Data Documentation

◆ errorGroups

ErrorGroups QQmlJS::Dom::ErrorMessage::errorGroups

Definition at line 172 of file qqmldomerrormessage_p.h.

Referenced by ErrorMessage(), ErrorMessage(), dump(), and toCbor().

◆ errorId

QLatin1String QQmlJS::Dom::ErrorMessage::errorId

◆ file

QString QQmlJS::Dom::ErrorMessage::file

Definition at line 175 of file qqmldomerrormessage_p.h.

Referenced by dump(), toCbor(), withFile(), withFile(), and withItem().

◆ level

Level QQmlJS::Dom::ErrorMessage::level

Definition at line 173 of file qqmldomerrormessage_p.h.

Referenced by QmlLsp::QmlLintSuggestions::diagnose().

◆ location

SourceLocation QQmlJS::Dom::ErrorMessage::location

Definition at line 176 of file qqmldomerrormessage_p.h.

Referenced by QmlLsp::QmlLintSuggestions::diagnose().

◆ message

QString QQmlJS::Dom::ErrorMessage::message

Definition at line 171 of file qqmldomerrormessage_p.h.

Referenced by QmlLsp::QmlLintSuggestions::diagnose().

◆ path

Path QQmlJS::Dom::ErrorMessage::path

Definition at line 174 of file qqmldomerrormessage_p.h.

Referenced by withPath().


The documentation for this class was generated from the following files: