-
Notifications
You must be signed in to change notification settings - Fork 61
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
Provide getProperty
method for VError and WError
#33
Comments
I think it's useful to first-class the notion of properties, and we've been talking about it over on #10. I've got a branch there with a prototype that I'm getting pretty confident about. It's a little different than the way you've done it here, but addresses some other issues. |
I looked at the verror.js, the IMHO, there are two things not good with this way: Suggestion with what you have built:
My opinion about VError is that it's the best fit in my use case to build errors for both developer and end users. No matter it's 3rd-party npm module or internal lib/util, the error processing always starts with Error instance with whatever properties assigned to it. Take express.js req/res for example Route Handler ---(invoke)---> Controller ---(invoke)---> Library Library generate whatever error (e.g. request connection timeout error), should be wrapped in Controller with Developer friendly message (e.g. XXX API Request Timeout), and before we send the error to client, we need to wrap it again with Client friendly message (e.g. Oops, something wrong blabla, retry pls...) In this common use case, the most likely place to set properties is at the Library. And I don't think it's significant better to group all properties to error.jse_info and force user to create a VError at Library. |
[edited] The "jse_info" bit is an implementation detail, but what you're getting at is that the design for #10 does not use arbitrary properties hanging off the Error object. That is a little more inconvenient, but it has a couple of advantages:
As for (a), you're right that the constructor can look more like a large block, but I don't think it's very different than if you're using separate properties. You've got to compare:
to:
I think it's cleaner that it's declarative. And in the much more common case where you don't need additional properties, it's still ergonomic:
As for (b), I think it's a reasonable idea to provide a VError function that takes an Error provided by a third-party library and creates a VError containing all of the non-standard property names as VError 'info' properties. |
Having heard no more, I'm closing this out. I'm hoping to land #10 soon. |
I find it useful that if VError and WError instance could get its parent(s)'s property value. A use case could be like
I have created a utility method like below, but I think it would be better to be part of the library
The text was updated successfully, but these errors were encountered: