1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-08-10 22:11:50 +02:00

Desktop: Fixes #11871: Put crash dump files at the platform-compliant locations (#12839)

This commit is contained in:
w568w
2025-08-06 18:08:29 +08:00
committed by GitHub
parent 8c8a38e704
commit 72f8ebe4ff
4 changed files with 43 additions and 5 deletions

View File

@@ -8,8 +8,8 @@ import { urlDecode } from '@joplin/lib/string-utils';
import * as Sentry from '@sentry/electron/main';
import { homedir } from 'os';
import { msleep } from '@joplin/utils/time';
import { pathExists, pathExistsSync, writeFileSync } from 'fs-extra';
import { extname, normalize } from 'path';
import { pathExists, pathExistsSync, writeFileSync, ensureDirSync } from 'fs-extra';
import { extname, normalize, join } from 'path';
import isSafeToOpen from './utils/isSafeToOpen';
import { closeSync, openSync, readSync, statSync } from 'fs';
import { KB } from '@joplin/utils/bytes';
@@ -67,6 +67,30 @@ export class Bridge {
this.logFilePath_ = v;
}
private getCrashDumpDirectory(): string {
try {
const platformName = shim.platformName();
switch (platformName) {
case 'win32':
// Windows: Use %LOCALAPPDATA%\CrashDumps
return join(process.env.LOCALAPPDATA || join(homedir(), 'AppData', 'Local'), 'CrashDumps');
case 'darwin':
// macOS: Use ~/Library/Logs/DiagnosticReports
return join(homedir(), 'Library', 'Logs', 'DiagnosticReports');
case 'linux':
// Linux: Use XDG_STATE_HOME (for logs) or fallback to ~/.local/state
return join(process.env.XDG_STATE_HOME || join(homedir(), '.local', 'state'), 'joplin');
default:
// For unknown platforms, default to the home directory
return homedir();
}
} catch (error) {
// If we can't get the platform name, fallback to the home directory
return homedir();
}
}
private sentryInit() {
const getLogLines = () => {
try {
@@ -109,7 +133,10 @@ export class Bridge {
log: logAttachment ? logAttachment.data.trim().split('\n') : [],
};
writeFileSync(`${homedir()}/joplin_crash_dump_${date}.json`, JSON.stringify(errorEventWithLog, null, '\t'), 'utf-8');
const crashDumpDir = this.getCrashDumpDirectory();
ensureDirSync(crashDumpDir);
const crashDumpPath = join(crashDumpDir, `joplin_crash_dump_${date}.json`);
writeFileSync(crashDumpPath, JSON.stringify(errorEventWithLog, null, '\t'), 'utf-8');
} catch (error) {
// Ignore the error since we can't handle it here
}

View File

@@ -195,3 +195,4 @@ orderedmap
labelledby
isTextblock
deflt
LOCALAPPDATA

View File

@@ -17,7 +17,7 @@ Make sure you disable debugging once you've finished. Leaving it enabled can cau
### Crash reports
When the application crashes, a report is created in your [home directory](https://github.com/laurent22/joplin/blob/dev/readme/apps/home_directory.md) under the name `joplin_crash_dump_<DATE_TIME>.json`. If you experience a crash please share this log with the team by posting it to the [forum](https://discourse.joplinapp.org/), [GitHub](https://github.com/laurent22/joplin/issues) or [by email](https://raw.githubusercontent.com/laurent22/joplin/dev/Assets/AdresseSupport.png). You may also enable crash report auto-upload in the [Configuration screen](https://github.com/laurent22/joplin/blob/dev/readme/apps/config_screen.md) in the "Application" section.
When the application crashes, a report is created in your [crash report directory](https://github.com/laurent22/joplin/blob/dev/readme/apps/home_directory.md) under the name `joplin_crash_dump_<DATE_TIME>.json`. If you experience a crash please share this log with the team by posting it to the [forum](https://discourse.joplinapp.org/), [GitHub](https://github.com/laurent22/joplin/issues) or [by email](https://raw.githubusercontent.com/laurent22/joplin/dev/Assets/AdresseSupport.png). You may also enable crash report auto-upload in the [Configuration screen](https://github.com/laurent22/joplin/blob/dev/readme/apps/config_screen.md) in the "Application" section.
### Safe mode

View File

@@ -7,3 +7,13 @@ Joplin stores some data in your home directory, such as your profile and certain
| Windows | `C:\\Users\\(username)` | `%UserProfile%` |
| Linux | `/home/(username)` | `$HOME` |
| macOS | `/Users/(Username)` | `$HOME` |
## Crash report directory
When Joplin crashes, it generates a crash report that can help diagnose the issue. The location of these crash reports varies by operating system:
| Operating System | Path | Environment Variable |
| --- | --- | --- |
| Windows | `C:\\Users\\(username)\\AppData\\Local\\CrashDumps` | `%LocalAppData%\CrashDumps` |
| Linux | `/home/(username)/.local/state/joplin` | `$XDG_STATE_HOME/joplin` |
| macOS | `/Users/(Username)/Library/Logs/DiagnosticReports` | `$HOME/Library/Logs/DiagnosticReports` |