{"record":{"id":"bf4eb49be1a3e945","repo":"different-ai/openwork","slug":"the-snapshot-response-was-invalid","errorCode":null,"errorMessage":"The snapshot response was invalid.","messagePattern":"The snapshot response was invalid\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ee/apps/den-web/app/(den)/dashboard/_components/workflow-data.tsx","lineNumber":59,"sourceCode":"      );\n      if (typeof payload !== \"object\" || payload === null || !(\"script\" in payload)) throw new Error(\"The Workflow response was invalid.\");\n      return workflowDetailSchema.parse(payload.script);\n    },\n    enabled: Boolean(configObjectId),\n  });\n}\n\nexport function useWorkflowSnapshots(configObjectId: string) {\n  return useQuery({\n    queryKey: keys.snapshots(configObjectId),\n    queryFn: async () => {\n      const payload = await checkedRequest(\n        `/v1/workflows/${encodeURIComponent(configObjectId)}/snapshots?limit=100`,\n        { method: \"GET\" },\n        \"Failed to load snapshots\",\n      );\n      if (typeof payload !== \"object\" || payload === null || !(\"items\" in payload) || !Array.isArray(payload.items)) {\n        throw new Error(\"The snapshot response was invalid.\");\n      }\n      return payload.items.map((item) => workflowArtifactSnapshotSchema.parse(item));\n    },\n    enabled: Boolean(configObjectId),\n  });\n}\n\nfunction useLifecycleMutation<TInput, TResult>(input: {\n  configObjectId: string;\n  mutation: (value: TInput) => Promise<TResult>;\n}) {\n  const queryClient = useQueryClient();\n  return useMutation({\n    mutationFn: input.mutation,\n    onSettled: async () => {\n      await queryClient.invalidateQueries({ queryKey: [\"workflow\", input.configObjectId] });\n      await queryClient.invalidateQueries({ queryKey: [\"plugins\"] });\n      await queryClient.invalidateQueries({ queryKey: [\"automations\"] });","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/ee/apps/den-web/app/(den)/dashboard/_components/workflow-data.tsx#L41-L77","documentation":"useWorkflowSnapshots GETs /v1/workflows/{id}/snapshots?limit=100 and requires the payload to be an object whose 'items' is an array; otherwise it throws 'The snapshot response was invalid.' Each item is then validated with workflowArtifactSnapshotSchema.parse.","triggerScenarios":"Snapshots endpoint returns ok but body lacks an items array (e.g. {error: ...} with 200, null body, or items as an object), so the Array.isArray check fails.","commonSituations":"API contract change renaming/relocating items; gateway returning an empty JSON body on 200; workflow id valid but snapshots feature disabled server-side returning a bare object.","solutions":["Log the response body to see the actual shape vs expected {items: []}.","Update the client check/parser to match the current API contract, or fix the server to return {items: [...]}.","Verify the workflow id exists (a 404 leaking as a 200-shaped body indicates proxy interference).","If Zod throws on individual items after this check, the items shape changed — update workflowArtifactSnapshotSchema."],"exampleFix":"// before\nif (typeof payload !== \"object\" || payload === null || !(\"items\" in payload) || !Array.isArray(payload.items)) {\n  throw new Error(\"The snapshot response was invalid.\");\n}\n// after\nconst items = (payload as {items?: unknown} | null)?.items;\nif (!Array.isArray(items)) {\n  console.error(\"snapshots payload:\", payload);\n  throw new Error(\"The snapshot response was invalid.\");\n}\nreturn items.map((item) => workflowArtifactSnapshotSchema.parse(item));","handlingStrategy":"type-guard","validationCode":"function hasItemsArray(v: unknown): v is { items: unknown[] } {\n  return isRecord(v) && Array.isArray(v.items);\n}","typeGuard":"function isSnapshotList(v: unknown): v is { items: WorkflowArtifactSnapshot[] } {\n  return isRecord(v) && Array.isArray(v.items) && v.items.every((i) => isRecord(i) && typeof i.id === \"string\");\n}","tryCatchPattern":"try {\n  const snapshots = await snapshotsQuery.refetch();\n} catch (e) {\n  if (e instanceof Error && e.message === \"The snapshot response was invalid.\") {\n    console.error(\"snapshots body shape mismatch\");\n    // render empty state and log payload for contract debugging\n  } else throw e;\n}","preventionTips":["Pin API contract with tests for {items: []} shape","Check response Content-Type before parsing","Update workflowArtifactSnapshotSchema whenever item fields change"],"tags":["api","schema","response-parsing"],"backgroundTag":"schema-validation-failed","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}