valibot: Include the issue path at the ValiError message by default
Subject Matter
There are ways to extract the path and other issue details from the ValiError (i.e. error.issues) but the default ValiError error message still lacks some pretty essential error information - the path of the issue in question.
Context
We have identified this as a major shortcoming when comparing to zod, as to get feature-parity with easily identifiable errors you actually have to do something else but the usual v.parse - not great.
Our typical use-cases for zod/valibot are 90% internal / 10% external validation, the internal being where the errors are for the devs and are not rendered fancily to the users - like loading the internal configs, and etc.
Proposed Changes
What we would like to have is to see those issues’ paths out-of-the-box at ValiError message and to not write any custom issue rendering for the basic usage scenario.
Note that we do see some use of having the concise message that we have currently readily available - but from the broad usage experience of zod and migration to valibot - I’ve found that this is far less useful than having an more detailed / less concise error.
The concise message could still be preserved and exposed via a properly as it is indeed useful occasionally.
Current Implementation
See that super call? It simply takes the first issue message - but not the path.
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 10
- Comments: 20 (9 by maintainers)
No, you missed my point. I already have those wrappers.
What I want is the defaults change, for everyone. Eliminate the need to have custom wrappers.
I think this issue should get more into the discussion about the listing and discussing the design decisions that led to the current state of the
ValiErrormessage. Having paths shown to you is a tremendous help, so it is counter-intuitive to me they’d be omitted. What is the reason for that?Look. Your answer to this whole chain of discussion comes across as if you are either not paying attention, or you have some hidden concerns on why what I’m asking here is unwanted.
To be specific on why I feel like this is the case: your last reply reads, essentially, like this: “You better write a custom API. I won’t discuss why, but I refuse to have such API in the library, now, but later maybe I’ll change my mind”. Am I wrong?
I’d like to address this reply.
Don’t get me wrong, your reply is helpful, the
flattenfn would be useful to write a wrapper like that - but, as I said in the beginning, I already got a wrapper. I don’t need help implementing one, or a workaround to my issue. I don’t have a “question” like this issue is labeled. I just really want to dig deep into a particular design aspect, not only for the sake of improving this crate, but to also improve my knowledge on why this would be a blocker. For selfish reasons, I admit - if I knew upfront would kind of save me some time.Anyhow, I see you have been doing an amazing job with the library lately, and what you’ve built is helping us a lot with our advanced cases that require composing custom validation logic. The composition is much better than with
zod, and, in fact, we’ve discovered this library while digging through the unsolved/unsolvablezodissues that we’ve encountered while trying to solve our practical problems. This library ticks all the boxes for us, except for the DX with the default errors - and here’s why I’m here trying to contribute this missing piece. The aim here is improve things for us, but also for everyone.Valibot v1.1.0 with the new
summarizemethod is available! I will try to answer the last comments in the next few days.Actually, I don’t think adding
dotPathto theIssueis of any help here. It might be useful in its own right, but for the subject it at most makes it easy to write your wrappers - not get rid of them.About the standard schema
Issueinterface specifically - not sure that one is relevant here, but it might be - in case if we provideValiErrorin places where theIssueis expected.I think, ultimately an error’s default display implementation should serve a concise a summary of the issues - possibly with a cap on the max amount of issues at maybe 20 to avoid overwhelming the output stream for non-typical cases.
Also, and we’re getting technical here, I’m mostly worried about having the “user (dev) visible” representation of the error that we get from the
console.logand other ways of printing/displaying the error. What I mean is, maybe we leave themessagefield as is, and provide a customizedtoString()implementation?I would agree with having
dotPathinIssue, definitely would have been nice to have it on multiple occasions, but that would probably require an adjustment on Standard Schema too? (https://github.com/standard-schema/standard-schema/blob/main/packages/spec/src/index.ts#L40)Just as a note, there’s builtin util to get dotPath from
Issue: https://valibot.dev/api/getDotPath/