-
-
Notifications
You must be signed in to change notification settings - Fork 20
Support cause
in Error constructor
#112
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
Comments
cause
in Error constructor cause
in Error constructor
Maybe when we drop node 14 👍 |
There is no need to wait, we could implement it ourselves in this repo. |
How could we support this without breaking change? I'm +1 to change the FastifyError class constructor signature and use normal arguments. |
Something like: // function createError (code, message, statusCode = 500, Base = Error, hasCause = false)
const MyErorr = createError('ABC', 'something', Error, true)
new MyError({ message, args, cause }) Which is backward compatible. At some point, we would need to drop (!) the positional arguments and use an object. |
Is it really preferable to pass in an object? I created once #103 were the formatter would have been generated on creation of the ErrorConstructor. If we never had rest arguments, the serializer would be faster. And tbh. I dont know how the { args } would work. Also |
In my opinion, all functions should be declared
Technically, the signature is |
Exactly. So it would something like MyError({args, cause, statusCode}) and so on. But it would make sense then to change the format string to a simple serializer. E.g. const createError = require('@fastify/error')
const MyError = createError('ERROR_CODE', 'Hello %entity')
console.log(new MyError({entity: 'world'})) // error.message => 'Hello world' |
I don't think so. It's easier all around to have |
It feels like the whole aspect of fast error instanciation get lost, when we pass objects and arrays. |
Pretty sure that's never been the goal of this module. I believe its purpose is for generating standard errors with error codes. |
There is absolutely nothing fast in creating an error due to the stacktrace requirement. Fastify kinds of requires the use of Errors for certain patterns and maybe we might want to provide a few fast-paths there. |
I will pick this up, I will open a draft PR soon EDIT: PR open, I will wait your feedback on the draft before proceeding if you don't mind. |
Thanks guys for implementing this! |
Prerequisites
🚀 Feature Proposal
it would be great to be able to use cause option in fastify errors as well
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause
Motivation
No response
Example
The text was updated successfully, but these errors were encountered: