-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Generate @apollo/client/invariantErrorCodes.js for each release. #6665
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
When an invariant fails in production, a cryptic numeric error of the form `Invariant Violation: 42` is thrown, with a reference to the error codes section of invariant-packages README.md: https://github.com/apollographql/invariant-packages#error-codes This vague guidance has not proven adequate in many cases, to say the least: see apollographql/invariant-packages#18, apollographql/invariant-packages#19, #6604, Using error codes instead of error strings remains important for production bundle sizes, but I think we can make it substantially easier to look up the error string corresponding to each error code, by generating a single file containing all the invariant error codes for each @apollo/client release. Starting with Apollo Client 3.1.0, this manifest file can be found in @apollo/client/invariantErrorCodes.js (using an npm/yarn-installed copy of @apollo/client, since this file is generated in the ./dist directory, not checked into the repository). The file contains an explanatory comment, the @apollo/client version, and a sequential map from error numbers to the { file, node } responsible for the error. I wish we could go back and republish old versions of @apollo/client to include this file, but at least things should be easier going forward.
Here's a taste of what this file looks like: // This file is meant to help with looking up the source of errors like
// "Invariant Violation: 35" and is automatically generated by the file
// @apollo/client/config/processInvariants.ts for each @apollo/client
// release. The numbers may change from release to release, so please
// consult the @apollo/client/invariantErrorCodes.js file specific to
// your @apollo/client version. This file is not meant to be imported.
{
"@apollo/client version": "3.1.0",
1: {
file: "@apollo/client/cache/inmemory/policies.js",
node: invariant(!old || old === which, "Cannot change root " + which + " __typename more than once")
},
2: {
file: "@apollo/client/cache/inmemory/policies.js",
node: new InvariantError("Cannot automatically merge arrays")
},
3: {
file: "@apollo/client/cache/inmemory/policies.js",
node: invariant(hasOwn.call(response, responseName), "Missing field '" + responseName + "' while computing key fields")
},
4: {
file: "@apollo/client/cache/inmemory/readFromStore.js",
node: new InvariantError("Dangling reference to missing " + objectOrReference.__ref + " object")
},
// ... skipping a few ...
52: {
file: "@apollo/client/utilities/graphql/storeUtils.js",
node: new InvariantError("The inline argument \"" + name.value + "\" of kind \"" + value.kind + "\"" +
'is not supported. Use variables instead of inline arguments to ' +
'overcome this limitation.')
},
53: {
file: "@apollo/client/utilities/testing/mocking/mockLink.js",
node: invariant(queryWithoutConnection, "query is required")
}
} |
jcreighton
approved these changes
Jul 21, 2020
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🆒 👍
jimrandomh
pushed a commit
to jimrandomh/apollo-client
that referenced
this pull request
Jul 22, 2020
…llographql#6665) When an invariant fails in production, a cryptic numeric error of the form `Invariant Violation: 42` is thrown, with a reference to the error codes section of invariant-packages README.md: https://github.com/apollographql/invariant-packages#error-codes This vague guidance has not proven adequate in many cases, to say the least: see apollographql/invariant-packages#18, apollographql/invariant-packages#19, apollographql#6604, However, this vague guidance (which was intended to suggest searching your installed node_modules/@apollo/client package for the error code) has not proven adequate in many cases, to say the least: see apollographql/invariant-packages#18, apollographql/invariant-packages#19, apollographql#6604, apollographql#5730, apollographql#5291, and apollographql#5975, to cite just a few of the many issues we've seen since apollographql#4521. Using error codes instead of error strings remains important for production bundle sizes, but I think we can make it substantially easier to look up the error string corresponding to each error code, by generating a single file containing all the invariant error codes for each @apollo/client release. Starting with Apollo Client 3.1.0, this manifest file can be found in @apollo/client/invariantErrorCodes.js (using an npm/yarn-installed copy of @apollo/client, since this file is generated in the ./dist directory, not checked into the repository). The file contains an explanatory comment, the @apollo/client version, and a sequential map from error numbers to the { file, node } responsible for the error.
This was referenced Aug 18, 2020
This was referenced Apr 28, 2021
Closed
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When an
invariant
fails in production, a cryptic numeric error of the formInvariant Violation: 42
is thrown, with a reference to the error codes section ofinvariant-packages
README.md. This system was introduced in #4521 to save bundle size by stripping long error strings from production bundles, and it continues to be one of the most impactful things we've done to reduce bundle sizes.However, this vague guidance (which was intended to suggest searching your installed
node_modules/@apollo/client
package for the error code) has not proven adequate in many cases, to say the least: see apollographql/invariant-packages#18, apollographql/invariant-packages#19, #6604, #5730, #5291, and #5975, to cite just a few of the many issues we've seen since #4521.Using error codes instead of error strings remains important for production bundle sizes, but I think we can make it substantially easier to look up the error string corresponding to each error code, by generating a single file containing all the invariant error codes for each
@apollo/client
release.Starting with Apollo Client 3.1.0, this manifest file can be found in
@apollo/client/invariantErrorCodes.js
(using annpm
/yarn
-installed copy of@apollo/client
, since this file is generated in the./dist
directory, not checked into the repository). The file contains an explanatory comment, the@apollo/client
version, and a sequential map from error numbers to the{ file, node }
responsible for the error.I wish we could go back and republish old versions of
@apollo/client
to include this file, but at least things should be easier going forward.