FOSSredder 0.5.0
Loading...
Searching...
No Matches
QmlDiagnostics.cpp
Go to the documentation of this file.
1
5
7
8#include <QObject>
9#include <QQmlEngine>
10#include <QQmlError>
11#include <QQuickView>
12
13#include <memory>
14#include <string>
15
20
21namespace ui::bootstrap {
22namespace {
23
24core::errors::ErrorContext qmlErrorContext(const QQmlError& error) {
26 context.emplace_back(ui::observability::context::kUrl,
27 error.url().toString().toStdString());
28 context.emplace_back(ui::observability::context::kLine,
29 std::to_string(error.line()));
30 context.emplace_back(ui::observability::context::kColumn,
31 std::to_string(error.column()));
32 return context;
33}
34
35void reportQmlError(core::ports::diagnostics::IErrorReporter* reporter,
36 core::errors::ErrorSeverity severity, const char* code,
37 const char* origin, const QQmlError& error) {
38 core::errors::report(reporter, severity, code, origin,
39 error.toString().toStdString(),
40 qmlErrorContext(error));
41}
42
43} // namespace
44
45void reportQmlLoadErrors(QQuickView* quickView, const QUrl& source,
47 if (!quickView || quickView->status() != QQuickView::Error) {
48 return;
49 }
50
51 const auto errors = quickView->errors();
52 if (errors.isEmpty()) {
54 reporter,
58 "QQuickView failed to load the main QML source",
59 {{ui::observability::context::kUrl, source.toString().toStdString()}});
60 return;
61 }
62
63 for (const auto& error : errors) {
64 reportQmlError(reporter, core::errors::ErrorSeverity::Error,
67 }
68}
69
71 QQmlEngine* engine, QObject* context,
72 std::shared_ptr<core::ports::diagnostics::IErrorReporter> reporter) {
73 if (!engine || !context) {
74 return;
75 }
76
77 QObject::connect(engine, &QQmlEngine::warnings, context,
78 [reporter = std::move(reporter)](
79 const QList<QQmlError>& warnings) {
80 for (const auto& warning : warnings) {
81 reportQmlError(
85 }
86 });
87}
88
89} // namespace ui::bootstrap
Provides shared helpers for reporting structured errors and exceptions.
Declarations for the UI Origins component.
QML runtime diagnostics reporting helpers.
Declarations for the UI Trace component.
Port for reporting structured diagnostic error events.
ErrorSeverity
Severity level for structured error events.
Definition ErrorEvent.h:17
std::vector< std::pair< std::string, std::string > > ErrorContext
Key/value context attached to an error event.
Definition ErrorEvent.h:27
void report(core::ports::diagnostics::IErrorReporter *reporter, const ErrorEvent &event)
Report an already constructed error event when a reporter exists.
void reportQmlLoadErrors(QQuickView *quickView, const QUrl &source, core::ports::diagnostics::IErrorReporter *reporter)
Reports QQuickView load errors through the structured error reporter.
void wireQmlWarnings(QQmlEngine *engine, QObject *context, std::shared_ptr< core::ports::diagnostics::IErrorReporter > reporter)
Wires QQmlEngine runtime warnings into structured error reporting.
constexpr auto kColumn
Definition Trace.h:22
constexpr auto kUrl
Definition Trace.h:40
constexpr auto kLine
Definition Trace.h:31
Declarations for the UI ErrorCodes component.