jaredpalmer/formik · warning
Warning: An unhandled error was caught during validation in
Error message
Warning: An unhandled error was caught during validation in <Formik validationSchema />
What it means
Formik ran your Yup `validationSchema` and Yup threw an error that is NOT a `ValidationError` (e.g. TypeError, a schema bug, or a rejected promise from a lazy/async schema). Formik maps `ValidationError` to form errors; any other exception is a real bug, so it warns (dev only) and re-throws via rejection.
Source
Thrown at packages/formik/src/Formik.tsx:256
field && schema.validateAt
? schema.validateAt(field, values)
: validateYupSchema(values, schema);
return new Promise((resolve, reject) => {
promise.then(
() => {
resolve(emptyErrors);
},
(err: any) => {
// Yup will throw a validation error if validation fails. We catch those and
// resolve them into Formik errors. We can sniff if something is a Yup error
// by checking error.name.
// @see https://github.com/jquense/yup#validationerrorerrors-string--arraystring-value-any-path-string
if (err.name === 'ValidationError') {
resolve(yupToFormErrors(err));
} else {
// We throw any other errors
if (process.env.NODE_ENV !== 'production') {
console.warn(
`Warning: An unhandled error was caught during validation in <Formik validationSchema />`,
err
);
}
reject(err);
}
}
);
});
},
[props.validationSchema]
);
const runSingleFieldLevelValidation = React.useCallback(
(field: string, value: void | string): Promise<string> => {
return new Promise(resolve =>
resolve(fieldRegistry.current[field].validate(value) as string)View on GitHub (pinned to 91475adbf3)
Solutions
- Look at the second warn argument (the raw err) — it is the actual thrown error with stack; fix that.
- Wrap custom Yup `test()` message/test functions defensively; guard property access inside tests.
- Verify you're on a single compatible yup version (`npm ls yup`) — mismatched versions can produce errors not shaped like ValidationError.
- Reproduce by calling `schema.validate(values)` manually in a unit test to see the raw exception.
Example fix
// before
validationSchema: Yup.object().shape({
email: Yup.string().test('domain', 'bad', v => v.split('@')[1] === 'x.com'), // throws on undefined
})
// after
validationSchema: Yup.object().shape({
email: Yup.string().test('domain', 'bad', v =>
typeof v === 'string' && v.split('@')[1] === 'x.com'
),
}) Defensive patterns
Strategy: try-catch
Validate before calling
// sanity-check the schema in a test/dev before using it schema.validateSync(initialValues); // surfaces non-ValidationError throws early
Type guard
import * as Yup from 'yup'; const isValidSchema = (s: unknown): s is Yup.ObjectSchema => !!s && typeof (s as Yup.ObjectSchema).validate === 'function';
Try / catch
// custom Yup tests: keep them total (never throw)
Yup.string().test('check', 'msg', v => {
try { return check(v); } catch { return false; }
}) Prevention
- Pin one yup version; check npm ls yup
- Guard property access inside custom test() callbacks
- Unit-test schema.validate against edge-case values (undefined, empty)
When it happens
Trigger: A `validationSchema` whose schema construction throws (e.g. `Yup.object().shape({ a: undefined })`), a `lazy()` schema that throws, casting/reach issues, or runtime TypeErrors inside custom Yup test functions.
Common situations: Custom `test()` callbacks that access undefined properties, mixing Yup versions where `ValidationError.name` differs, conditionally building a schema with a bug, or schema referenced before definition.
Related errors
- Warning: An unhandled error was caught during validation in
- Warning: An unhandled error was caught from submitForm()
- Warning: Formik called \`${handlerName}\`, but you forgot to
AI-assisted analysis of jaredpalmer/formik@91475adbf3 (2026-08-27).
Data as JSON: /api/errors/c7fa53400aafbed4.
Report an issue: GitHub.