{"record":{"id":"cf05a5a0765d65de","repo":"amruthpillai/reactive-resume","slug":"json-stringify-flattenerror-error","errorCode":null,"errorMessage":"JSON.stringify(flattenError(error))","messagePattern":"JSON\\.stringify\\(flattenError\\(error\\)\\)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"packages/import/src/error.ts","lineNumber":6,"sourceCode":"import { flattenError, ZodError } from \"zod\";\n\n/** Rethrows a ZodError as a serialized string error; re-throws other errors as-is. */\nexport function rethrowAsImportError(error: unknown): never {\n\tif (error instanceof ZodError) {\n\t\tthrow new Error(JSON.stringify(flattenError(error)));\n\t}\n\tthrow error;\n}\n","sourceCodeStart":1,"sourceCodeEnd":10,"githubUrl":"https://github.com/amruthpillai/reactive-resume/blob/3a5b12e2a40374a9571988701fcb75c5a1831c42/packages/import/src/error.ts#L1-L10","documentation":"rethrowAsImportError converts a ZodError from resume parsing into a generic Error whose message is the JSON-serialized flattened error (issue + form errors). It is thrown during resume import when the imported payload, after transformation, fails the resume Zod schema. The message string is intentionally machine-readable JSON, not prose.","triggerScenarios":"Importing a JSON/ZIP/LinkedIn/Reactive-Resume export whose structure does not match the current resume schema; a version skew between the export producer and the running schema; a partially-corrupt export.","commonSituations":"User uploads an export from an older/newer Reactive Resume version; a third-party 'resume.json' missing required fields; an import adapter that didn't fill required defaults.","solutions":["Catch the error and JSON.parse(err.message) to display the flattened field errors to the user.","Pre-validate the imported object against the public resume schema before calling the import pipeline.","Update the export source to include all required resume fields for the current schema version.","If migrating an old export, run it through the schema migration/upgrade step before import."],"exampleFix":"// before: surfacing raw JSON message\ntry { await importResume(file); }\ncatch (e) { toast.error(String(e.message)); }\n// after: parse and display flattened errors\ntry { await importResume(file); }\ncatch (e) {\n  const flat = safeJsonParse(e.message);\n  toast.error(flat ? formatFlattened(flat) : 'Import failed');\n}","handlingStrategy":"try-catch","validationCode":"import { parseResumeData } from '@reactive-resume/schema';\nconst parsed = parseResumeData(raw); // throws ZodError before the import pipeline does","typeGuard":"function isSerializedZod(e: unknown): boolean {\n  if (!(e instanceof Error)) return false;\n  try { JSON.parse(e.message); return true; } catch { return false; }\n}","tryCatchPattern":"try { await importResume(file); }\ncatch (e) {\n  const flat = isSerializedZod(e) ? JSON.parse((e as Error).message) : null;\n  ui.error(flat ? formatFlattened(flat) : 'Import failed');\n}","preventionTips":["Pre-validate imports against the public resume schema.","Migrate old exports to the current schema before import.","Display flattened field errors to the user."],"tags":["import","zod","serialization","validation","resume"],"backgroundTag":null,"analyzedSha":"3a5b12e2a40374a9571988701fcb75c5a1831c42","analyzedAt":"2026-08-12T22:31:22.666Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}