-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
[Reliability] Making Android robust during development and production #3779
Comments
Thanks for putting this together!
|
Subscribing. |
@mkonicek some replies:
|
Thanks for the awesome writeup @ide! I'm just cleaning up the
I'm wondering whether we should be handling errors like this. It causes redbox in dev but hard crashes in production without the developer having any chance to handle this. They can't do for example:
When writing an app in Obj-C or Java the developer always has the option to handle the error. @kmagiera, @nicklockwood what do you think? Should we always be returning a Promise to pass any error to back to JS and logging it? I like the idea of specifying what errors should redbox / hard crash vs just log on a case-by-case basis by distinguishing between soft and fatal errors (empty POST request body could be a soft error for example). |
But then if we handle errors like this:
It is really easy to call Making it easy to ignore errors and just logging them to the console (like browsers do) is a bit strange to me but could be just a matter of preference. If we want to allow the above and still have redboxes we'd have to find a way to detect all unhandled errors somehow, e.g.: |
Runtime errors due to bad data, user input, network failures, hardware malfunctions, etc. should always be passed back to JS to be handled by the developer. Programming errors, such as bad arguments sent to a function should red box and/or crash in production. The tricky part is cases where it's not clear which it is. For example, is a bad url sent to a JS function a programmer error or a user input error? It depends on whether the value eas hard coded or provided by the user, but we can't know that. In the case of a URI, I'd tend to assume that it's been provided by the programmer and that it's their responsibility to validate it before sending it over the bridge. If we were going to validate URIs in release mode and return an error, it would probably make more sense to do that in JS anyway, so the behavior is consistent across platform. |
cc: @javache, who's overhauling the error handling logic on iOS at the moment. |
FWIW, I'm not a fan of the soft exceptions / hard exceptions system. Our error handling at the moment is a bit of a mashup of code written by people who subscribe to the "fail soft" approach and those who subscribe to "fail hard", so that a programmer error might call the js error handler in one function, even though there's no programmatic way to handle it, and corrupt data in an http response might hard crash the app in another function even though there's no programmatic way to sanitise the data beforehand There are also some differences between platforms. For example red box errors are recoverable/closable on iOS, but on Android you only have the option to reload. I'd prefer we just stick to:
|
@mkonicek I like the async function API. It is consistent with ES7 and async functions in other languages. I'm not too concerned (but still slightly concerned :P) about people ignoring promise errors because (a) it's a problem that the entire JavaScript language faces and needs a solution and (b) with async functions it becomes more natural to catch these errors. I've certainly forgotten to catch errors from promises before and do wish there a better solution existed, but tooling around promises/async functions will likely improve next year.
Just my perspective on this - I would like for the severity of programmer errors to be configurable since I generally believe a policy of forgiveness works well for frameworks / platforms. As an example, if you make a bad DOM API call the browser window doesn't crash (hopefully!) but you'll still get an exception that you can handle however you want. |
@ide the problem is that checking for all possible error conditions has a runtime penalty, which we don't want to be paying in release mode, so we disable these checks for release. Doing the checks in dev mode allows us to produce helpful, specific errors, but those errors need to be fatal (red box) so that developers see and fix them. If we leave it up to the developer how to handle them in dev mode, those soft errors may turn into hard crashes in production when we disable the checks. From a philosophical PoV, while I agree that APIs should be friendly to n00bs, I don't think that quietly allowing errors to slide is particularly friendly. Each error we detect is an opportunity to teach the developer about a misconception they may have, and steer them down the right path. If we encourage them to ignore or suppress errors, that's a missed opportunity. |
I'm with Nick on this.
Right, we just need a way to allow the developer to configure what should happen in prod. @javache told me iOS has a way to do this. For example, in the main fb iOS app, we don't want to crash on exceptions from RN.
I like this too. Don't think we do this consistently (yet). Also, let's expose native methods using promises everywhere and let's stop using callbacks. Promises are a really nice API. |
That would be awesome 👍 Do you have any links to what's being worked on? |
Created separate issue for error handling with promises/async functions: #4045 |
@mkonicek - regarding devtool improvements, Chrome has an "Async" checkbox (http://www.html5rocks.com/en/tutorials/developertools/async-call-stack/). Node.js + Google were looking into a tracing API for debugging/instrumentation and async APIs (what Node's AsyncWrap native abstraction was doing, I believe): https://github.com/nodejs/tracing-wg. Generally I'm happy that some major JS stakeholders are thinking about asychrony more. |
Hi there! This issue is being closed because it has been inactive for a while. But don't worry, it will live on with ProductPains! Check out its new home: https://productpains.com/post/react-native/reliability-making-android-robust-during-development-and-production ProductPains helps the community prioritize the most important issues thanks to its voting feature. Also, if this issue is a bug, please consider sending a PR with a fix. |
It looks very strange when there's a conversation going on by some core React contributors, and then one of the authors of the discussion closes that issue. Of course this applies assuming moving issues to product pains is not an automated process. I'm curious what was the conclusion to this. Was there any decision? |
@hey99xx We now mostly use promises and pass errors to JS. Promise rejections show redbox if not handled. |
There are a couple of things that are fragile about the RN Android environment right now. There has been some work put into RN iOS to be more forgiving about errors and bad inputs while still telling developers about the problems. A few things I've noticed that RN iOS does well that Android currently doesn't do:
cc @mkonicek
The text was updated successfully, but these errors were encountered: