Skip to content
This repository was archived by the owner on Oct 28, 2025. It is now read-only.

Conversation

@asnov
Copy link
Contributor

@asnov asnov commented Dec 27, 2024

By definition, a JavaScript Promise object can be in one of three states: pending , resolved , or rejected. Throwing an error is kind of fourth state which contradicts the definition and violates the handling of promise results.
So you should not throw an error inside promise, you should reject the promise.

From a practical point of view, this means that if an error occurs in one of the simultaneously executing queries, then throwing an error does not allow tracking down which specific query caused the error and does not save the results of other queries that executed successfully. So I fixed it for quotes as this issue was not allowing to use SDK correctly.

@0xsambugs
Copy link
Contributor

Hey @asnov !

You are right in the sense that these functions should always return a Promise. Just a question though, did you get an error when using them?

Because these functions are mostly async, and errors thrown inside async functions should be transformed into rejected promises automatically (as far I understood)

So just wanted to make sure you run into an error instead of a rejected Promise

@asnov
Copy link
Contributor Author

asnov commented Dec 28, 2024

Hi @0xsambugs ,
Yes, I run into an error instead of a rejected Promise.
Errors thrown inside functions are transformed into rejected promises automatically only for synchronous functions. For async func they are generate unhandled errors. You could read more about this here: https://stackoverflow.com/a/33446005/2591174 and the next answers.
Cheers!

@0xsambugs
Copy link
Contributor

TIL! @asnov would you mind sharing how you are getting the error and not the rejected promise? I would love to reproduce it

@0xsambugs
Copy link
Contributor

0xsambugs commented Dec 28, 2024

Ok, now I'm even more curious @asnov as to how you are getting the error instead of the rejected promise. I just added this test and it seems to pass without any issues

@asnov
Copy link
Contributor Author

asnov commented Dec 28, 2024

Yeah, now I don't understand myself how I got it. I'm trying to repeat it, but in vain. Probably, it was some old version of the SDK. Give me a couple more days to repeat the steps.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants