Unhandled exception should still be printed to the Console
Setting up this module hides errors from the Chrome console. This is not good for debugging
I'm on the fence about this one, while its nice to see the errors, in local development the package should be not initialized. In your live environment, there's little benefit in the users of the application to see the errors, and as a developer you can see all of the errors in the stackdriver dashboard.
Thoughts @steren ?
That's a good point that in local dev, it's better to not initialize the module.
I still wonder if in a scenario of troubleshooting a customer issue, it's convenient to ask the customer: "open the Chrome console, is there any errors there?".
Very good point!
I would definitely agree with @steren in this case, but it should be an option which could be turned off in config if someone would still want to run logging silently.
You should not break default browser behaviour. Sometimes one need to check by himself that is an error somewhere without access to stackdriver. How could he know that this script is running and errors are suppresed? It can lead to many problems.
For those who needs fix for this, just change return value of this function in source code from true to false: window.onerror = function(message, source, lineno, colno, error) { if(error){ that.report(error); } oldErrorHandler(message, source, lineno, colno, error); return true; };
Line 74 in current version
and then rebuild (npm run dist).
What about just make this configurable?
another possible workaround:
import StackdriverErrorReporter from "stackdriver-errors-js";
const errorReporter = new StackdriverErrorReporter();
function startReportingUnhanldedErrors() {
// 1. report errors to stackdriver
errorReporter.start(YOUR_CONFIG);
const stackdriverErrorHandler = window.onerror;
window.onerror = () => {
stackdriverErrorHandler(...arguments);
// 2. log errors to the console (default browser behavior)
return false;
};
}
the bad thing is that StackDriver automatically makes the decision for you, violating Inversion of Control. It could be especially bad when there are other handlers that monitor the console (Winston, for example)
should be disabled by default, or configurable.
@oshalygin, @steren
- A lot of small companies, don't have strict QA, and they ship products with bugs and fix bugs on production (hello, can you send the screenshot of the console ?). In this case, Whenever something is not working, we can't go to stackdriver and refresh the screen every few seconds to see any new error is captured.
- Other error-capturing (ex: sentry) libraries do print unhandled errors on the console. That's what console is for.
- In local development, I was running this library, with disabled = true, in this mode also errors are swallowed (errors not printed, errors not sent to the server).