question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Guarantees on promise rejection

See original GitHub issue

Hi, the README.md carefully advises against having exceptions/rejections when working with the library.

In particular, the fromSafePromise function mentions:

Ensure you know what you’re doing, otherwise a thrown exception within this promise will break any guarantees that neverthrow provides.

Now, I would like to encode expected/regular errors in the Result type, but allow unexpected/rare/fatal errors to reject my promises.

Looking at the code, this library seems to allow that, but the documentation kind of suggests that that is not okay and the compatibility could break later on after some changes.

What is the position on that? I can always not use ResultAsync and encode my functions as Promise<Result<T,E>> manually, but it is kind of a pity, because ResultAsync methods are pretty useful.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
davazpcommented, Apr 2, 2021

I guess the “fix” to this GitHub issue is simply to update the README or add an entry into the wiki? I would gladly accept a contribution on this - especially a wiki article.

I think so! I’ll try to sketch something next week. Thanks!

1reaction
supermacrocommented, Mar 31, 2021

Hey @davazp,

Great question, and something I should probably bring up more explicitly in the docs.

I think there isn’t a clear-cut answer and it’s about a team’s / individual’s preference on how they want to deal with / think about “irrecoverable errors”.

I would say that most people in the functional programming community (and Rust?) would agree with me when I say that you should encode recoverable errors into your type system (i.e. in your Result types), and have a separate process / system in place for irrecoverable errors.

For servers, that means - shut down your server because something horribly wrong has just occurred and your server is now in a non-sensical state. An example of this would be if you’re missing critical environment variables. In some of my applications, I throw and have a process.on('UnhandledException', () => {}) handler that terminates the server safely.

The rust community has done a great job of documenting this distinction between recoverable vs irrecoverable errors:

https://doc.rust-lang.org/stable/book/ch09-00-error-handling.html

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using promises - JavaScript - MDN Web Docs
A Promise is an object representing the eventual completion or failure of an asynchronous operation. Since most people are consumers of ...
Read more >
What does it mean for promises to be immutable and their ...
A promise is a one-way latch. Once it is resolved with a value or rejected with a reason, its state and value/reason can...
Read more >
Using promises
A Promise is an object representing the eventual completion or failure ... Whenever a promise is rejected, one of two events is sent...
Read more >
prefer-promise-reject-errors - Pluggable JavaScript Linter
This rule aims to ensure that Promises are only rejected with Error objects. Options. This rule takes one optional object argument: allowEmptyReject: true...
Read more >
JavaScript Promise Tutorial: Resolve, Reject, and Chaining in ...
A promise in JavaScript is similar to a promise in real life. When we make a promise in real life, it is a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found