Skip to content

Panics are logged on every system, not only on Windows - #300

Merged
pitis merged 4 commits into
mainfrom
fix/panic-log-everywhere
Nov 29, 2026
Merged

pitis merged 4 commits into
mainfrom
fix/panic-log-everywhere

Conversation

@pitis

@pitis pitis commented Nov 29, 2026 •

Copy link
Copy Markdown
Owner

What changed

  • The panic hook from On Windows Hush writes a small log file, panics too, since it has no console #289 is installed on every system, not only on Windows: sig_core::logging::init (the desktop app's first line, and Client::open) now calls log_panics everywhere. A panic is logged as panicked at <file>:<line>:<col>: <message> through the same scrubbed log. std's own hook (its thread '…' panicked at … on stderr, with a backtrace under RUST_BACKTRACE=1) then runs only in a debug build: it prints the message as it is, ids and all, so a release build logs only the scrubbed line (the rule that ids stay out of logs, Group keys and contact ids stay out of logs, file names, notifications and preferences #176). Where the line goes:
  • core/sig-core/src/logging.rs: the two cfg gates (#[cfg(windows)] on the call, #[cfg(any(windows, test))] on log_panics) are gone, and the module doc says panics go with the log on every system.
  • README (Download): where the log, a panic too, is on each system: macOS log show --predicate 'subsystem == "dev.pitis.hush"' --last 1h in Terminal, or Console.app live; Linux stderr (~/.local/bin/hush in a terminal), from the launcher usually the user journal (journalctl --user -b); Windows hush.log (already there). Development: a panic is one scrubbed line on every system; only a debug build (make run, cargo run) also prints Rust's report, with a backtrace under RUST_BACKTRACE=1.

Why

Owner's decision of 2026-11-29: a Hush.app opened from Finder, or Hush started from a Linux launcher, had nowhere to print a panic.

Re-checked against the code

  • The issue's "the existing panic test runs on every system": the test already ran everywhere, but it called log_panics directly, so it never showed that init installs the hook. It now calls init (as the app does) and checks the panic is logged exactly once (it was "any", with a note that Windows could log it twice; with the hook only under init's Once there is one).

How it was tested

  • Test first: a_panic_is_logged_with_its_place_and_scrubbed through init, run on macOS before the change: failed (left: 0, right: 1, no panic line); after it: passes.
  • The real oslog path: a throwaway test (not committed) called init and panicked inside catch_unwind with no test subscriber, so the line went to the global oslog layer; then /usr/bin/log show --predicate 'subsystem == "dev.pitis.hush"' had [dev.pitis.hush:core] panicked at sig-core/src/logging.rs:463:45: probe-298 with <redacted> (the UUID in the message blanked).
  • Gate on the final head 88dc932 (main c3f74e7 merged in with make update): make format no changes, make check passes: cargo fmt --check, both clippy runs (-D warnings, plain and --features hush-desktop/snapshot), cargo test --features hush-desktop/snapshot (402 + 553 passed, 4 ignored). An earlier run failed only a_long_history_draws_as_fast_as_a_short_one, a frame-time ratio test, at load average ~150 from other builds; it passes at normal load.
  • The debug-only call has no test: it is an inline cfg!(debug_assertions), and checking a release build's panic in cargo test would mean a release build of the core; the debug side is what the panic test runs.
  • Not run: Linux and Windows (no change to their paths besides the hook now being on for Linux; Windows is as in On Windows Hush writes a small log file, panics too, since it has no console #289).

Closes #298

The panic hook now starts with the log everywhere: on macOS a panic reaches
the unified log, on Linux stderr, on Windows hush.log as before. The panic
test goes through init, and the README says where the log is on each system.
…nux binary is

Also: the panic comments say std's hook prints the panic unscrubbed, and why
the test expects one line.
@pitis

pitis commented Nov 29, 2026

Copy link
Copy Markdown
Owner Author

Review (pr-review-toolkit: code, tests, comments/docs, failure paths) and what was done

Fixed in acd0c42:

  • Important (docs): Console.app can't show a past panic. It shows the log only while it streams. The README now says log show … in Terminal, or Console.app live (Start streaming, then search for subsystem dev.pitis.hush).
  • Important (docs): Linux "run hush in a terminal" came before the install steps, and ~/.local/bin may not be on PATH yet (the README already gives the launcher an absolute path for that reason). The sentence now comes after the install block and says ~/.local/bin/hush.
  • Suggestion (comments): taken. The module doc puts "every panic" in its first list, so it can't be read as "elsewhere" only. The test's comment says why it expects exactly one line (init hooks once, however many tests open a core). log_panics's doc says std's hook prints the panic unscrubbed, to stderr.

Declined:

  • Critical (docs): "log is a zsh builtin, so log show fails in Terminal." Checked, and that's not so in Terminal: Apple's /etc/zshrc (line 13) runs disable log for interactive shells, and zsh -ic 'whence -w log' says command. Only a non-interactive zsh -f shadows it. The README keeps log show, the command the issue names.
  • Suggestion (failure paths): call std's hook first, then log. That would get std's stderr report out even if the logging stack itself hung or panicked. The only paths found need a span and a broken invariant inside tracing-oslog, and the app logs no spans that pass the filter. The ticket asks for std's output after the log line, so the order stays.
  • Suggestion (docs): journalctl --user -b -g panicked. Not taken: the README sentence is about the whole log, panics included.
  • Suggestion (tests): test that the previous hook is still called. Not taken: it would mean swapping the process-wide hook in a test, racing other tests' panics.

For the owner (product call, unchanged here):

  • On Linux, stderr gets each panic twice: the log's scrubbed line, then std's raw one. The journal then keeps both. This isn't new: std always printed the raw panic to stderr. Panics are logged on every system, not only on Windows #298 asks to keep std's hook. Skipping before(panic) where stderr is already the log would drop the raw copy, and with it std's backtrace hint. macOS (a Finder-launched app's stderr is /dev/null) and Windows (no console) aren't affected.

Gate after the fixes, on the head merged with main (make update: already up to date with origin/main f85a957): make format (no changes), make check passes on acd0c42: cargo fmt --check, both clippy runs (-D warnings, plain and --features hush-desktop/snapshot), cargo test --features hush-desktop/snapshot (402 + 553 passed, 4 ignored). The run before it failed only a_long_history_draws_as_fast_as_a_short_one, a frame-time ratio test, with the machine at load average ~150 from other builds (55–138 ms against 17 ms); rerun at normal load, it passed with everything else.

@pitis

pitis commented Nov 29, 2026

Copy link
Copy Markdown
Owner Author

Main moved to c3f74e7 (the release workflow's protoc, #301) after the gate above: merged it in with make update (48ec2e3) and gated again on that head: make format no changes, make check passes (fmt, both clippy runs, 402 + 553 tests).

std's hook prints the panic as it is, ids and all: only a debug build still
calls it, for its report and RUST_BACKTRACE backtrace.
@pitis

pitis commented Nov 29, 2026

Copy link
Copy Markdown
Owner Author

Owner's ruling on the raw duplicate (the rule that ids stay out of logs, #176), done in 88dc932: std's own hook now runs only in a debug build (cfg!(debug_assertions)), on every system, so a release build logs a panic only as its scrubbed line. The hook's doc and the README (Development) say a debug build (make run, cargo run) also prints Rust's report to stderr, with a backtrace under RUST_BACKTRACE=1. No test of that branch: it is an inline cfg!, and a release-mode check in cargo test would mean a release build of the core; the panic test still covers the debug side. Gate on 88dc932 (origin/main c3f74e7 merged): make format no changes, make check passes (fmt, both clippy runs, 402 + 553 tests).

@pitis
pitis merged commit 28e6d7e into main Nov 29, 2026
@pitis
pitis deleted the fix/panic-log-everywhere branch November 29, 2026 22:54
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.

Panics are logged on every system, not only on Windows

1 participant