{"record":{"id":"0d7de98d0b357b9c","repo":"jaredpalmer/formik","slug":"warning-an-unhandled-error-was-caught-during-vali","errorCode":null,"errorMessage":"Warning: An unhandled error was caught during validation in <Formik validate />","messagePattern":"Warning: An unhandled error was caught during validation in <Formik validate />","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/formik/src/Formik.tsx","lineNumber":211,"sourceCode":"    // force rerender\n    if (prev !== stateRef.current) setIteration(x => x + 1);\n  }, []);\n\n  const runValidateHandler = React.useCallback(\n    (values: Values, field?: string): Promise<FormikErrors<Values>> => {\n      return new Promise((resolve, reject) => {\n        const maybePromisedErrors = (props.validate as any)(values, field);\n        if (maybePromisedErrors == null) {\n          // use loose null check here on purpose\n          resolve(emptyErrors);\n        } else if (isPromise(maybePromisedErrors)) {\n          (maybePromisedErrors as Promise<any>).then(\n            errors => {\n              resolve(errors || emptyErrors);\n            },\n            actualException => {\n              if (process.env.NODE_ENV !== 'production') {\n                console.warn(\n                  `Warning: An unhandled error was caught during validation in <Formik validate />`,\n                  actualException\n                );\n              }\n\n              reject(actualException);\n            }\n          );\n        } else {\n          resolve(maybePromisedErrors);\n        }\n      });\n    },\n    [props.validate]\n  );\n\n  /**\n   * Run validation against a Yup schema and optionally run a function if successful","sourceCodeStart":193,"sourceCodeEnd":229,"githubUrl":"https://github.com/jaredpalmer/formik/blob/91475adbf33579561e580eceea0c031f4ec2e992/packages/formik/src/Formik.tsx#L193-L229","documentation":"Formik's `validate` function (or `validateYupSchema` path when using plain validate) returned a rejected Promise or threw a non-validation exception. Formik intentionally does not swallow these: it logs a dev-only warning and re-rejects so the error surfaces, because an exception inside `validate` is a bug in user validation code, not a validation result.","triggerScenarios":"A `validate` or `validateYupSchema` prop that throws/rejects for reasons other than returning errors — e.g. accessing a property of undefined values (`values.user.email` when `user` is undefined), calling an API that rejects inside validate, or returning a Promise that rejects instead of resolving to an errors object.","commonSituations":"Deeply nested initial values not pre-populated (undefined path access), async validation calling a backend that 500s, a Yup schema reused with `.validate()` that throws a non-ValidationError, or a refactor that made validate async without awaiting internals.","solutions":["Inspect the second console.warn argument (the actualException) — it contains the real stack and message; fix that underlying throw in your validate function.","Guard nested access: use optional chaining (`values.user?.email`) or lodash `get` inside validate.","Ensure async validate always resolves to an errors object (`return {}` instead of throwing) and wrap any remote calls in try/catch that resolve to a form-level error.","If the exception comes from Yup inside validate, use `validationSchema` instead so Formik maps ValidationError to form errors properly."],"exampleFix":"// before\nvalidate: values => {\n  const errors = {};\n  if (!values.user.email) errors.email = 'Required'; // throws if user undefined\n  return errors;\n}\n// after\nvalidate: values => {\n  const errors = {};\n  if (!values.user?.email) errors.email = 'Required';\n  return errors;\n}","handlingStrategy":"try-catch","validationCode":"// before wiring validate, smoke-test it against initial values\nimport { get } from 'lodash';\nconst errors = safeValidate(validateFn, initialValues);\nconsole.log(errors); // inspect for thrown exceptions vs returned errors","typeGuard":"const isSafeValidate = (fn: (v: any) => any) =>\n  typeof fn === 'function';\n\n// wrap to guarantee resolution to an errors object\nconst safeValidate = (fn: FormikConfig<V>['validate'], values: V) => {\n  try { return fn(values) ?? {}; } catch (e) { return { _: 'Validation crashed' }; }\n};","tryCatchPattern":"validate: async values => {\n  try {\n    return await myValidate(values);\n  } catch (e) {\n    return { form: 'Could not validate, please retry.' };\n  }\n}","preventionTips":["Always resolve validate to an errors object; never let it throw","Use optional chaining / lodash get for nested value access","Initialize all nested paths in initialValues"],"tags":["formik","validation","async","unhandled-rejection"],"backgroundTag":"validation-function-throw","analyzedSha":"91475adbf33579561e580eceea0c031f4ec2e992","analyzedAt":"2026-08-27T12:26:57.937Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}