Closed bjrmatos closed 8 years ago
:+1:
Joyent recommends using “the Error's name property to distinguish errors programmatically”. However, I can't see a way to use VError with custom error types – if everything has a name of VError
or WError
then obviously you can no longer use the name property to distinguish programmatically.
Thanks for the pointer! I'll take a look at extend-error. There's a branch of VError that lets you set name and other properties here:
https://github.com/davepacheco/node-verror/compare/props
but I haven't had occasion to use it in an application so I haven't integrated it into master yet.
My branch of VError may have what you are looking for https://github.com/naddison36/node-verror
It preserves the name property from the error cause rather than setting the name property to VError or WError.
Maybe you should allow to extend VErrors by inheritance?
Inheritance allows to use generic tests like err instanceof HttpError
(catches HttpError
, PageNotFoundError
, ForbiddenError
etc).
As a side effect, name
is available (and should be supported).
P.S. Maybe it is allowed to inherit from VErrors
right now, but in the examples
folder I don't see that as a use case.
@iliakan If you have successfully inherited VError can you provide an example . Cause in the current implementation we get the VError object by calling the method of static class I have not idea how to perform inheritance in this scenario using the inbuilt Node "Util" library.
@iliakan I just checked the docs there is also a constructor function available so I can inherit easily.
oh that was so long ago I can't even remember what the issue was about. There definitely was something. Withdrawing my question cause of lack of memories.
@davepacheco Any updates on whether you'll merge in your branch? It'd be really nice to be able to use the new features.
@yunong I haven't really had a chance to play with it much myself, so I haven't really validated the new design. Have you tried it? Or at least looked at the API?
@naddison36 That is what I was looking for
Another alternative for folks looking is restify-errors, we built it on top of VError (thanks Dave!) and made it relatively straightforward to create custom constructors and properties.
My changes for #10 (which are out for code review) support configuring the "name", and the pattern for inheritance is better documented, too. Closing this as a dup of #10. Thanks!
I like the approach of defining custom type errors in this module https://github.com/jayyvis/extend-error , I think it would be great to add this functionality