{"record":{"id":"04fd2ad2533e93b7","repo":"jquense/yup","slug":"errors-length-errors-occurred","errorCode":null,"errorMessage":"${errors.length} errors occurred","messagePattern":"(.+?) errors occurred","errorType":"validation","errorClass":"ValidationError","httpStatus":null,"severity":"error","filePath":"src/schema.ts","lineNumber":621,"sourceCode":"  validateSync(\n    value: any,\n    options?: ValidateOptions<TContext>,\n  ): this['__outputType'] {\n    let schema = this.resolve({ ...options, value });\n    let result: any;\n    let disableStackTrace =\n      options?.disableStackTrace ?? schema.spec.disableStackTrace;\n\n    schema._validate(\n      value,\n      { ...options, sync: true },\n      (error, parsed) => {\n        if (ValidationError.isError(error)) error.value = parsed;\n        throw error;\n      },\n      (errors, validated) => {\n        if (errors.length)\n          throw new ValidationError(\n            errors!,\n            value,\n            undefined,\n            undefined,\n            disableStackTrace,\n          );\n        result = validated;\n      },\n    );\n\n    return result;\n  }\n\n  isValid(value: any, options?: ValidateOptions<TContext>): Promise<boolean> {\n    return this.validate(value, options).then(\n      () => true,\n      (err) => {\n        if (ValidationError.isError(err)) return false;","sourceCodeStart":603,"sourceCodeEnd":639,"githubUrl":"https://github.com/jquense/yup/blob/ff31eee8a2b10c938bb3a22544d9e33957a8cf01/src/schema.ts#L603-L639","documentation":"validateSync() collects all validation errors and, if any were found, throws a single yup ValidationError whose message is \"N errors occurred\". The individual error details are on the error.value/inner errors — the top message is just a summary count.","triggerScenarios":"Calling schema.validateSync(value) when one or more fields fail validation; thrown instead of returning, even for a single error, because the sync path always aggregates into a ValidationError.","commonSituations":"Synchronous form/server-side validation where submitted data fails multiple rules; code written for validate() (async, returns undefined on failure) ported to validateSync() without a try/catch.","solutions":["Wrap validateSync() in try/catch and read err.value / err.inner / err.path for details","Use err.errors array to get all individual messages","If a promise-based flow is fine, use await validate() which rejects with the same details"],"exampleFix":"// before\nconst val = schema.validateSync(data); // throws '2 errors occurred'\n// after\nlet val;\ntry {\n  val = schema.validateSync(data);\n} catch (err) {\n  console.log(err.errors); // individual messages\n}","handlingStrategy":"try-catch","validationCode":"const { error } = schema.validateSync(data, { abortEarly: false }) instanceof ValidationError ? { error: ... } : {};\n// simpler: pre-check with schema.isValidSync(data)","typeGuard":"function isYupValidationError(e: unknown): e is yup.ValidationError {\n  return yup.ValidationError.isError(e as any);\n}","tryCatchPattern":"try {\n  value = schema.validateSync(data);\n} catch (e) {\n  if (yup.ValidationError.isError(e)) {\n    const messages = e.errors; // individual messages in e.errors\n  } else throw e;\n}","preventionTips":["Always wrap validateSync in try/catch — it signals failure by throwing","Use err.errors / err.inner, not err.message, for per-field details","Consider abortEarly: false to collect all errors at once"],"tags":["validation","aggregate-error","sync-validation"],"backgroundTag":"schema-validation-failed","analyzedSha":"ff31eee8a2b10c938bb3a22544d9e33957a8cf01","analyzedAt":"2026-08-31T21:51:03.773Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}