Problem
When an error is thrown in a Crank component, the stack trace includes Crank's internal execution frames mixed with user code:
Error: Cannot read property 'name' of undefined
at UserProfile (UserProfile.js:12)
at runComponent (crank.js:482)
at diffChildren (crank.js:312)
at commitHost (crank.js:198)
at UserCard (UserCard.js:8)
at runComponent (crank.js:482)
...
Ideally it would show only the component chain:
Error: Cannot read property 'name' of undefined
at UserProfile (UserProfile.js:12)
at UserCard (UserCard.js:8)
at App (App.js:5)
Constraints
- Use platform APIs, avoid runtime overhead
- Only incur cost when errors are thrown
- Cross-browser would be nice, but V8-only (
Error.prepareStackTrace) is acceptable
Research
- V8's
Error.prepareStackTrace allows filtering frames, but only works in Chrome/Node
Error.captureStackTrace can hide frames above a function reference
- Safari has issues with rethrowing errors losing stack info
- React maintains a separate
componentStack string rather than eliding the JS stack
Possible approaches
- Use
Error.prepareStackTrace to filter frames containing Crank internals (V8 only)
- Use
Error.captureStackTrace at strategic points to truncate internal frames
- Post-hoc string parsing of
error.stack (cross-browser but fragile)
- Hybrid: platform APIs where available, graceful degradation elsewhere
Problem
When an error is thrown in a Crank component, the stack trace includes Crank's internal execution frames mixed with user code:
Ideally it would show only the component chain:
Constraints
Error.prepareStackTrace) is acceptableResearch
Error.prepareStackTraceallows filtering frames, but only works in Chrome/NodeError.captureStackTracecan hide frames above a function referencecomponentStackstring rather than eliding the JS stackPossible approaches
Error.prepareStackTraceto filter frames containing Crank internals (V8 only)Error.captureStackTraceat strategic points to truncate internal frameserror.stack(cross-browser but fragile)