amruthpillai/reactive-resume · error · Error

Patch produced invalid resume data: ${error instanceof Error

Error message

Patch produced invalid resume data: ${error instanceof Error ? error.message : String(error)}

What it means

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.

Source

Thrown at packages/resume/src/patch.ts:123

	// Validate operations structurally before applying.
	const validationError = jsonpatch.validate(operations, data);
	if (validationError) throw toResumePatchError(validationError);

	// Apply operations. applyPatch throws on `test` failures.
	let patched: ResumeData;

	try {
		const result = jsonpatch.applyPatch(data, operations, false, false);
		patched = result.newDocument;
	} catch (error: unknown) {
		if (isJsonPatchError(error)) throw toResumePatchError(error);
		throw error;
	}

	try {
		return parseResumeData(patched);
	} catch (error) {
		throw new Error(`Patch produced invalid resume data: ${error instanceof Error ? error.message : String(error)}`, {
			cause: error,
		});
	}
}

View on GitHub (pinned to 3a5b12e2a4)

Solutions

  1. Inspect err.cause (a ZodError) to see exactly which field failed validation.
  2. Adjust the offending patch operation to keep the document schema-valid (correct type, keep required fields).
  3. Pre-validate the patched document with parseResumeData (dry-run) before persisting.
  4. Avoid patches that remove required resume keys; use the higher-level resume mutation API instead.

Example fix

// before: a patch that nulls a required field
[{ op: 'replace', path: '/basics/name', value: null }]
// after
[{ op: 'replace', path: '/basics/name', value: 'Jane Doe' }] // parseResumeData now passes
Defensive patterns

Strategy: try-catch

Validate before calling

// dry-run validation before persisting
const patched = jsonpatch.applyPatch(structuredClone(data), ops, false, false).newDocument;
parseResumeData(patched); // throws ZodError early with clear field errors

Type guard

import { isJsonPatchError } from 'fast-json-patch';
function isPatchError(e: unknown): boolean { return isJsonPatchError(e); }

Try / catch

try { await applyResumePatch(data, ops); }
catch (e) {
  if (e instanceof ZodError) { /* field-level errors in e.issues */ }
  else if (/Patch produced invalid resume data/.test(String((e as Error).message))) {
    const cause = (e as Error).cause; // ZodError
  }
}

Prevention

When it happens

Trigger: 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.

Common situations: Collaborative editing patches that race and produce inconsistent state; a patch generated against an older schema; misuse of replace ops with wrong-typed values.

Related errors


AI-assisted analysis of amruthpillai/reactive-resume@3a5b12e2a4 (2026-08-12). Data as JSON: /api/errors/7b1cb5b5352c1289. Report an issue: GitHub.