Cockatrice 2026-10-19-Development-3.1.2-beta.2
A virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
crash_reporter.h
Go to the documentation of this file.
1
5
6#ifndef CRASH_REPORTER_H
7#define CRASH_REPORTER_H
8
9#include <QByteArray>
10#include <QLoggingCategory>
11#include <QString>
12#include <QStringList>
14#include <memory>
15
16#ifndef COCKATRICE_WITH_CRASH_REPORTING
17#define COCKATRICE_WITH_CRASH_REPORTING 0
18#endif
19
20#ifndef COCKATRICE_SENTRY_DSN
21#define COCKATRICE_SENTRY_DSN ""
22#endif
23
24#ifndef COCKATRICE_SENTRY_RELEASE
25#define COCKATRICE_SENTRY_RELEASE ""
26#endif
27
28class QLockFile;
29
31
60{
61public:
63 CrashReporter(const CrashReporter &) = delete;
68
69 void init(const QString &dsn,
70 const QString &release,
71 const QString &databasePath,
73 [[nodiscard]] bool isReady() const;
74 void shutdown();
75 void giveConsent();
76 void revokeConsent();
77 bool sendReport(const QString &redactedPreview, const QString &userNote = QString());
78
94 int attachToPendingCrashEnvelopes(const QString &redactedLogText, const QString &userNoteText);
95 static int attachToPendingCrashEnvelopes(const QString &databasePath,
96 const QString &redactedLogText,
97 const QString &userNoteText);
98
110 static bool
111 appendAttachmentToEnvelope(const QString &envelopePath, const QString &filename, const QByteArray &payload);
112
122 static QStringList pendingEnvelopePaths(const QString &databasePath);
123
127 static bool isReportingEnabled(const QString &dsn, PersonalSettings::CrashReportingMode consentMode);
128
138 static bool isDsnWellFormed(const QString &dsn);
139
145 static QString describeDsn(const QString &dsn);
146
157 static QString describeOriginMismatch(const QString &envelopePath, const QString &currentDsn);
158
164 bool beginSession(const QString &dir);
165 void endSession();
166
167 static QString sanitizeLogLine(const QString &line);
168 static QString redactCockatriceUrls(const QString &line);
169
170private:
171 bool ready = false;
174 std::unique_ptr<QLockFile> sessionLock;
175};
176
177#endif
static bool isReportingEnabled(const QString &dsn, PersonalSettings::CrashReportingMode consentMode)
SDK-independent gating decision, unit-testable in OFF builds.
Definition crash_reporter.cpp:220
static bool isDsnWellFormed(const QString &dsn)
Whether a DSN has the shape the build and the SDK require: <scheme>://<key><host>/<project-id>.
Definition crash_reporter.cpp:178
int attachToPendingCrashEnvelopes(const QString &redactedLogText, const QString &userNoteText)
Append the redacted log (and optional user note) to every pending native crash envelope in the local ...
Definition crash_reporter.cpp:553
CrashReporter(const CrashReporter &)=delete
static QString sanitizeLogLine(const QString &line)
Definition crash_reporter.cpp:586
void giveConsent()
Definition crash_reporter.cpp:378
void revokeConsent()
Definition crash_reporter.cpp:387
QString sessionLockPath
Definition crash_reporter.h:173
bool isReady() const
Definition crash_reporter.cpp:290
static QStringList pendingEnvelopePaths(const QString &databasePath)
Pending crash envelopes in <database>: the consent-held files in <database>/cache and the in-flight f...
Definition crash_reporter.cpp:505
CrashReporter(CrashReporter &&)=delete
bool beginSession(const QString &dir)
Claim this process's session lock, reporting a previous unclean exit.
Definition crash_reporter.cpp:308
void endSession()
Definition crash_reporter.cpp:364
QString sentryDatabasePath
Definition crash_reporter.h:172
static QString describeDsn(const QString &dsn)
Human-readable destination of a DSN, e.g. "o0.ingest.sentry.io (project 1234567)".
Definition crash_reporter.cpp:183
CrashReporter & operator=(const CrashReporter &)=delete
std::unique_ptr< QLockFile > sessionLock
Definition crash_reporter.h:174
static QString describeOriginMismatch(const QString &envelopePath, const QString &currentDsn)
Describe the captured-for DSN of a pending envelope when it points at a different destination than th...
Definition crash_reporter.cpp:193
void shutdown()
Definition crash_reporter.cpp:295
void init(const QString &dsn, const QString &release, const QString &databasePath, PersonalSettings::CrashReportingMode consentMode)
Definition crash_reporter.cpp:225
static QString redactCockatriceUrls(const QString &line)
Definition crash_reporter.cpp:595
static bool appendAttachmentToEnvelope(const QString &envelopePath, const QString &filename, const QByteArray &payload)
Append one attachment item to a cached Sentry envelope file.
Definition crash_reporter.cpp:463
bool ready
Definition crash_reporter.h:171
bool sendReport(const QString &redactedPreview, const QString &userNote=QString())
Definition crash_reporter.cpp:402
CrashReporter & operator=(CrashReporter &&)=delete
CrashReportingMode
Definition personal_settings.h:28
Q_DECLARE_LOGGING_CATEGORY(CrashReportLog)