Skip to content

When is Issue.path allowed to be undefined? #60

Open

Description

@michaelboyles

I'm implementing standard-schema support for my library and I'm currently mapping standard-schema Issues to my own equivalent.

The current documentation currently just says "The path of the issue, if any", but it's not clear to me in which situations Issue.path may be omitted.

My first thought was maybe it could be omitted when enforcing some invariant { isOdd: true, num: 1 }. In such case it may not be desirable to use either of the paths [isOdd] or [num] to express that issue, since neither is individually the issue, and a validator might want to express that a higher level - to display that as an issue with the object as a whole rather than any individual property. But in such case, isn't an empty path ([]) appropriate? Is an empty path ([]) equivalent to a lack of a path (undefined)?

I think the spec would benefit from being more specific about this.

Activity

  1. fabian-hiller commented on Feb 23, 2025

    @fabian-hiller
    Member

    The current documentation currently just says "The path of the issue, if any", but it's not clear to me in which situations Issue.path may be omitted.

    If someone provides a wrong input for the outermost schema, the path will be undefined or empty. For example, if you define an object schema but your user enters a string, the validation will return and issue for the object schema without a path because the problem occurred at the root.

  2. michaelboyles commented on Feb 23, 2025

    @michaelboyles
    Author

    Sorry, I asked the question directly but you didn't answer it directly: Is an empty path ([]) equivalent to a lack of a path (undefined)? I think you're saying yes, but I want to be clear.

    This wasn't only a question, though. It was also essentially a recommendation for you to clarify the wording in the spec. Specs should be very precise, and this part isn't at the moment.

  3. ssalbdivad commented on Feb 23, 2025

    @ssalbdivad
    Collaborator

    My interpretation was that undefined should be used in cases where the library could not provide a path associated with the error e.g. because they never track it whereas [] would be used if there is explicitly a problem with the root data.

    IMO [] should generally be preferred, as the distinction for a consumer is pretty marginal.

  4. fabian-hiller commented on Feb 23, 2025

    @fabian-hiller
    Member

    Right now Valibot will never return an empty array. If there is a path you can be sure it includes at least one item. I would say the spec is not opinionated about this at the moment as we can't control how library authors implement it. Even if we advise them, there is no guarantee.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

questionFurther information is requested

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions