fix: use safe error coercion in debug catch blocks#630
Conversation
Replace `(e as Error).message` with `e instanceof Error ? e.message : String(e)` in all catch blocks introduced by #616. Handles non-Error throws safely (e.g. from WASM layer) instead of producing `undefined` in debug output.
|
Claude finished @carlos-alm's task —— View job PR Review CompleteReview Checklist
Root Cause AnalysisProblem Being Solved: Fixes unsafe type assertions introduced in PR #616 that added debug logging to catch blocks. The original implementation used Why This Approach: The fix properly handles the TypeScript reality that Risk Assessment: Very low risk. This is purely defensive programming in debug/logging paths with no behavioral changes to core functionality. Configuration Changes✅ No high-risk configuration changes detected
Test Integrity✅ No test files modified
Code Quality Analysis✅ Strengths
Pattern AnalysisBefore (unsafe): } catch (e) {
debug(`message: ${(e as Error).message}`);
}After (safe): } catch (e) {
debug(`message: ${e instanceof Error ? e.message : String(e)}`);
}📍 Locations Updated
Validation✅ Confirmed all unsafe Backlog Compliance
Final RecommendationRating: ⭐⭐⭐⭐☆ (4/5)Action: APPROVE Reasoning: This is a well-executed defensive programming fix that addresses a real issue. The unsafe type assertions could produce Minor considerations:
The PR demonstrates good engineering hygiene by properly handling TypeScript's catch semantics and ensuring debug output remains meaningful regardless of what's thrown. |
Greptile SummaryThis PR completes a follow-up to #616 by replacing all 14 instances of Confidence Score: 5/5Safe to merge — all changes are in debug-only logging paths with no functional side effects. Pure defensive fix in debug logging; the pattern used is the idiomatic TypeScript-safe approach for unknown catch values, all 14 sites from PR #616 are covered, and the changes carry zero runtime risk to any non-debug code path. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[catch block triggered
e: unknown] --> B{e instanceof Error?}
B -- Yes --> C[use e.message
structured Error object]
B -- No --> D[use String e
handles WASM strings,
numbers, objects, etc.]
C --> E[debug log message]
D --> E
|
Summary
(e as Error).messagewithe instanceof Error ? e.message : String(e)in all 14 catch blocks introduced by that PRundefinedin debug output when non-Errorvalues are thrown (e.g. from WASM layer)config.ts(4),native.ts(2),parser.ts(4),resolve.ts(4)Test plan