Skip to content

Elide Crank internals from error stack traces #323

Description

@brainkim

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

  1. Use Error.prepareStackTrace to filter frames containing Crank internals (V8 only)
  2. Use Error.captureStackTrace at strategic points to truncate internal frames
  3. Post-hoc string parsing of error.stack (cross-browser but fragile)
  4. Hybrid: platform APIs where available, graceful degradation elsewhere

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions