TritonDataCenter / node-verror

Rich JavaScript errors
MIT License
1.18k stars 61 forks source link

Support for custom error types? #15

Closed bjrmatos closed 8 years ago

bjrmatos commented 10 years ago

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

OliverJAsh commented 10 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.

https://www.joyent.com/developers/node/design/errors

davepacheco commented 10 years ago

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.

naddison36 commented 9 years ago

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.

iliakan commented 9 years ago

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).

iliakan commented 9 years ago

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.

vipreshjha commented 9 years ago

@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.

vipreshjha commented 9 years ago

@iliakan I just checked the docs there is also a constructor function available so I can inherit easily.

iliakan commented 9 years ago

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.

yunong commented 9 years ago

@davepacheco Any updates on whether you'll merge in your branch? It'd be really nice to be able to use the new features.

davepacheco commented 9 years ago

@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?

figadore commented 8 years ago

@naddison36 That is what I was looking for

DonutEspresso commented 8 years ago

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.

davepacheco commented 8 years ago

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!