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

https://github.com/fabian-hiller/valibot/blob/fd9189064831451f1f97c2f94b7afd9a0fca26dd/library/src/utils/ValiError/ValiError.ts#L27-L31

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)

Most upvoted comments

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 ValiError message. 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.

  1. Adding a new custom method doesn’t help with my issue. I have been very clear in explaining what I ask for. I have been explicit in that having a new API won’t help (again: because this just helps you to write the wrappers, and it is not the same as not needing to have wrappers). It is frustrating that we can’t even move past acknowledging what this issue I’m bringing up is about, and what are specifically non-solutions to it.
  2. You essentially say “no, I don’t want it”. Well, yes, your call at the end of the day. But, please, let me know your thoughts about this design decision. Tell me: why? The reason I am asking is 1) I’d like to talk this through with you to have a chance to convince you, and 2) I need to make a decision on whether to fork and implement this myself (or make a side-package with reusable wrappers or etc) - and pay the greater effort and cost of maintenance than contributing directly here (but at this point I have to consider it) - or if there is a legitimate reason why this is a bad idea and should not be done at all. Or, idk, maybe you’d just accept a PR if we author it and that’d be the end of it. Please, just, share you vision. For instance. Looks ugly and won’t be a good interop with other things that keep the error message as a one line? Yes, I get that. There’s a trade-off here, I can explain this aspect of the proposed design in more detail. Don’t want to implement it yourself? I can do it, no biggie, just let me know! Something problem there that I haven’t addressed yet? Well, then let me know, and let’s work this through. Busy and not ready to think about something like this right now? It’s ok, everyone has a lot on their plate these days - just let me know and we’ll put it on hold for now and pick up later.

Don’t get me wrong, your reply is helpful, the flatten fn 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/unsolvable zod issues 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 summarize method is available! I will try to answer the last comments in the next few days.

Actually, I don’t think adding dotPath to the Issue is 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 Issue interface specifically - not sure that one is relevant here, but it might be - in case if we provide ValiError in places where the Issue is 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.log and other ways of printing/displaying the error. What I mean is, maybe we leave the message field as is, and provide a customized toString() implementation?

I would agree with having dotPath in Issue, 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/