Skip to content

fix: add error context to silent catches and debugger detection#1479

Merged
kevincodex1 merged 2 commits into
Gitlawb:mainfrom
skyhighbg22-jpg:fix/developer-experience
Jun 8, 2026
Merged

fix: add error context to silent catches and debugger detection#1479
kevincodex1 merged 2 commits into
Gitlawb:mainfrom
skyhighbg22-jpg:fix/developer-experience

Conversation

@skyhighbg22-jpg

@skyhighbg22-jpg skyhighbg22-jpg commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Replace silent catch handlers and remove dead debug code so failures and stale instrumentation are no longer hidden.

main.tsx

  • migrateChangelogFromConfig().catch(() => {}) now logs the error via logError (with the original error as cause). Migration still retries on the next startup, but the failure is now visible.
  • Debugger-detection branch now writes a stderr message before process.exit(1) so users see why the process exited.
  • Silent catch block in logManagedSettings now calls logForDebugging instead of swallowing the error.
  • Three void getSystemContext() calls now use .catch(logError) so git-hook/config failures are surfaced.

src/utils/worktree.ts

  • Two diagnostic console.log call sites (Using worktree via hook: ... and Created worktree: ... (based on ...)) are converted to logForDebugging. They were diagnostic noise that polluted stdout in normal use; routing them through the debug log pipeline lets the matching biome-ignore comments go away.
  • The iTerm2 tip console.log further down is intentionally user-facing guidance and is left untouched.

src/utils/fileHistory.ts

  • Removed the dead ENABLE_DUMP_STATE flag (hard-coded to false) and its maybeDumpStateForDebug helper, both call sites in fileHistoryTrackEdit / fileHistoryMakeSnapshot, and the now-unused inspect import from util. State-dump debug output can be re-introduced with a real debug flag if it is ever needed.

Summary by CodeRabbit

  • Chores

    • Improved startup error reporting and logging consistency so initialization failures are now surfaced and logged.
    • Removed optional debug state dumping functionality.
    • Updated logging output for worktree operations to use consistent debug-level logs.
  • Bug Fixes

    • Ensured non-blocking startup tasks log failures instead of being silently ignored.

@jatmn jatmn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found an issue that needs to be addressed before this is ready.

Findings

  • [P2] Finish or remove the advertised debug-cleanup changes
    src/main.tsx:351
    The PR description says this fixes the silent migrateChangelogFromConfig catch and cleans debug artifacts in src/utils/worktree.ts and src/utils/fileHistory.ts, but the patch only changes src/main.tsx. On this branch, migrateChangelogFromConfig().catch(() => {}) still silently ignores migration failures, worktree.ts still has the three console.log call sites called out in the PR body, and fileHistory.ts still has console.error(inspect(state, false, 5)) behind ENABLE_DUMP_STATE. As written, the PR does not deliver a meaningful part of its stated scope, and reviewers/users would believe those noisy debug paths and silent errors were fixed when they were not. Please either implement those advertised changes or narrow the PR description to the behavior this patch actually changes.

@jatmn jatmn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update. I rechecked the changed paths and found an issue that still needs to be addressed.

Findings

  • [P2] Finish or remove the advertised debug-cleanup changes
    src/main.tsx:351
    The PR description still says this fixes the silent migrateChangelogFromConfig catch and cleans debug artifacts in src/utils/worktree.ts and src/utils/fileHistory.ts, but the patch still only changes src/main.tsx. On this branch, migrateChangelogFromConfig().catch(() => {}) still silently ignores migration failures, worktree.ts still has the three console.log call sites called out in the PR body, and fileHistory.ts still has console.error(inspect(state, false, 5)) behind ENABLE_DUMP_STATE. As written, the PR still does not deliver a meaningful part of its stated scope, and reviewers/users would believe those noisy debug paths and silent errors were fixed when they were not. Please either implement those advertised changes or narrow the PR description to the behavior this patch actually changes.

main.tsx:
- Add logError to silent migrateChangelogFromConfig catch -- migration
  failures are now surfaced (with the original error as cause) instead
  of being silently dropped. Will still retry on next startup.
- Add stderr message before process.exit(1) in debugger detection --
  users see why the process exited.
- Add logForDebugging to silent catch block in logManagedSettings --
  errors are no longer swallowed.
- Add .catch(logError) to 3 void getSystemContext() calls -- git
  failures are now logged.

src/utils/worktree.ts:
- Convert two diagnostic console.log sites ("Using worktree via hook"
  and "Created worktree") to logForDebugging. These were diagnostic
  output, not user-facing; sending them through the debug log pipeline
  removes the need for the biome-ignore comments and stops polluting
  stdout in normal use. The iTerm2 tip console.log further down is
  intentionally user-facing guidance and is left untouched.

