{"record":{"id":"a2cab54351ae936c","repo":"thedotmack/claude-mem","slug":"servergenerationjobpayloadvalidationerror","errorCode":null,"errorMessage":"ServerGenerationJobPayloadValidationError","messagePattern":"ServerGenerationJobPayloadValidationError","errorType":"validation","errorClass":"ServerGenerationJobPayloadValidationError","httpStatus":null,"severity":"error","filePath":"src/server/jobs/types.ts","lineNumber":124,"sourceCode":"  constructor(issues: z.ZodIssue[]) {\n    super(`invalid server generation job payload: ${issues.map(i => i.message).join('; ')}`);\n    this.issues = issues;\n  }\n}\n\n/**\n * Validate a candidate BullMQ payload against the discriminated union and\n * return a typed payload, or throw `ServerGenerationJobPayloadValidationError`.\n * Use this at every enqueue site so a malformed payload never enters the\n * transport — the worker MUST also re-validate from Postgres but defense in\n * depth is cheap.\n */\nexport function assertServerGenerationJobPayload(\n  candidate: unknown,\n): ServerGenerationJobPayload {\n  const result = ServerGenerationJobPayloadSchema.safeParse(candidate);\n  if (!result.success) {\n    throw new ServerGenerationJobPayloadValidationError(result.error.issues);\n  }\n  return result.data as ServerGenerationJobPayload;\n}\n","sourceCodeStart":106,"sourceCodeEnd":128,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/d8bc9755e74915e5c3b999181e10a67c889bce2a/src/server/jobs/types.ts#L106-L128","documentation":"assertServerGenerationJobPayload validates an unknown payload against ServerGenerationJobPayloadSchema (Zod). If parsing fails it throws ServerGenerationJobPayloadValidationError carrying the Zod issues, because processing a malformed generation job would produce corrupt or unsafe behavior downstream.","triggerScenarios":"A job dequeued by process() (or passed to validated()) whose payload does not match the schema: missing required fields, wrong types, or unexpected shapes — e.g. jobs enqueued by an older version or hand-crafted entries.","commonSituations":"Schema updated after jobs were already queued; a different service enqueues payloads that drifted from the current schema; manual Redis inspection/insertion of job records; version skew between producer and consumer.","solutions":["Fix the producer so it enqueues payloads matching ServerGenerationJobPayloadSchema","Read the Zod issues on the error to identify the exact missing/mismatched fields","Drain or migrate stale jobs created under the old schema before deploying the new one","If extending the schema, make new fields optional or versioned to stay backward-compatible"],"exampleFix":"// before\nawait queue.add(jobId, { prompt }); // missing required 'generationId'\n// after\nawait queue.add(jobId, { prompt, generationId: crypto.randomUUID() });","handlingStrategy":"validation","validationCode":"const parsed = ServerGenerationJobPayloadSchema.safeParse(candidate);\nif (!parsed.success) {\n  console.error(parsed.error.issues);\n  throw new Error('payload fails ServerGenerationJobPayloadSchema');\n}","typeGuard":"const isValidPayload = (c: unknown): c is ServerGenerationJobPayload =>\n  ServerGenerationJobPayloadSchema.safeParse(c).success;","tryCatchPattern":"try {\n  const payload = assertServerGenerationJobPayload(candidate);\n  // process payload\n} catch (e) {\n  if (e instanceof ServerGenerationJobPayloadValidationError) {\n    logger.error('invalid job payload', { issues: e.issues });\n    return; // or dead-letter the job\n  }\n  throw e;\n}","preventionTips":["Validate payloads with the same schema at enqueue time","Version the payload schema and migrate queued jobs on deploy","Keep producer and consumer on the same published version of types.ts"],"tags":["validation","zod","schema","payload","jobs"],"backgroundTag":"schema-validation-failed","analyzedSha":"d8bc9755e74915e5c3b999181e10a67c889bce2a","analyzedAt":"2026-09-17T16:40:26.182Z","contentChangedAt":"2026-09-17T16:40:26.182Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}