When an exception is being thrown in the validate function, the exception-object is being treated as a validation result. Since the exception does not contain any fields of the form, the form is considered valid.
The error should be rethrown and if not otherwise caught, the program should crash.
https://codesandbox.io/s/7mryz7opqx
Using reject() to indicate that there is an error is imho a bit of a poor design: The goal of the validate method should be, to find validation errors. The reject method of a promise however should be used when the promise cannot be completed, for example because of an error. So a successful validation should end up in a resolve of the promise, as the function core functionality and the expected result were successfully produced.
I'd recommend to change the api here, so that a valid form state is indicated by the state of the returned object. eg. an empty object indicates that there is no validation error.
This problem described in here is especially problematic sinc using the validate function asynchronously is usually the case when communicating with a server for complexer validations. That szenario is likely to fail because of external issues.
| Software | Version(s) |
| ---------------- | ---------- |
| Formik | 1.2.0
| React | 16.5.0
| TypeScript |
| Browser | chrome 70
| npm/Yarn | npm
| Operating System | macOS Sierra, Windows 10
@jaredpalmer Do you need any help to fix this issue? We find this line https://github.com/jaredpalmer/formik/blob/0e459bce5f88bc60681f81ffe13df81982a723ab/src/Formik.tsx#L296 is the root cause. What is your suggestion?
@PeerHartmann imho you are correct. Indicating validation errors in any async validation should be passed to formik via resolve. There are several bugs and questions that come up, i.e. https://github.com/jaredpalmer/formik/issues/966, https://github.com/jaredpalmer/formik/issues/1141
This would be a breaking change.
@jaredpalmer as this would be a breaking change, whats your opinion on this? I would also jump in to help working on this.
Closing in favour of https://github.com/formium/formik/issues/1329
Most helpful comment
@jaredpalmer Do you need any help to fix this issue? We find this line https://github.com/jaredpalmer/formik/blob/0e459bce5f88bc60681f81ffe13df81982a723ab/src/Formik.tsx#L296 is the root cause. What is your suggestion?