{"record":{"id":"9bee0d62a3119069","repo":"amruthpillai/reactive-resume","slug":"an-unknown-error-occurred-while-validating-the-mer","errorCode":null,"errorMessage":"An unknown error occurred while validating the merged resume data.","messagePattern":"An unknown error occurred while validating the merged resume data\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/ai/src/resume/sanitize.ts","lineNumber":264,"sourceCode":"\t\tconst coercedData = coerceValueAgainstTemplate(mergedData, defaultResumeData, \"\", diagnostics);\n\t\tconst normalizedData = normalizeResumeDataForSchema(coercedData as Record<string, unknown>, diagnostics);\n\n\t\tconst data = resumeDataSchema.parse({\n\t\t\t...normalizedData,\n\t\t\tcustomSections: [],\n\t\t\tpicture: defaultResumeData.picture,\n\t\t\tmetadata: defaultResumeData.metadata,\n\t\t});\n\n\t\treturn { data, diagnostics };\n\t} catch (error: unknown) {\n\t\tif (error instanceof ZodError) {\n\t\t\tconsole.error(\"Zod validation failed during resume parsing:\", flattenError(error));\n\t\t\tthrow error;\n\t\t}\n\n\t\tconsole.error(\"Unknown error during resume data validation:\", error);\n\t\tthrow new Error(\"An unknown error occurred while validating the merged resume data.\");\n\t}\n}\n","sourceCodeStart":246,"sourceCodeEnd":267,"githubUrl":"https://github.com/amruthpillai/reactive-resume/blob/3a5b12e2a40374a9571988701fcb75c5a1831c42/packages/ai/src/resume/sanitize.ts#L246-L267","documentation":"Generic catch-all in sanitizeAndParseResumeJson: any error during jsonrepair, JSON.parse, mergeDefaults, coerceValueAgainstTemplate, normalizeResumeDataForSchema, or resumeDataSchema.parse that is NOT a ZodError is re-thrown as a plain Error with this message. ZodErrors are re-thrown unchanged (with console.error logging the flattened issue); everything else (broken jsonrepair, thrown primitives, unexpected exceptions in coercers) gets wrapped here after being logged to console as 'Unknown error during resume data validation'.","triggerScenarios":"LLM returned text that jsonrepair cannot fix (e.g. truncated beyond repair); a custom coercer threw a non-Error value; structuredClone/merge failed on a cyclic object built from parsed JSON; an exception inside normalizeResumeDataForTemplate that isn't a Zod issue.","commonSituations":"Streaming truncation produced half a JSON object; the model emitted markdown fences or prose mixed with JSON that the boundary slicer couldn't clean; an upstream change to defaultResumeData introduced a non-serializable value.","solutions":["Inspect server logs: the original error is logged via console.error('Unknown error during resume data validation:', error) immediately before the rethrow — read that line for the real cause.","If it is jsonrepair failing, pre-trim the model output to the outermost {...} before calling sanitizeAndParseResumeJson, or increase the model's max_tokens so output isn't truncated.","If a coercer threw, reproduce with the exact resultText and step through mergeDefaults/coerceValueAgainstTemplate to find the failing branch.","Consider letting ZodErrors surface their issues to the user so they can retry the prompt."],"exampleFix":"// before: only the wrapped message reaches the caller\ntry {\n  sanitizeAndParseResumeJson(text);\n} catch (e) {\n  console.log(e.message); // 'An unknown error occurred...'\n}\n\n// after: surface the original cause for debugging\nthrow new Error('An unknown error occurred while validating the merged resume data.', { cause: error });","handlingStrategy":"try-catch","validationCode":"// Pre-validate that the model output is parseable JSON before sending through sanitize.\nfunction looksLikeCompleteJson(text: string): boolean {\n  const t = text.trim();\n  return t.startsWith('{') && t.endsWith('}') && JSON.parse(structuredClone(t).replace(/```json|```/g, ''));\n}","typeGuard":null,"tryCatchPattern":"try {\n  const { data } = sanitizeAndParseResumeJson(text);\n  useResume(data);\n} catch (err) {\n  if (err instanceof ZodError) showValidationIssues(err.issues);\n  else {\n    // The original cause was logged server-side; ask the user to retry.\n    retryPrompt('The model returned an unparseable resume. Please try again.');\n  }\n}","preventionTips":["Increase model max_tokens to avoid truncated JSON.","Trim the model output to the outermost JSON braces before sanitizing.","Add the underlying cause via Error options for easier triage.","Log the raw resultText alongside the error for post-mortem."],"tags":["ai","resume","json","zod","sanitization","llm-output","wrapping"],"backgroundTag":null,"analyzedSha":"3a5b12e2a40374a9571988701fcb75c5a1831c42","analyzedAt":"2026-08-12T22:31:22.666Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}