Replies: 1 comment 1 reply
-
Any schema has its own error message: const RecordSchema = v.record(v.string('key error'), v.string('value error'), 'object error'); If you want the same error message for all nested schemas you can use the const RecordSchema = v.config(v.record(v.string(), v.string()), { message: 'error' }); If you want the same error message for all schemas when using const RecordSchema = v.record(v.string(), v.string());
const output = v.parse(RecordSchema, data, { message: 'error' }); If you want the same error message for all schemas globally you can use v.setGlobalMessage('error'); |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I think this relates to: #467.
I'm a bit confused about how to take advantage of custom error messages. For example:
I would expect the stack trace would consist of my custom error message but alas I see:
I'm also aware there's
safeParse
but when I inspect the issues and or the first issue's path I still don't see the error message. Am I misunderstanding how this API works? I am basing my example off of the docs for records here https://valibot.dev/api/record/#generics.Any help is appreciated, thanks!
Beta Was this translation helpful? Give feedback.
All reactions