src/utils/fileHistory.ts:
- Remove dead ENABLE_DUMP_STATE flag and maybeDumpStateForDebug helper
  (flag was hard-coded to false, so the helper never ran). Also remove
  the two call sites in fileHistoryTrackEdit and fileHistoryMakeSnapshot,
  and drop the now-unused `inspect` import from 'util'.
@skyhighbg22-jpg skyhighbg22-jpg force-pushed the fix/developer-experience branch from f82c56d to 8377a7b Compare June 4, 2026 17:08
@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: cc0f75b2-179b-479a-8533-e5418369c227

📥 Commits

Reviewing files that changed from the base of the PR and between 8377a7b and dc947a7.

📒 Files selected for processing (1)
  • src/main.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main.tsx

📝 Walkthrough

Walkthrough

Adds logging for previously-unhandled startup errors, changes two console debug prints to use the debug logger, and removes an unused debug state-dump facility. No exported/public signatures changed.

Changes

Observability and Debug Improvements

Layer / File(s) Summary
Startup path error logging
src/main.tsx
Managed settings errors are logged via logForDebugging; debugger-detected external-build exit writes a message to process.stderr; non-blocking changelog migration errors are caught, wrapped in an Error with cause, and logged via logError; getSystemContext() calls in prefetch and print-mode paths now attach .catch(logError) so failures are reported.
Debug message logging migration
src/utils/worktree.ts
Worktree messages previously emitted with console.log ("Using worktree via hook", "Created worktree") are now emitted with logForDebugging().
Remove debug state dumping facility
src/utils/fileHistory.ts
Deletes the util.inspect import, the ENABLE_DUMP_STATE constant and maybeDumpStateForDebug helper, and removed calls to that helper from fileHistoryTrackEdit and fileHistoryMakeSnapshot.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰
I hopped through startup's silent night,
And nudged the logs to show the light.
Old dumps were cleared beneath my paws,
Now errors speak without a pause.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main objectives: adding error context to silent catch handlers and improving debugger detection error visibility.
Description check ✅ Passed The pull request description provides comprehensive coverage of changes across all three files with clear explanations of what changed and why, but lacks explicit Testing and Impact sections required by the template.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/main.tsx`:
- Around line 226-229: The catch block after calling logManagedSettings
currently swallows the exception; modify the catch to capture the error (e.g.,
catch (err)) and pass that error into the debug log call so the exception
details are preserved—update the logForDebugging('[main] logManagedSettings
failed', { level: 'debug' }) invocation to include the caught error (err or
err.message/stack) so callers can see the failure context for the
logManagedSettings call.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 716c4aea-6356-4dae-ac0c-eecdd395c144

📥 Commits

Reviewing files that changed from the base of the PR and between e357d59 and 8377a7b.

📒 Files selected for processing (3)
  • src/main.tsx
  • src/utils/fileHistory.ts
  • src/utils/worktree.ts
💤 Files with no reviewable changes (1)
  • src/utils/fileHistory.ts

Comment thread src/main.tsx Outdated
@skyhighbg22-jpg skyhighbg22-jpg requested a review from jatmn June 4, 2026 17:12

@jatmn jatmn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update. I rechecked the previously discussed paths and found one item that still needs to be addressed.

Findings

  • [P2] Complete CodeRabbit's request to keep the managed-settings error context
    src/main.tsx:226
    CodeRabbit's review thread is marked resolved, but the current patch still uses a bare catch around logManagedSettings and logs only [main] logManagedSettings failed. That means any failure while reading policy settings, formatting the managed keys, or sending the analytics event is still reduced to a generic message with no exception details, which undercuts the PR's stated goal of adding error context to silent catches. Please complete that review request by catching the error value and including its message/stack in the debug log.

Capture the error in the logManagedSettings catch and include its formatted message in the debug log so failures while reading policy settings, formatting managed keys, or sending the analytics event surface exception details instead of a generic message.
@skyhighbg22-jpg skyhighbg22-jpg requested a review from jatmn June 5, 2026 17:08

@jatmn jatmn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update. I rechecked the previously discussed paths and found one item that still needs to be addressed.

Findings

  • [P2] Surface the changelog cache-write failures too
    src/utils/releaseNotes.ts:226
    The new .catch(logError) around migrateChangelogFromConfig() only reports errors that escape the migration, but the migration still catches every mkdir/writeFile failure internally and treats it like the cache file already existed. If creating the changelog cache fails for another reason, the failure is still silent and saveGlobalConfig(({ cachedChangelog: _, ...rest }) => rest) then removes the legacy value, so the advertised "migration failures are now surfaced / will retry next startup" behavior does not hold for that write path. Please either rethrow/log non-EEXIST write failures before removing cachedChangelog, or narrow the PR description so it does not claim those migration failures are now visible.

@kevincodex1 kevincodex1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kevincodex1 kevincodex1 merged commit e9b211a into Gitlawb:main Jun 8, 2026
3 checks passed
deagwon97 pushed a commit to deagwon97/openclaude that referenced this pull request Jun 11, 2026
…awb#1479)

* fix: add error context to silent catches and debugger detection

main.tsx:
- Add logError to silent migrateChangelogFromConfig catch -- migration
  failures are now surfaced (with the original error as cause) instead
  of being silently dropped. Will still retry on next startup.
- Add stderr message before process.exit(1) in debugger detection --
  users see why the process exited.
- Add logForDebugging to silent catch block in logManagedSettings --
  errors are no longer swallowed.
- Add .catch(logError) to 3 void getSystemContext() calls -- git
  failures are now logged.

src/utils/worktree.ts:
- Convert two diagnostic console.log sites ("Using worktree via hook"
  and "Created worktree") to logForDebugging. These were diagnostic
  output, not user-facing; sending them through the debug log pipeline
  removes the need for the biome-ignore comments and stops polluting
  stdout in normal use. The iTerm2 tip console.log further down is
  intentionally user-facing guidance and is left untouched.

src/utils/fileHistory.ts:
- Remove dead ENABLE_DUMP_STATE flag and maybeDumpStateForDebug helper
  (flag was hard-coded to false, so the helper never ran). Also remove
  the two call sites in fileHistoryTrackEdit and fileHistoryMakeSnapshot,
  and drop the now-unused `inspect` import from 'util'.

* fix: include error context in logManagedSettings debug log

Capture the error in the logManagedSettings catch and include its formatted message in the debug log so failures while reading policy settings, formatting managed keys, or sending the analytics event surface exception details instead of a generic message.
hotmanxp added a commit to hotmanxp/openclaude that referenced this pull request Jun 13, 2026
End-to-end smoke exercising the full bg-agent-view flow on macOS:

1. bun run build
2. node dist/cli.mjs daemon install — DISPATCH GAP (not wired)
3. node dist/cli.mjs daemon start — DISPATCH GAP (not wired)
4. node dist/cli.mjs daemon status — DISPATCH GAP (not wired)
5. node dist/cli.mjs -p 'echo hi' --bg test — DEFERRED (T10 wired
   detectRelaunch() helper but --bg parsing is gated behind
   scripts/build.ts:34 BG_SESSIONS=false; flip the flag or wire
   --bg in src/entrypoints/cli.tsx:276)
6. node dist/cli.mjs bg-agents — DISPATCH GAP (handler exists but
   not wired; T7 renamed to 'bg-agents' to avoid collision with
   the upstream-synced agentsHandler from PR Gitlawb#1479)
7. node dist/cli.mjs bg-agents --json — DEFERRED (same gap as 6)
8. node dist/cli.mjs bg-agents --kill-all --yes — DEFERRED
9. node dist/cli.mjs daemon stop — best-effort
10. node dist/cli.mjs daemon uninstall — best-effort

Adds 'smoke:bg-agent-view' npm script entry.

Reality check (2026-06-13): T2-T10 landed as library code
(supervisor, IPC, roster, launchd plist, bg-agents handler,
/background slash, BackgroundAgentViewDialog, --bg helper) but did
NOT wire any of the subcommands into src/entrypoints/cli.tsx, and
the relevant bun:bundle feature flags (DAEMON=false,
BG_SESSIONS=false) strip the fast-paths at build time. Running
`node dist/cli.mjs daemon …` or `node dist/cli.mjs bg-agents`
today falls through to the full TUI Ink stack and errors out with
'Raw mode is not supported on the current process.stdin'. The
smoke script captures these failures cleanly, prints a summary of
PASS/SKIP/FAIL, exits 0 (gaps are documented, not blocking), and
self-cleans via trap EXIT so no orphan launchd agents survive a
mid-script Ctrl-C.

When the wiring lands, the FAIL→PASS flips happen automatically:
flip DAEMON/BG_SESSIONS to true in scripts/build.ts:27/34 and add
an argv check for 'bg-agents' in src/entrypoints/cli.tsx that
imports handleBgAgentsCommand from src/cli/handlers/bgAgents.ts.
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.

3 participants