{"record":{"id":"ad96e2e38ba80348","repo":"amruthpillai/reactive-resume","slug":"invalid-patch-operations","errorCode":"INVALID_PATCH_OPERATIONS","errorMessage":"Failed to apply patch operations","messagePattern":"Failed to apply patch operations","errorType":"exception","errorClass":"ORPCError","httpStatus":400,"severity":"error","filePath":"packages/api/src/features/resume/service.ts","lineNumber":179,"sourceCode":"\t\tthrow resumeVersionConflict(existing.updatedAt);\n\t}\n\n\tinput.operations.forEach(assertSafePatchPointers);\n\n\tlet patchedData: ResumeData;\n\n\ttry {\n\t\tpatchedData = applyResumePatches(existing.data, input.operations);\n\t} catch (error) {\n\t\tif (error instanceof ResumePatchError) {\n\t\t\tthrow new ORPCError(\"INVALID_PATCH_OPERATIONS\", {\n\t\t\t\tstatus: 400,\n\t\t\t\tmessage: error.message,\n\t\t\t\tdata: { code: error.code, index: error.index, operation: error.operation },\n\t\t\t});\n\t\t}\n\n\t\tthrow new ORPCError(\"INVALID_PATCH_OPERATIONS\", {\n\t\t\tstatus: 400,\n\t\t\tmessage: error instanceof Error ? error.message : \"Failed to apply patch operations\",\n\t\t});\n\t}\n\n\tpatchedData = parseWritableResumeData(preserveServerStylesheet(existing.data, patchedData));\n\tif (\n\t\texisting.data.metadata.stylesheet?.mode === \"semantic\" &&\n\t\tJSON.stringify(existing.data.metadata.styleRules) !== JSON.stringify(patchedData.metadata.styleRules)\n\t) {\n\t\tthrow invalidPatchOperation(\"Legacy style rules cannot be changed while Semantic CSS mode is active.\");\n\t}\n\n\tconst renderDataChanged = hasRenderDataChanged(existing.data, patchedData);\n\tconst [resume] = await client\n\t\t.update(schema.resume)\n\t\t.set({\n\t\t\tdata: patchedData,","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/amruthpillai/reactive-resume/blob/3a5b12e2a40374a9571988701fcb75c5a1831c42/packages/api/src/features/resume/service.ts#L161-L197","documentation":"applyResumePatchTx() wraps applyResumePatches(); if patching throws anything that is not a ResumePatchError, it is re-thrown as INVALID_PATCH_OPERATIONS with the original message. (A ResumePatchError is mapped separately with structured code/index/operation data.) This guards the JSON Patch path against arbitrary failures.","triggerScenarios":"A JSON Patch operation whose 'path' or structure triggers a non-ResumePatchError exception — e.g. an internal assertion, a type error in the patch engine, or an operation the resume patch layer doesn't support.","commonSituations":"A malformed op object, an outdated client building patches against an older resume shape, or a bug in the patch library.","solutions":["Validate operations against the JSON Patch schema and run assertSafePatchPointers before submitting.","Inspect error.message (and for a ResumePatchError, error.data.code/index/operation) to find the offending op.","Reduce the batch to a single op to isolate the failing operation."],"exampleFix":"// before\nresumeService.patch({ id, userId, operations: [{ op: 'replace', path: 'basics.name', value: 123 }] });\n// after\nimport { parseResumeData } from '@reactive-resume/schema/resume/data';\n// ensure value types match the schema; strings stay strings\nresumeService.patch({ id, userId, operations: [{ op: 'replace', path: 'basics.name', value: 'Jane Doe' }] });","handlingStrategy":"validation","validationCode":"function assertSafeOperations(operations) {\n  for (const op of operations) {\n    if (!['add','remove','replace','move','copy','test'].includes(op.op)) throw new Error(`Bad op: ${op.op}`);\n    if (typeof op.path !== 'string' || !op.path.startsWith('/')) throw new Error(`Bad path: ${op.path}`);\n  }\n}","typeGuard":"function isJsonPatchOperation(value: unknown): value is { op: string; path: string; value?: unknown } {\n  return typeof value === 'object' && value !== null && typeof (value as any).op === 'string' && typeof (value as any).path === 'string';\n}","tryCatchPattern":"try {\n  await resumeService.patch({ id, userId, operations });\n} catch (e) {\n  if (e.code === 'INVALID_PATCH_OPERATIONS') {\n    // e.data may carry { code, index, operation } for a ResumePatchError\n    console.error('Patch op failed at index', e.data?.index, e.data?.operation);\n  } else throw e;\n}","preventionTips":["Validate the JSON Patch shape and pointer types before submitting.","Match value types to the schema at each path (e.g. name is a string).","Send small batches so a failing op is easy to isolate."],"tags":["resume","json-patch","validation","bad-request"],"backgroundTag":null,"analyzedSha":"3a5b12e2a40374a9571988701fcb75c5a1831c42","analyzedAt":"2026-08-12T22:31:22.666Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}