fix: add debug logging to silently swallowed catch blocks#65
fix: add debug logging to silently swallowed catch blocks#65devin-ai-integration[bot] wants to merge 1 commit into
Conversation
Add a shared debugError() helper in env.ts that logs catch block errors when CC_SAFETY_NET_DEBUG=1, replacing 10 bare catch blocks that previously discarded all error context. Files changed: - src/core/env.ts: new debugError(context, error) helper - src/core/audit.ts: log audit write failures - src/core/git/config.ts: log git dir/config read failures - src/core/rules/policy/sync.ts: log local rules repair failures - src/core/rules/policy/scope-policy.ts: log realpath, legacy config parse, and rulebook read failures Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #65 +/- ##
==========================================
- Coverage 97.40% 97.31% -0.10%
==========================================
Files 94 94
Lines 10341 10359 +18
==========================================
+ Hits 10073 10081 +8
- Misses 268 278 +10 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Greptile SummaryThis PR instruments 10 previously bare
Confidence Score: 4/5Safe to merge — purely additive instrumentation behind a debug flag, with no change to runtime behaviour when the flag is off. The change is narrow and well-scoped: every fallback return value is preserved, the new helper is gated behind an existing env flag, and the pattern matches the rest of the codebase. The only open question is whether error.message alone is sufficient for the debug use-case, or whether error.stack would be more actionable. src/core/env.ts — the new debugError helper is the only file worth a second look, specifically around what error detail is surfaced to the developer. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[catch block fires] --> B{CC_SAFETY_NET_DEBUG=1?}
B -- No --> C[Silent fallback\nreturn null / return false / no-op]
B -- Yes --> D["console.error(\nCC Safety Net debug: {context}: {message}\n)"]
D --> C
subgraph Callers
E[audit.ts]
F[git/config.ts resolveGitDirFromDotGit]
G[git/config.ts resolveCommonGitDir]
H[git/config.ts gitConfigFileEnablesRecursiveSubmodules]
I[scope-policy.ts isSameConfigPath]
J[scope-policy.ts legacyRulesConfigNeedsMigration]
K[scope-policy.ts getRulebookMigratedFrom]
L[sync.ts repairLocalRulesScope]
end
Callers --> A
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
A[catch block fires] --> B{CC_SAFETY_NET_DEBUG=1?}
B -- No --> C[Silent fallback\nreturn null / return false / no-op]
B -- Yes --> D["console.error(\nCC Safety Net debug: {context}: {message}\n)"]
D --> C
subgraph Callers
E[audit.ts]
F[git/config.ts resolveGitDirFromDotGit]
G[git/config.ts resolveCommonGitDir]
H[git/config.ts gitConfigFileEnablesRecursiveSubmodules]
I[scope-policy.ts isSameConfigPath]
J[scope-policy.ts legacyRulesConfigNeedsMigration]
K[scope-policy.ts getRulebookMigratedFrom]
L[sync.ts repairLocalRulesScope]
end
Callers --> A
Reviews (1): Last reviewed commit: "fix: add debug logging to silently swall..." | Re-trigger Greptile |
| console.error( | ||
| `CC Safety Net debug: ${context}: ${error instanceof Error ? error.message : String(error)}`, | ||
| ); |
There was a problem hiding this comment.
Using
error.stack (when available) gives the full call chain, which is more actionable when the same catch site can be reached from multiple paths. error.stack already includes the message in all major JS runtimes, so there is no duplication.
| console.error( | |
| `CC Safety Net debug: ${context}: ${error instanceof Error ? error.message : String(error)}`, | |
| ); | |
| console.error( | |
| `CC Safety Net debug: ${context}: ${error instanceof Error ? (error.stack ?? error.message) : String(error)}`, | |
| ); |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Summary
10 bare
catch {}blocks across 4 files silently discard all error context, making failures in audit logging, git config resolution, and rules policy loading invisible even when debugging. This adds a shareddebugError(context, error)helper that emitsCC Safety Net debug: ...messages to stderr whenCC_SAFETY_NET_DEBUG=1is set, consistent with the existing debug logging pattern inhook/common.tsandpi/tool-call.ts.Catch blocks changed from bare
catch {}/catch { return null }tocatch (error) { debugError('...', error); }in:audit.ts— audit log write failures (previously "silently ignore errors")git/config.ts—resolveGitDirFromDotGit,resolveCommonGitDir,gitConfigFileEnablesRecursiveSubmodulesrules/policy/sync.ts—repairLocalRulesScoperules/policy/scope-policy.ts—isSameConfigPath,legacyRulesConfigNeedsMigration,getRulebookMigratedFromAll fallback return values are preserved (no behavioral change without
CC_SAFETY_NET_DEBUG=1).Link to Devin session: https://app.devin.ai/sessions/1580eeec7c9c4bbeb8e18289b09f0db3
Requested by: @kenryu42