Message "%s" does not resolve to "" when argument is not passed into Error
### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
### Fastify version
4.26.0
### Plugin version
_No response_
### Node.js version
22.3.0
### Operating system
Linux
### Operating system version (i.e. 20.04, 11.3, 10)
20.04.6
### Description
I'm not sure if this is a bug or a feature request. Please correct me one way or the other.
I'm trying to support the following functionality:
```ts
export const Unauthorized = createError("MY_UNAUTHORIZED", "%s", 403);
throw new Unauthorized("You cannot do this")
// { "code": "MY_UNAUTHORIZED", "Bad Request", "message": "You cannot do this", "statusCode": 403 }
throw new Unauthorized()
// { "code": "MY_UNAUTHORIZED", "Bad Request", "message": "", "statusCode": 403 }
```
However, the second case resolves to:
```ts
throw new Unauthorized()
// { "code": "MY_UNAUTHORIZED", "Bad Request", "message": "%s", "statusCode": 403 }
// Note the "%s" in the message.
```
This is consistent with how `node:util`'s `format` works, but I don't think it's useful here. I think a blank message, rather than "%s", is preferable in this scenario.
### Link to code that reproduces the bug
_No response_
### Expected Behavior
_No response_
关闭于 2024-09-10 9 条评论