{"record":{"id":"a8f051fd6ba74ac8","repo":"Hmbown/CodeWhale","slug":"invalid-pet-recording-world","errorCode":null,"errorMessage":"Invalid pet recording.","messagePattern":"Invalid pet recording\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"pet/src/core/pet-world.ts","lineNumber":138,"sourceCode":"      targetX: this.targetX, targetY: this.targetY, x: this.x, y: this.y, flip: this.flip, lit: this.lit,\n      lastActivity: this.lastActivity, addressedAt: Number.isFinite(this.addressedAt) ? this.addressedAt : null,\n      waitSince: this.waitSince, food: this.food, members: [...this.members.values()], lastStill: this.lastStill,\n      frame: this.frame, voices: this.voices });\n  }\n\n  recording(withCheckpoint = true, completed = false): PetRecording {\n    const tapeEnd = completed ? this.bucketIndex + 1 : this.tapeLog.length;\n    const inputEnd = completed ? this.interactionIndex : this.interactionLog.length;\n    const history = this.historyDigest(tapeEnd, inputEnd);\n    return { petReplayVersion: this.segmented ? 2 : 1, expressionVersion: this.sim.expressionVersion,\n      tape: this.tapeLog.slice(0, tapeEnd), interactions: this.interactionLog.slice(0, inputEnd).map(e => ({ ...e })),\n      ...(this.origin ? { start: { ...structuredClone(this.origin), hasTelemetry: this.hasTelemetry, history } } : {}),\n      ...(withCheckpoint ? { checkpoint: { ...this.checkpoint(), history } } : {}) };\n  }\n\n  static fromRecording(points: [number, number][], value: unknown): PetWorld {\n    const r = value as PetRecording;\n    if (!r || ![1, 2].includes(r.petReplayVersion) || !Array.isArray(r.tape) || !Array.isArray(r.interactions)) throw new Error('Invalid pet recording.');\n    const version = r.expressionVersion === undefined ? 1 : r.expressionVersion;\n    if (![1, 2].includes(version)) throw new Error('Unsupported pet expression version.');\n    if (r.checkpoint !== undefined && !r.checkpoint || r.start !== undefined && !r.start) throw new Error('Invalid pet checkpoint.');\n    for (const c of [r.start, r.checkpoint]) if (c && (c.sim?.expressionVersion ?? 1) !== version) throw new Error('Pet expression version does not match its checkpoint.');\n    if (r.petReplayVersion === 1 && (r.start || r.checkpoint && r.checkpoint.petCheckpointVersion !== 1)) throw new Error('Invalid legacy pet recording.');\n    if (r.petReplayVersion === 2 && (!r.start || r.start.petCheckpointVersion !== 2 || r.start.historyStart !== r.start.tick)) throw new Error('The recording segment is missing its starting checkpoint.');\n    const first = r.start && PetWorld.restore(points, r.tape, r.interactions, r.start);\n    const world = r.checkpoint ? PetWorld.restore(points, r.tape, r.interactions, r.checkpoint) : first ?? new PetWorld(points, r.tape, r.interactions, version);\n    if (first) {\n      if (!world.segmented || world.tick < first.tick || r.checkpoint && r.checkpoint.historyStart !== first.tick) throw new Error('Pet segment checkpoints do not agree.');\n      world.origin = first.checkpoint();\n    }\n    return world;\n  }\n\n  /** Retire only consumed input. The exact origin makes each archived segment\n   * independently replayable; no particle, random stream or score is reset. */\n  prepareSegment(): PetSegment {","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/pet/src/core/pet-world.ts#L120-L156","documentation":"fromRecording is the trusted entry point for loading a serialized PetRecording. The value must be a truthy object with petReplayVersion 1 or 2, and array-valued tape and interactions. Anything else throws this error.","triggerScenarios":"Passing null/undefined, a JSON string instead of a parsed object, petReplayVersion 3 or missing, or tape/interactions that are not arrays (or absent) to PetWorld.fromRecording(points, value).","commonSituations":"Loading a file saved by a newer app version with an unknown replay version; forgetting JSON.parse; a corrupted or truncated recording file; passing an old export shape without tape/interactions.","solutions":["Parse the file with JSON.parse before passing it to fromRecording.","Check recording.petReplayVersion is 1 or 2 and that tape and interactions are arrays.","Re-export the recording from a compatible app version.","Validate the recording shape before calling fromRecording."],"exampleFix":"// before\nconst world = PetWorld.fromRecording(points, localStorage.getItem('rec'));\n// after\nconst raw = JSON.parse(localStorage.getItem('rec'));\nconst world = PetWorld.fromRecording(points, raw);","handlingStrategy":"type-guard","validationCode":"function looksLikeRecording(v) { return !!v && typeof v === 'object' && [1,2].includes(v.petReplayVersion) && Array.isArray(v.tape) && Array.isArray(v.interactions); }\nif (!looksLikeRecording(parsed)) throw new Error('Not a pet recording');","typeGuard":"const isPetRecording = (v): v is PetRecording => !!v && typeof v === 'object' && [1,2].includes((v as any).petReplayVersion) && Array.isArray((v as any).tape) && Array.isArray((v as any).interactions);","tryCatchPattern":"try { world = PetWorld.fromRecording(points, value); } catch (e) { if (e.message === 'Invalid pet recording.') showCorruptRecordingDialog(); }","preventionTips":["JSON.parse stored strings before passing them.","Store petReplayVersion in the file and check it before load."],"tags":["validation","deserialization"],"backgroundTag":"schema-validation-failed","analyzedSha":"433685b2024e7bc4c99e1e2e326bcad39b4d9d65","analyzedAt":"2026-09-15T12:24:24.634Z","contentChangedAt":"2026-09-15T12:24:24.634Z","schemaVersion":2},"datasetVersion":"2026-09-22T11:17:16.035Z"}