-
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
Generic errors with no message on production builds #4519
Comments
Sorry for the surprising change. I agree this should have been better documented. Stripping error strings from the production bundle cuts 10-20% from bundle sizes (depending on how many error strings are used). Very few build-time optimizations have that much impact on bundle sizes (besides minification and gzip, of course). I'm open to refining how this system works, but it's very unlikely that we will ever go back to embedding the full strings in the bundle. The pressure from developers who want smaller bundle sizes is not something we can ignore (see #4324). Throwing an exception changes control flow, so it's important to continue throwing even if the error message has been sanitized. For cases where throwing in production is not desirable, we have The stripping of error strings happens only when I realize this isn't trivial because of security considerations, but if you have the ability to enable source maps in production, it might be easier to figure out where the exceptions are being thrown. |
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.
Inspired by #4519. Implemented and explained by apollographql/invariant-packages#1.
@GreenGremlin Please have a look at #4521 when you get a chance! |
That's great! Any chance you could take a look at #4373, which fixes the original issue that led to my fix that relied on the error messages? |
Inspired by #4519. Implemented and explained by apollographql/invariant-packages#1.
Inspired by #4519. Implemented and explained by apollographql/invariant-packages#1.
Closing since we just published the final version of |
Hi @benjamn, thanks for the PR, but may I ask is there any way for me to track the error based on the errorCode. I'm not sure where to start. E.g I got the error Then what next, where should I use the number 2 to see what is the exact error?. Thank you |
@GreenGremlin @benjamn same question here. Got |
same for me, |
This is an option for finding the message associated with the error number: #4521 (comment) It's pretty tough to determine production errors, since the numbers might not always be the same for each error. #4521 (comment) The most helpful way I've found for deobfuscating the production errors is using source maps and go up the stack trace to find usable error messages. |
EDIT: Thanks @benjamn - All good here! If anyone is still having issues, this may help: #4521 (comment) |
Version 4.2 graphql-anywhere included a change that stripped messages from some errors (invariant violations) in production builds. This change resulted in very generic errors that are very difficult to track down. I'm curious why the decision was made to strip messages from errors that ARE still thrown. I can understand preventing warnings in production builds, but stripping messages from errors that ARE still thrown does not make sense to me. Furthermore, there was no mention of this change in the changelog, and it was released as a minor version bump!
For us this was an even bigger issue, because we were relying on the error message to handle the errors caused by #4372. The undocumented removal of invariant error messages resulted in generic errors in our production builds that could not be reproduced in our development builds.
Please at least document these types of changes, in the future! And consider adding back invariant violation error messages.
The text was updated successfully, but these errors were encountered: