-
Notifications
You must be signed in to change notification settings - Fork 206
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
Confusing error message when stream is expected #482
Comments
This has already bit me twice. First time I blamed myself, the second I realized that in the midst of many code pieces this can happen more times than you think |
IMO, introducing runtime checks and custom error messages is expensive. Already, most has TypeScript types defined, which statically check for such errors. In the future, Flow types will also be available. If you have such concerns about correct types, I suggest you use TS if you can. |
Duplicate of #480 |
These runtime checks can be placed only for development versions (like react, redux and others have) via |
I'm not sure how I feel about this. I understand the error coming from the VM is cryptic. It's quite unhelpful that Node's unhandledRejection machinery appears not to be printing stack traces. There's nothing we could do about that. Even if we threw a descriptive error message, you'd never see the stack trace, due to node not printing it. The only actual guarantee is a type system. If we check I'm open to finding a simple way to help as long as we don't have to pollute the code or take on much additional maintenance (e.g. in a build step). On the other hand, I'm not sure how much help we can realistically provide if Node is hiding the stack trace. |
We can try to introduce something like calls chain like promises do. We can use
|
I'm not in favor of adding that level of extra machinery. Also, it'd have to be done in a way that works across 3rd party libraries (which may export pure functions), which I don't think is possible. I'd rather we all ask Node to improve their unhandled rejection reporting to include a stack. When you see an unhandled rejection, you do have options for getting a stack trace. You can add a process unhandledRejection event handler, or you can |
Wow, I tried to reproduce and seems like stack trace was improved in chrome. There's now a section in stack trace |
We can make a version with runtime checks for those who don't use type systems. It will also make stack trace more transparent, because checks throw errors inside constructors instead of delegated |
That’s extra maintenance. |
For what it's worth, I completely agree with the reasoning above and in fact I wouldn't want to trade speed for clearer messages tbh. This may be possibly fine in my case once Flow types are added and I might be able to use comment types. I can close this issue if there's agreement to do so. |
I wonder if there is something we can do for those who dont not use TS/Flow... maybe in the form of docs or tips how to debug via the devtools? |
Just as an extra data point, React provides runtime checks in the dev-only build. I do the same in my own code in some places. I use tiny-preprocessor to strip out the dev-only checks for production. Disclaimer: not a request or an opinion about what Most.js should do in this regard. |
Summary
Wherever a stream is expected, if a Promise is passed (by mistake) instead, the message returned is very hard to understand.
Expected result
TypeError: Wrong type passed to 'most.chain' {insert func used}. Expected Stream, passed in Promise.
Actual Result
(node:41876) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot read property 'run' of undefined
(node:41876) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Versions
Code to reproduce
const most = require('most');
const shouldBeStream = foo => {
return most.fromPromise(Promise.resolve(foo + 'bar'));
};
most.of('foo')
.chain(shouldBeStream)
.observe(console.log);
The text was updated successfully, but these errors were encountered: