-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
Userland errors vs. Node errors #15057
Comments
If they have the code property they are of class |
Maybe we should just add something like |
@addaleax I would be all for that 👍 |
Looking a bit further by the way, I realize that AssertionError is not a NodeError, but the The only way to truly solve that, seems to be to stop using the |
What's stopping you from fixing this on your side by defining a common error subclass or property to errors you raise with |
@benjamingr Nothing is stopping me from doing that at all.
But since I'm developing a middleware, now my users will have to use my middleware's error classes instead of their own. On top of that, they can no longer use just any assertion library, since that too will throw errors of the wrong class. Maybe there is room for Node to make this all a bit easier. |
I don't think this scales well. Let's say you use a package I don't have a better idea right now, I just think the benefits of having such a property are minimal.
How did you do this before, did you rely on the existence / absence of the |
@tniessen You are right about other modules. That is an issue.
I didn't really use While I don't consider this solved, I'm gonna close this issue. I don't see a single obvious solution here. Worth a blog post maybe ;) |
@ronkorving I see a lot of value in discussion of a longer term error strategy in Node.js - if you'd open a nodejs/CTC issue I would participate. We spent a lot of time considering g different models for bluebird and how to distinguish our own errors. |
Thanks 👍 |
When I create and manage errors, I often add a
.code
property on my error objects. Node of course does this as well. This is all fine, until my use case became "send my codes to the the end-user and turn them into a human readable error description". Once I catch an error and start sendingerror.code
to the user, I have no easy way to identify if this is one of the userland errors, or a Node error.This is of course not a bug in Node, it's just a paradoxical situation, with arguably many solutions. But I wonder if I'm really the only one out there who has been using
error.code
for userland errors. If so, I should change my approach. But if this is actually really common, perhaps there's a case to be made to make Node errors more identifiable as coming from Node (they could be instances of a NodeError class, or they could perhaps have an extra property on them).Of course the easiest approach is for me to just pick a new property name for userland error codes, or create a specialized error class myself. But I have to wonder, am I alone on this? Should this be the burden of users, or should Node perhaps stop claiming the
Error
class and.code
property for itself? Really hoping for some feedback from users and @nodejs/collaborators. Thanks.The text was updated successfully, but these errors were encountered: