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

Assign unique error codes to production invariant errors. #4521

Merged
merged 2 commits into from
Mar 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@

## Apollo Client vNEXT

### Apollo Client
- In production, `invariant(condition, message)` failures will now include
a unique error code that can be used to trace the error back to the
point of failure. <br/>
[@benjamn](https://github.com/benjamn) in [#4521](https://github.com/apollographql/apollo-client/pull/4521)

- Update the React Native docs to remove the request for external example
apps that we can link to. We're no longer going to manage a list of
### Apollo Client

- Update the React Native docs to remove the request for external example
apps that we can link to. We're no longer going to manage a list of
external example apps. <br />
[@hwillson](https://github.com/hwillson) in [#4531](https://github.com/apollographql/apollo-client/pull/4531)

Expand All @@ -14,7 +19,6 @@
- Support `new InMemoryCache({ freezeResults: true })` to help enforce immutability. <br/>
[@benjamn](https://github.com/benjamn) in [#4514](https://github.com/apollographql/apollo-client/pull/4514)


## Apollo Client 2.5.1

### apollo-client 2.5.1
Expand Down
10 changes: 9 additions & 1 deletion config/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,15 @@ export function rollup({
module: true,
}),
typescriptPlugin({ typescript, tsconfig }),
invariantPlugin(),
invariantPlugin({
// Instead of completely stripping InvariantError messages in
// production, this option assigns a numeric code to the
// production version of each error (unique to the call/throw
// location), which makes it much easier to trace production
// errors back to the unminified code where they were thrown,
// where the full error string can be found. See #4519.
errorCodes: true,

Choose a reason for hiding this comment

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

This is great! Would it be possible for the error codes to be there in both the production and development versions?

Copy link
Member Author

Choose a reason for hiding this comment

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

The error codes will be present in Apollo Client library code in development, since the unminified code looks like this:

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

The codes won't be automatically included in the error messages in development, though. I think this is a reasonable balance, since these error codes are subject to change, so we don't want to commit to specific numbers for specific errors. The goal of this PR is just to make sure it's possible to make sense of production errors.

}),
],
onwarn,
},
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
{
"name": "apollo-utilities",
"path": "./packages/apollo-utilities/lib/bundle.cjs.min.js",
"maxSize": "4.15 kB"
"maxSize": "4.2 kB"
}
],
"lint-staged": {
Expand Down Expand Up @@ -89,7 +89,7 @@
"react": "16.8.3",
"react-dom": "16.8.3",
"rollup": "1.2.2",
"rollup-plugin-invariant": "^0.3.2",
"rollup-plugin-invariant": "^0.4.0",
"rollup-plugin-local-resolve": "1.0.7",
"rollup-plugin-node-resolve": "4.0.1",
"rollup-plugin-sourcemaps": "0.4.2",
Expand Down
8 changes: 4 additions & 4 deletions packages/apollo-boost/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/apollo-boost/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"apollo-link-error": "^1.0.3",
"apollo-link-http": "^1.3.1",
"graphql-tag": "^2.4.2",
"ts-invariant": "^0.2.1",
"ts-invariant": "^0.3.0",
"tslib": "^1.9.3"
},
"peerDependencies": {
Expand Down
8 changes: 4 additions & 4 deletions packages/apollo-cache-inmemory/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/apollo-cache-inmemory/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"apollo-cache": "file:../apollo-cache",
"apollo-utilities": "file:../apollo-utilities",
"optimism": "^0.6.9",
"ts-invariant": "^0.2.1",
"ts-invariant": "^0.3.0",
"tslib": "^1.9.3"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-cache/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions packages/apollo-client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/apollo-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"apollo-link-dedup": "^1.0.0",
"apollo-utilities": "file:../apollo-utilities",
"symbol-observable": "^1.0.2",
"ts-invariant": "^0.2.1",
"ts-invariant": "^0.3.0",
"tslib": "^1.9.3",
"zen-observable": "^0.8.0"
},
Expand Down
8 changes: 4 additions & 4 deletions packages/apollo-utilities/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/apollo-utilities/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
},
"dependencies": {
"fast-json-stable-stringify": "^2.0.0",
"ts-invariant": "^0.2.1",
"ts-invariant": "^0.3.0",
"tslib": "^1.9.3"
}
}
2 changes: 1 addition & 1 deletion packages/graphql-anywhere/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.