mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-08 02:53:25 -08:00
[CrashReporting] Attach crash log and user note to the pending crash event
The redacted log used to ride a separate message event from the native
crash (minidump + stack), forcing manual correlation in Sentry. Fold it
into the pending crash envelope(s) instead by appending well-formed
attachment items before consent releases them: sentry-native replays
cached envelopes byte-for-byte (raw read, raw serialize in 0.17.3), so
the appended crash-log.txt and user-note.txt items upload with the very
event that already carries the dump and stack.
Covers both storage locations: Ask mode's consent-held files in
<database>/cache and AlwaysSend's transport-dumped files in
<database>/<run>.run, which must be attached before sentry_init replays
them. When no pending crash event exists (unclean exit without a native
crash) the standalone message event remains as fallback, now also
carrying the optional note.
The dialog gains an optional free-text field ('Here's what I was
doing...') that travels as user-note.txt; the mock JSON records it too.
This commit is contained in:
parent
038e56aab6
commit
2a21c87e7c
6 changed files with 437 additions and 31 deletions
|
|
@ -34,6 +34,11 @@ DlgCrashReport::DlgCrashReport(QWidget *parent, bool _realSending, CrashReporter
|
|||
previewArea->setReadOnly(true);
|
||||
previewArea->setPlainText(buildRedactedPreview());
|
||||
|
||||
noteArea = new QPlainTextEdit(this);
|
||||
// Optional free text ("what I was doing when it crashed") — a few lines are
|
||||
// enough for a description, leave the rest of the space to the log excerpt.
|
||||
noteArea->setMaximumHeight(70);
|
||||
|
||||
rememberBox = new QCheckBox(this);
|
||||
|
||||
sendButton = new QPushButton(this);
|
||||
|
|
@ -53,6 +58,7 @@ DlgCrashReport::DlgCrashReport(QWidget *parent, bool _realSending, CrashReporter
|
|||
auto *mainLayout = new QVBoxLayout;
|
||||
mainLayout->addWidget(infoLabel);
|
||||
mainLayout->addWidget(accountLabel);
|
||||
mainLayout->addWidget(noteArea);
|
||||
mainLayout->addWidget(previewArea);
|
||||
mainLayout->addLayout(buttonLayout);
|
||||
setLayout(mainLayout);
|
||||
|
|
@ -92,6 +98,7 @@ void DlgCrashReport::retranslateUi()
|
|||
}
|
||||
accountLabel->setText(tr("No account needed, and no contact info is collected. Login links "
|
||||
"(cockatrice://...) are scrubbed before sending."));
|
||||
noteArea->setPlaceholderText(tr("Here's what I was doing when it crashed (optional)"));
|
||||
rememberBox->setText(tr("Remember my choice"));
|
||||
sendButton->setText(tr("Send"));
|
||||
dontSendButton->setText(tr("Don't send"));
|
||||
|
|
@ -122,7 +129,7 @@ QString DlgCrashReport::buildRedactedPreview()
|
|||
return lines.join(QStringLiteral("\n"));
|
||||
}
|
||||
|
||||
QString DlgCrashReport::writeMockReport(const QString &previewText)
|
||||
QString DlgCrashReport::writeMockReport(const QString &previewText, const QString &userNote)
|
||||
{
|
||||
Logger &logger = Logger::getInstance();
|
||||
|
||||
|
|
@ -134,6 +141,7 @@ QString DlgCrashReport::writeMockReport(const QString &previewText)
|
|||
report[QStringLiteral("systemLocale")] = logger.getSystemLocale();
|
||||
report[QStringLiteral("installInfo")] = logger.getClientInstallInfo();
|
||||
report[QStringLiteral("logPreview")] = previewText;
|
||||
report[QStringLiteral("userNote")] = userNote;
|
||||
|
||||
QString fileName = QStringLiteral("crash-report-mock-%1.json")
|
||||
.arg(QDateTime::currentDateTimeUtc().toString(QStringLiteral("yyyyMMdd-HHmmss")));
|
||||
|
|
@ -154,9 +162,17 @@ void DlgCrashReport::actSend()
|
|||
SettingsCache::instance().personal().setCrashReportingMode(PersonalSettings::CrashReportingMode::AlwaysSend);
|
||||
}
|
||||
const QString preview = previewArea->toPlainText();
|
||||
const QString userNote = noteArea->toPlainText().trimmed();
|
||||
if (realSending && reporter != nullptr) {
|
||||
// Fold log and note into the pending native crash event(s) BEFORE consent:
|
||||
// giveConsent() releases the held envelopes for upload, so dump, stack,
|
||||
// log and note arrive as one Sentry event. Without a pending crash event
|
||||
// (unclean exit that produced no native crash) this returns 0 and
|
||||
// sendReport() falls back to a standalone message event with the same
|
||||
// attachments.
|
||||
const int attached = reporter->attachToPendingCrashEnvelopes(preview, userNote);
|
||||
reporter->giveConsent();
|
||||
if (reporter->sendReport(preview)) {
|
||||
if (attached > 0 || reporter->sendReport(preview, userNote)) {
|
||||
accept();
|
||||
return;
|
||||
}
|
||||
|
|
@ -177,7 +193,7 @@ void DlgCrashReport::actSend()
|
|||
failureBox.setEscapeButton(QMessageBox::Cancel);
|
||||
const QMessageBox::StandardButton choice = static_cast<QMessageBox::StandardButton>(failureBox.exec());
|
||||
if (choice == QMessageBox::Save) {
|
||||
const QString savedPath = writeMockReport(preview);
|
||||
const QString savedPath = writeMockReport(preview, userNote);
|
||||
if (savedPath.isEmpty()) {
|
||||
QMessageBox::warning(this, tr("Send crash report"), tr("Could not save the crash report locally."));
|
||||
} else {
|
||||
|
|
@ -194,7 +210,7 @@ void DlgCrashReport::actSend()
|
|||
}
|
||||
return;
|
||||
}
|
||||
const QString savedPath = writeMockReport(preview);
|
||||
const QString savedPath = writeMockReport(preview, userNote);
|
||||
if (savedPath.isEmpty()) {
|
||||
qCWarning(CrashReportLog) << "Could not save the mock crash report locally";
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -22,8 +22,11 @@ class CrashReporter;
|
|||
*
|
||||
* Mock mode (default): the Send path writes a redacted JSON file to the temp
|
||||
* dir instead of uploading anything. Real mode (realSending, with a live
|
||||
* CrashReporter): Send gives consent and captures a redacted message event
|
||||
* with the log preview attached; failure offers a local save instead.
|
||||
* CrashReporter): Send first folds the redacted log and the optional user note
|
||||
* into the pending native crash event(s), then gives consent so dump, stack,
|
||||
* log and note upload as one Sentry event; when no pending crash event exists
|
||||
* it falls back to a standalone message event with the same attachments.
|
||||
* Failure offers a local save instead.
|
||||
*/
|
||||
class DlgCrashReport : public QDialog
|
||||
{
|
||||
|
|
@ -32,7 +35,7 @@ public:
|
|||
explicit DlgCrashReport(QWidget *parent = nullptr, bool realSending = false, CrashReporter *_reporter = nullptr);
|
||||
|
||||
static QString buildRedactedPreview();
|
||||
static QString writeMockReport(const QString &previewText);
|
||||
static QString writeMockReport(const QString &previewText, const QString &userNote = QString());
|
||||
|
||||
void reject() override;
|
||||
|
||||
|
|
@ -43,6 +46,7 @@ private:
|
|||
QLabel *infoLabel;
|
||||
QLabel *accountLabel;
|
||||
QPlainTextEdit *previewArea;
|
||||
QPlainTextEdit *noteArea;
|
||||
QCheckBox *rememberBox;
|
||||
QPushButton *sendButton;
|
||||
QPushButton *dontSendButton;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue