Ability to add label to be shown in error instead of generic like: String must contain at least 3 character(s)
See original GitHub issueFor example if I have this validation
const schema = z.object({
firstName: z.string().min(3).max(12),
isActive: z.boolean(),
role: z.enum(['Admin', 'User']),
});
const result = schema.safeParse({
"firstName": '',
"isActive": null,
"role": "min",
});
console.log(JSON.stringify(result, null, 2));
{
"success": false,
"error": {
"issues": [
{
"code": "too_small",
"minimum": 3,
"type": "string",
"inclusive": true,
"message": "String must contain at least 3 character(s)",
"path": [
"firstName"
]
},
{
"code": "invalid_type",
"expected": "boolean",
"received": "null",
"path": [
"isActive"
],
"message": "Expected boolean, received null"
},
{
"received": "min",
"code": "invalid_enum_value",
"options": [
"Admin",
"User"
],
"path": [
"role"
],
"message": "Invalid enum value. Expected 'Admin' | 'User', received 'min'"
}
],
"name": "ZodError"
}
}
Error message will be
firstName must contain at least 3 character(s)
instead of String must contain at least 3 character(s)
Issue Analytics
- State:
- Created a year ago
- Comments:11
Top Results From Across the Web
Troubleshoot Shipment Issues - ShipStation Help
The shipment detail shown in the error has not been set yet. ShipStation requires all four shipment details to create a label successfully....
Read more >ios - Simplest way to throw an error/exception with a custom ...
The simplest approach is probably to define one custom enum with just one case that has a String attached to it: enum MyError:...
Read more >Error Explanations for The W3C Markup Validation Service
An attribute name (and some attribute values) must start with one of a restricted set of characters. This error usually indicates that you...
Read more >Troubleshooting Common Error Messages in Shippo
Error messages can be confusing, frustrating, and can happen for various reasons. Thats why we have put together this list of common...
Read more >Improve Validation Errors with Adaptive Messages
In this article we'll go over findings from our usability studies on how the wording of validation error messages largely determines the user's ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
i think by default it should use the field name, and also have a convenient override like label().
so it seems like you’re asking why users can’t just use
path
as alluded to in the ERROR_HANDLING docs. There is also this package as another option.IIRC, (i haven’t used any of this in 2 months) I think some of us just didn’t see why manual customization/workaround or another package should be necessary to use path by default and preferably even a label() option. If it needs to stay hard-coded with a generic type label for other use cases, then that’s understandable.
If what i have listed above is the stance of devs, than maybe closing as
wontfix
, optionally with a brief explanation, would be preferable to the stalebot being unleashed, which i find to be a somewhat disagreeable way to close an issue. 😃thanks