Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotate sanitized InvariantErrors with numeric error codes. #1

Merged
merged 3 commits into from
Mar 2, 2019

Conversation

benjamn
Copy link
Member

@benjamn benjamn commented Mar 2, 2019

Inspired by apollographql/apollo-client#4519.

Given the { errorCodes: true } option, rollup-plugin-invariant will now transform

invariant(condition, message)

into

process.env.NODE_ENV === 'production'
  ? invariant(condition, <number>)
  : invariant(condition, message)

and

new InvariantError(message)

into

process.env.NODE_ENV === 'production'
  ? new InvariantError(<number>)
  : new InvariantError(message)

so that production errors can be traced back to the place in the unminified source code where they were thrown. Since the full development version of the error is always colocated with the production one, it should be relatively easy to determine the nature of the error.

The messages for these sanitized errors will look like this:

Invariant Violation: <number> (see https://github.com/apollographql/invariant-packages)

The provided URL is appended by the InvariantError constructor within the ts-invariant package, so it will not be repeated at every call site.

Inspired by apollographql/apollo-client#4519.

Given the { errorCodes: true } option, rollup-plugin-invariant will now
transform

  invariant(condition, message)

into

  process.env.NODE_ENV === 'production'
    ? invariant(condition, <number>)
    : invariant(condition, message)

and

  new InvariantError(message)

into

  process.env.NODE_ENV === 'production'
    ? new InvariantError(<number>)
    : new InvariantError(message)

so that production errors can be traced back to the place in the
unminified source code where they were thrown. Since the full development
version of the error is always colocated with the production one, it
should be relatively easy to determine the nature of the error.

The message for these sanitized errors will look like this:

  Invariant Violation: <number> (see https://github.com/apollographql/invariant-packages)

The provided URL is appended by the InvariantError constructor within the
ts-invariant package, so it will not be repeated at every call site.
@benjamn benjamn self-assigned this Mar 2, 2019
@benjamn benjamn requested a review from hwillson March 2, 2019 02:02
Copy link
Member

@hwillson hwillson left a comment

Choose a reason for hiding this comment

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

Love it @benjamn - thanks!

@benjamn benjamn merged commit 7fbba13 into master Mar 2, 2019
@benjamn benjamn deleted the annotate-error-codes branch March 2, 2019 02:40
benjamn added a commit to apollographql/apollo-client that referenced this pull request Mar 2, 2019
benjamn added a commit to apollographql/apollo-client that referenced this pull request Mar 4, 2019
benjamn added a commit to apollographql/apollo-client that referenced this pull request Mar 4, 2019
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.

2 participants