jaredpalmer / formik

Build forms in React, without the tears 😭
https://formik.org
Apache License 2.0
33.88k stars 2.79k forks source link

Throwing an empty errors object passes async validation #1141

Open mschipperheyn opened 5 years ago

mschipperheyn commented 5 years ago

🐛 Bug report

Current Behavior

If you throw an empty errors object, validation passes validation successfully

Expected behavior

While in sync mode returning an empty errors object is supposed to pass validation, in async mode, the fact that the Promise throws is already an indication that an error occurred, otherwise it would simply return the empty object instead of throwing it.

This can lead to subtle errors if server side validation messages are processed and an error gets thrown during this process.

Reproducible example

Suggested solution(s)

Any scenario where async validation throws, should lead to a failed validation.

Your environment

Software Version(s)
Formik 1.3.2
React 16.6.3
TypeScript
Browser
npm/Yarn
Operating System
jaredpalmer commented 5 years ago

What if you throw undefined?

jannikbuschke commented 5 years ago

imho indicating (async) validation errors with throwing something is "wrong". The sync and async validation should be consistent: async validation should just return/resolve an object (an empty object would indicate no validation errors in both cases) see also https://github.com/jaredpalmer/formik/issues/966