Skip to content

issue: Improper handling of errors with empty path in Standard Schema #841

@evelynesideofdux

Description

@evelynesideofdux

Version Number

5.2.2

Codesandbox/Expo snack

https://codesandbox.io/p/sandbox/currying-wildflower-h472k9

Steps to reproduce

  1. Use the standard schema resolver with a validator that may return an error with either no path or an empty path (in my case, typia when union discrimination fails uses an empty path)
  2. Submit the form
  3. Notice how despite a validation fail occured, no errors are raised and handleSubmit calls the submit handler with an empty object

It is caused by the code correctly going down the "validation failure" code path, and returning { values: {}, errors: parseErrorSchema() }, but parseErrorSchema() starts from an empty object, iteratively adding errors to it while skipping empty paths, causing the returned error to end up as an empty object, which signals no error to react-hook-form.

Expected behaviour

Given that the path of a standard schema issue is explicitly optional in the spec, I would expect the standard schema resolver to properly handle such issue types.

Even if issues without a path are considered non-supported, at the very least, it should not return an empty object as a validated result, as that breaks the type contract of handleSubmit.

What browsers are you seeing the problem on?

Firefox

Relevant log output

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions