Skip to content

fix(notify): gracefully handle missing session file (#11)#12

Open
trentmcnitt wants to merge 1 commit into
mainfrom
fix/notify-missing-session-file
Open

fix(notify): gracefully handle missing session file (#11)#12
trentmcnitt wants to merge 1 commit into
mainfrom
fix/notify-missing-session-file

Conversation

@trentmcnitt
Copy link
Copy Markdown
Owner

Fixes #11.

Summary

  • Bug fix: cmd_notify no longer crashes with FileNotFoundError when the session file is missing. Previously, every Stop hook for a session that had no init file (e.g. cc-notifier was installed mid-session, or Claude Code bug #7911 caused a session-ID mismatch) produced a noisy [ERROR] Command 'notify' failed notification. It now falls through to the existing UNAVAILABLE path: skips dedup, picks up the current tmux session ID, and still attempts push.
  • README: spells out the missing Hammerspoon launch + hs.ipc.cliInstall() step. The reload command in the quick-start hangs forever if Hammerspoon isn't running or the CLI shim was never installed — issue Getting Error #11 reported exactly this. New troubleshooting note tells the user what to do.
  • install.sh hardening: previously only checked that the hs binary existed; now actually exercises hs -c 'print("ok")' with a 5s timeout (via perl -e 'alarm 5; exec @ARGV' since macOS has no portable timeout command) and bails with a clear pointer if Hammerspoon isn't reachable. This catches the issue Getting Error #11 setup failure at install time instead of letting it manifest as silent notification errors later.

Test plan

  • make check passes (format, lint, typecheck, 72/72 tests, deadcode, shell-lint)
  • New regression test test_notify_handles_missing_session_file asserts notify doesn't raise, still hits push, and doesn't write [ERROR] to the log when the session file is absent
  • Verified perl alarm timeout trick works on macOS (alarm preserved across exec, exit 142 on timeout)
  • Manual: install cc-notifier in a fresh state without launching Hammerspoon first — confirm install.sh now bails with a clear message instead of letting hs -c hang during reload
  • Manual: trigger Stop hook for a session that has no session file (e.g. delete /tmp/cc_notifier/$SESSION_ID then let Claude finish a task) — confirm no [ERROR] notification fires

When `cc-notifier notify` fired for a session that had no session file
on disk, it crashed with FileNotFoundError and produced a noisy "Command
'notify' failed" error notification on every Stop hook. The user in
issue #11 hit this because they installed cc-notifier mid-session — init
never ran for that session_id.

Changes:

- cc_notifier.py: cmd_notify now checks for the session file before
  reading. When missing, falls through to UNAVAILABLE (same path used
  when Hammerspoon isn't installed): skips dedup, picks up the current
  tmux session ID, lets the existing UNAVAILABLE branch decide local
  notification, and still attempts push.
- tests/test_core.py: regression test asserting notify doesn't raise,
  still hits push, and doesn't log an [ERROR] when the session file is
  absent.
- README.md: spell out the Hammerspoon launch + hs.ipc.cliInstall()
  step that was missing from the quick-start, with a note that the
  reload command hanging means this step was skipped.
- install.sh: actually exercise `hs -c` with a 5s timeout (via perl
  alarm — macOS has no portable `timeout` command) instead of only
  checking that the binary exists, so the install bails early with a
  clear pointer when Hammerspoon isn't reachable.
- Context files updated to reflect new behavior.
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.

Getting Error

1 participant