Skip to content

refactor: install the exception handler before startup - #983

Merged
albertospelta merged 2 commits into
mainfrom
refactor/crash-guard
Oct 20, 2026
Merged

albertospelta merged 2 commits into
mainfrom
refactor/crash-guard

Conversation

@albertospelta

Copy link
Copy Markdown
Member

Summary

The global exception handler is now installed right after the WinForms configuration, before directory and proxy
setup, the WebView2 runtime check and the bootstrap. A failure anywhere in startup, including an unreadable policy
registry key, now produces a saved report and a visible message instead of ending the process silently.

Changes

  • Program installs the handler before every other startup step. Until the bootstrap services exist, a fatal
    exception is saved to the report and shown in the dialog, without logging, telemetry or the Send button.
  • BootstrapContextFactory attaches the logger and telemetry to the handler when it creates the context;
    BootstrapContext detaches them before disposing them, so a late crash never uses disposed services. A detach
    releases only the services it attached.
  • If the task dialog fails, for example because a type it reads failed to initialize, a plain message box shows the
    error and the report path. The failure is logged once services are attached and no longer ends the process through
    FailFast.
  • The report folder is resolved only when a report is saved, so a failing AppEnvironment initialization still
    produces a dialog.
  • NullTelemetryService, used when telemetry cannot be created, counts as no telemetry: the dialog no longer offers a
    Send that always fails.
  • docs/design/diagnostics.md, docs/design/architecture.md and the consequences of ADR 0003 and ADR 0005 describe
    the new startup coverage.

Testing

  • Unit tests cover the handler before and after the services are attached, after they are detached, a failing dialog,
    an unavailable report folder and the attachment owned by BootstrapContext.
  • Manual: Debug build with BRAVO_CrashTest=startup (dialog before the bootstrap, no Send) and BRAVO_CrashTest=ui
    (dialog after the bootstrap).

The global exception handler is now installed right after the WinForms
configuration, before directory and proxy setup, the WebView2 runtime
check and the bootstrap. Until the bootstrap services are attached, a
fatal exception is saved to the report and shown in the dialog without
logging or telemetry, so a startup failure such as an unreadable policy
key is no longer silent.

A dialog that cannot be shown is logged instead of escaping the handler
and ending the process through FailFast.
- Show a plain message box when the task dialog fails, since the types
  it reads can be the cause of the crash.
- Resolve the report folder only when saving, so a failing AppEnvironment
  initialization still produces a dialog.
- Attach the bootstrap services to the exception handler when the
  context is created and detach them before they are disposed, so a late
  crash never flushes a disposed telemetry service. A detach releases
  only the services it attached.
- Treat NullTelemetryService as no telemetry, so the dialog does not
  offer a Send that always fails.
@albertospelta
albertospelta merged commit dfe1bb3 into main Oct 20, 2026
1 check passed
@albertospelta
albertospelta deleted the refactor/crash-guard branch October 20, 2026 12:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant