{"record":{"id":"c7fa53400aafbed4","repo":"jaredpalmer/formik","slug":"warning-an-unhandled-error-was-caught-during-vali-c7fa53","errorCode":null,"errorMessage":"Warning: An unhandled error was caught during validation in <Formik validationSchema />","messagePattern":"Warning: An unhandled error was caught during validation in <Formik validationSchema />","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/formik/src/Formik.tsx","lineNumber":256,"sourceCode":"        field && schema.validateAt\n          ? schema.validateAt(field, values)\n          : validateYupSchema(values, schema);\n      return new Promise((resolve, reject) => {\n        promise.then(\n          () => {\n            resolve(emptyErrors);\n          },\n          (err: any) => {\n            // Yup will throw a validation error if validation fails. We catch those and\n            // resolve them into Formik errors. We can sniff if something is a Yup error\n            // by checking error.name.\n            // @see https://github.com/jquense/yup#validationerrorerrors-string--arraystring-value-any-path-string\n            if (err.name === 'ValidationError') {\n              resolve(yupToFormErrors(err));\n            } else {\n              // We throw any other errors\n              if (process.env.NODE_ENV !== 'production') {\n                console.warn(\n                  `Warning: An unhandled error was caught during validation in <Formik validationSchema />`,\n                  err\n                );\n              }\n\n              reject(err);\n            }\n          }\n        );\n      });\n    },\n    [props.validationSchema]\n  );\n\n  const runSingleFieldLevelValidation = React.useCallback(\n    (field: string, value: void | string): Promise<string> => {\n      return new Promise(resolve =>\n        resolve(fieldRegistry.current[field].validate(value) as string)","sourceCodeStart":238,"sourceCodeEnd":274,"githubUrl":"https://github.com/jaredpalmer/formik/blob/91475adbf33579561e580eceea0c031f4ec2e992/packages/formik/src/Formik.tsx#L238-L274","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nvalidationSchema: Yup.object().shape({\n  email: Yup.string().test('domain', 'bad', v => v.split('@')[1] === 'x.com'), // throws on undefined\n})\n// after\nvalidationSchema: Yup.object().shape({\n  email: Yup.string().test('domain', 'bad', v =>\n    typeof v === 'string' && v.split('@')[1] === 'x.com'\n  ),\n})","handlingStrategy":"try-catch","validationCode":"// sanity-check the schema in a test/dev before using it\nschema.validateSync(initialValues); // surfaces non-ValidationError throws early","typeGuard":"import * as Yup from 'yup';\nconst isValidSchema = (s: unknown): s is Yup.ObjectSchema =>\n  !!s && typeof (s as Yup.ObjectSchema).validate === 'function';","tryCatchPattern":"// custom Yup tests: keep them total (never throw)\nYup.string().test('check', 'msg', v => {\n  try { return check(v); } catch { return false; }\n})","preventionTips":["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)"],"tags":["formik","yup","validation-schema","unhandled-rejection"],"backgroundTag":"yup-schema-validation-failed","analyzedSha":"91475adbf33579561e580eceea0c031f4ec2e992","analyzedAt":"2026-08-27T12:26:57.937Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}