Skip to content
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

Support for custom error types? #15

Closed
bjrmatos opened this issue Aug 12, 2014 · 13 comments
Closed

Support for custom error types? #15

bjrmatos opened this issue Aug 12, 2014 · 13 comments

Comments

@bjrmatos
Copy link

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
Copy link

👍

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
Copy link
Contributor

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
Copy link

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
Copy link

iliakan commented Dec 8, 2014

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
Copy link

iliakan commented Dec 8, 2014

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
Copy link

@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
Copy link

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

@iliakan
Copy link

iliakan commented Mar 20, 2015

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
Copy link

yunong commented May 18, 2015

@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
Copy link
Contributor

@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
Copy link

@naddison36 That is what I was looking for

@DonutEspresso
Copy link
Contributor

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
Copy link
Contributor

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants