{"record":{"id":"7b1cb5b5352c1289","repo":"amruthpillai/reactive-resume","slug":"patch-produced-invalid-resume-data-error-instan","errorCode":null,"errorMessage":"Patch produced invalid resume data: ${error instanceof Error ? error.message : String(error)}","messagePattern":"Patch produced invalid resume data: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/resume/src/patch.ts","lineNumber":123,"sourceCode":"\t// Validate operations structurally before applying.\n\tconst validationError = jsonpatch.validate(operations, data);\n\tif (validationError) throw toResumePatchError(validationError);\n\n\t// Apply operations. applyPatch throws on `test` failures.\n\tlet patched: ResumeData;\n\n\ttry {\n\t\tconst result = jsonpatch.applyPatch(data, operations, false, false);\n\t\tpatched = result.newDocument;\n\t} catch (error: unknown) {\n\t\tif (isJsonPatchError(error)) throw toResumePatchError(error);\n\t\tthrow error;\n\t}\n\n\ttry {\n\t\treturn parseResumeData(patched);\n\t} catch (error) {\n\t\tthrow new Error(`Patch produced invalid resume data: ${error instanceof Error ? error.message : String(error)}`, {\n\t\t\tcause: error,\n\t\t});\n\t}\n}\n","sourceCodeStart":105,"sourceCodeEnd":128,"githubUrl":"https://github.com/amruthpillai/reactive-resume/blob/3a5b12e2a40374a9571988701fcb75c5a1831c42/packages/resume/src/patch.ts#L105-L128","documentation":"applyResumePatch runs jsonpatch.applyPatch then parses the result with parseResumeData. If the patch applied without a JSON-Patch error but the resulting document violates the resume Zod schema, it throws a wrapped Error whose message embeds the parse error and sets the original as cause. Distinguish via isJsonPatchError earlier in the function.","triggerScenarios":"A JSON Patch operation that deletes a required field, renames a key to an invalid type, sets metadata.template to an unknown template, or otherwise produces a structurally-invalid resume; an AI/automation client composing patches without schema awareness.","commonSituations":"Collaborative editing patches that race and produce inconsistent state; a patch generated against an older schema; misuse of replace ops with wrong-typed values.","solutions":["Inspect err.cause (a ZodError) to see exactly which field failed validation.","Adjust the offending patch operation to keep the document schema-valid (correct type, keep required fields).","Pre-validate the patched document with parseResumeData (dry-run) before persisting.","Avoid patches that remove required resume keys; use the higher-level resume mutation API instead."],"exampleFix":"// before: a patch that nulls a required field\n[{ op: 'replace', path: '/basics/name', value: null }]\n// after\n[{ op: 'replace', path: '/basics/name', value: 'Jane Doe' }] // parseResumeData now passes","handlingStrategy":"try-catch","validationCode":"// dry-run validation before persisting\nconst patched = jsonpatch.applyPatch(structuredClone(data), ops, false, false).newDocument;\nparseResumeData(patched); // throws ZodError early with clear field errors","typeGuard":"import { isJsonPatchError } from 'fast-json-patch';\nfunction isPatchError(e: unknown): boolean { return isJsonPatchError(e); }","tryCatchPattern":"try { await applyResumePatch(data, ops); }\ncatch (e) {\n  if (e instanceof ZodError) { /* field-level errors in e.issues */ }\n  else if (/Patch produced invalid resume data/.test(String((e as Error).message))) {\n    const cause = (e as Error).cause; // ZodError\n  }\n}","preventionTips":["Pre-validate patched documents with parseResumeData.","Avoid patches that drop required fields.","Use the typed resume mutation API instead of raw patches when possible."],"tags":["resume","json-patch","zod","validation","patch"],"backgroundTag":null,"analyzedSha":"3a5b12e2a40374a9571988701fcb75c5a1831c42","analyzedAt":"2026-08-12T22:31:22.666Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}