-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
errors.js module #14554
Comments
Eventually this may be a possibility. For the time being, however, while we are still in the process of migrating all of our internal errors, I would rather avoid it. The reason is due to the fact that changes to that internal API are still possible / likely as we move along. |
I think we can create a new module named const PathNotFoundError = errors.makeError('ERR_PATH_NOT_FOUND', '%s not found')
const err = new PathNotFoundError('/usr/foo/bar')
// err.code === 'ERR_PATH_NOT_FOUND'
// err.message === '/usr/foo/bar not found' By the way, we can export all errors code used in |
@jasnell Maybe we can export just the constructors like the internal |
I've opened an issue (#14216) and a PR (#14250) earlier before about separating the error codes to a new module, but the errors are still being migrated so they are blocked temporarily. IMHO, the appropriate time to do these is after the migration are done. |
just trying to understand what needs to be done here:
is that so? |
There's been no activity on this issue for a long time. @nodejs/documentation, any update on this? |
There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment. For more information on how the project manages feature requests, please consult the feature request management document. |
Please keep this open. |
There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment. For more information on how the project manages feature requests, please consult the feature request management document. |
There has been no activity on this feature request and it is being closed. If you feel closing this issue is not the right thing to do, please leave a comment. For more information on how the project manages feature requests, please consult the feature request management document. |
Please re-open this (?) |
This is such a useful feature, yet it's dead again |
Jesus... I want to test for the type of error in my unit tests and it seems like a headache? What |
There is just no good way as far as I've looked. The only way I have ever found is to check if it's an instanceof Error and then check the .name property. It's horrid. I've ever only found pain when dealing with JS exceptions. |
Node now has
internal/errors.js
module which allows to set static error codes for errors, which is great. Would be good to expose Node's internal error constructors in a new module sayrequire('errors')
.My use case is as follows: I am now rewriting an in-memory file system module
memfs
that mimics howfs
module works, I would like to throw exactly the same errors as Node does, so that it can be used for testing, so now I have to basically copy-paste theinternal/errors.js
file into my project to be able to create similar errors to what Node does.The text was updated successfully, but these errors were encountered: