Skip to content

Log crashes and tell the user instead of vanishing - #167

Merged
danielchalmers merged 2 commits into
masterfrom
claude/crash-handling
Sep 22, 2026
Merged

danielchalmers merged 2 commits into
masterfrom
claude/crash-handling

Conversation

@danielchalmers

Copy link
Copy Markdown
Owner

An unhandled exception used to close the clock with no message, leaving only a .NET Runtime entry in Event Viewer. Now the first one, on the UI thread or a background thread like the clock's timer:

  1. Saves settings one last time, if they were loaded and can be saved.
  2. Appends the error to DesktopClock.log next to the app (named after the exe, like the settings file), or to %TEMP% if that folder can't be written to. Each entry has the time, app version, Windows and .NET versions, and the full stack trace. The log starts over past 1 MB.
  3. Shows one message: "DesktopClock ran into a problem and needs to close", where the log is, and where to report it.
  4. Exits. Carrying on in an unknown state could leave a clock that looks fine but has stopped.

A second crash while that's happening exits right away instead of stacking dialogs. No telemetry, uploads, dumps, or auto-restart.

Tested by running the real App (including its OnStartup registration) and MainWindow in-process and forcing crashes:

Case master this PR
UI-thread exception vanishes, exit 0xE0434352, no log, setting changed 0.3 s earlier lost one message, exit 1, log written, setting kept
Exception inside the clock's timer tick same same as above
App folder not writable n/a log goes to %TEMP%, message shows that path
Existing log over 1 MB n/a log starts over
Second crash while the message is open n/a exits immediately (5.6 s run vs 12.6 s with the message held open), one message, one log entry

A normal run creates no log, and the usual smoke test passes (launch, live reload, save on exit). The message text will need keys when the localization branch lands.

An unhandled exception closed the clock with no message, leaving only an entry in Event Viewer. Now the first one, on the UI thread or a background thread like the clock's timer, is appended to DesktopClock.log next to the app (or in the temp folder if that one can't be written to) with the time, version, Windows and .NET versions, and the stack trace. A message says where the log is and where to report it, then the app exits, since carrying on in an unknown state could leave a clock that looks fine but has stopped. A second crash while that's happening exits right away instead of stacking dialogs, and the log starts over past 1 MB.
Settings are saved a second after they change, so a crash within that second lost the last change. The crash handler now saves them first if they were loaded and can be saved, ignoring any error so it never gets in the way of logging. A setting changed 0.3 seconds before a crash is kept now.
@github-actions github-actions Bot added the enhancement New feature or request label Sep 22, 2026
@danielchalmers
danielchalmers merged commit 4e8d5d4 into master Sep 22, 2026
5 checks passed
@danielchalmers
danielchalmers deleted the claude/crash-handling branch September 22, 2026 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant