{"record":{"id":"e3569d5f1b7cb7b2","repo":"moeru-ai/airi","slug":"invalid-godot-stage-view-state-error-payload","errorCode":null,"errorMessage":"Invalid Godot stage view-state error payload.","messagePattern":"Invalid Godot stage view-state error payload\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/stage-shared/src/godot-stage/view-state.ts","lineNumber":178,"sourceCode":"\n/** Error event emitted by Godot for view-state request, validation, or lifecycle failures. */\nexport interface StageViewErrorPayload {\n  code: StageViewErrorCode\n  message: string\n  requestId?: string\n}\n\nexport const StageViewErrorPayloadSchema = strictObject({\n  code: picklist(['invalid-payload', 'invalid-state-file', 'persistence-failed', 'storage-root-missing', 'view-state-unavailable']),\n  message: string(),\n  requestId: requestIdSchema,\n})\n\n/** Parses a Godot-emitted view-state error. */\nexport function parseStageViewErrorPayload(payload: unknown): StageViewErrorPayload {\n  const result = safeParse(StageViewErrorPayloadSchema, payload)\n  if (!result.success)\n    throw new Error('Invalid Godot stage view-state error payload.')\n\n  return {\n    code: result.output.code,\n    message: result.output.message,\n    ...(result.output.requestId != null ? { requestId: result.output.requestId } : {}),\n  }\n}\n","sourceCodeStart":160,"sourceCodeEnd":186,"githubUrl":"https://github.com/moeru-ai/airi/blob/677329427f32468c74b17f3ec47eeca4e05bec65/packages/stage-shared/src/godot-stage/view-state.ts#L160-L186","documentation":"Thrown by parseStageViewErrorPayload when a Godot-emitted error event fails safeParse against StageViewErrorPayloadSchema. The schema is a strictObject requiring `code` to be one of 'invalid-payload' | 'invalid-state-file' | 'persistence-failed' | 'storage-root-missing' | 'view-state-unavailable', `message` to be a string, plus a `requestId`. Any unknown code, missing field, or extra key makes the parse fail — the irony being this parser handles error events themselves.","triggerScenarios":"The Godot side emits an error with a newly introduced code string (e.g. 'disk-full') not present in the picklist, omits `message`, or the error envelope is forwarded as a JSON string instead of an object.","commonSituations":"Version skew after someone adds a new StageViewErrorCode on the engine side without updating packages/stage-shared; GDScript error paths that build the table manually and typo a code ('Invalid-Payload'); tests that stub error payloads with only a message field.","solutions":["Run safeParse(StageViewErrorPayloadSchema, payload) yourself and inspect r.issues to see which field (usually `code`) is off","Diff the code list in the Godot emission site against the picklist in view-state.ts and sync them in one change","When adding a new code, extend both the picklist and the StageViewErrorCode union type, then rebuild both packages","For forwarded errors, degrade gracefully: if parsing fails, surface the raw payload in logs rather than dropping it"],"exampleFix":"// before\nconst err = parseStageViewErrorPayload(payload)\n\n// after\nimport { safeParse, StageViewErrorPayloadSchema } from '../godot-stage/view-state'\nconst r = safeParse(StageViewErrorPayloadSchema, payload)\nif (!r.success) {\n  // keep the raw error visible instead of failing opaquely\n  console.error('unrecognized Godot view-state error payload', payload, r.issues)\n} else {\n  handleKnownCode(r.output.code)\n}","handlingStrategy":"try-catch","validationCode":"import { safeParse, StageViewErrorPayloadSchema } from '../godot-stage/view-state'\n\nconst ok = safeParse(StageViewErrorPayloadSchema, payload).success","typeGuard":"const isKnownViewErrorCode = (c: unknown): c is 'invalid-payload' | 'invalid-state-file' | 'persistence-failed' | 'storage-root-missing' | 'view-state-unavailable' => typeof c === 'string' && ['invalid-payload','invalid-state-file','persistence-failed','storage-root-missing','view-state-unavailable'].includes(c)","tryCatchPattern":"catch (e) { if (e.message.includes('view-state error payload')) { console.error('raw Godot error event (unparsed):', payload); return } throw e }","preventionTips":["Sync StageViewErrorCode between engine and host in one change","Degrade to logging the raw payload instead of failing when an unknown error code arrives","Write unit tests for every emitted code string"],"tags":["valibot","schema-validation","godot","error-envelope","ipc-payload"],"backgroundTag":"schema-validation-failed","analyzedSha":"677329427f32468c74b17f3ec47eeca4e05bec65","analyzedAt":"2026-08-18T17:29:58.153Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}