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
Uncaught Exceptions on ResultAsync #113
Comments
Hello @Chuckytuh, thanks for this remark. You are right that these methods can include uncaught errors, however they are by design. In the case of Does this make sense to you ? If you have any suggestions to make |
Yes, it makes absolute sense, and it is known and disclaimed, that neverthrow isn't a solution that eliminates exceptions being thrown!
The only that I can think of, and also the easiest one, would be to have this, or a similar example, on the documentation for
|
Although not mentioned explicitly in this project, the idea behind a There shouldn't be any side effects. And yes, throwing exceptions is a side effect. If I have a If you have some exception or failed promise that you did not account for then I personally (in my own work) treat those as critical errors that shouldn't be recovered. I would much rather prefer my program to crash and stop running than to continue running in some weird indeterminate state. Then review logs and see what the error was and then encode that error into your type system so as to handle it smoothly if it ever occurs again. With all that said, I don't think there's anything to be done here. It's just a matter of making the distinction between expected errors and unexpected / irrecoverable errors. |
Going to close this issue. But feel free to open a PR to improve the documentation! |
The new ResultAsync constructs are pretty cool and an improvement over the chain function however, as it is implemented, it opens the door for Uncaught Exceptions to lurk easily!
Take the following example:
The error ("this is uncaught") thrown from the
map
is uncaught-able and the reason for it is because an async function is being passed into thePromise.then
and no error handling is being made there.https://github.com/supermacro/neverthrow/blob/master/src/result-async.ts#L29-L34
The same happens for
mapErr
.This might be by design or effectively a bug on the implementation.
Would wrapping the transform function
f
be acceptable?The problems I see with this approach is that the thrown error is not necessarily of type
E
so we're potentially introducing runtime errors.The text was updated successfully, but these errors were encountered: