{"record":{"id":"5a5cad208ae131d7","repo":"Hmbown/CodeWhale","slug":"invalid-recording-archive","errorCode":null,"errorMessage":"Invalid recording archive.","messagePattern":"Invalid recording archive\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"pet/src/ui/storage.ts","lineNumber":167,"sourceCode":"        }\n        const revision = (previous?.revision ?? 0) + 1;\n        if (archive) {\n          habitats.add(archive, `pet-archive-${revision}`);\n          habitats.add({ key: revision, name: archive.sourceName, seconds: archive.seconds,\n            startSeconds: (archive.start?.frame.timeMs ?? 0) / 1000 }, `pet-archive-meta-${revision}`);\n        }\n        habitats.put({ revision, habitat }, 'pet'); done(revision);\n      };\n    });\n  }\n  async petArchives(): Promise<PetArchive[]> {\n    return this.transaction('readonly', (_traces, _metas, done, _fail, habitats) => {\n      const request = habitats.getAll(IDBKeyRange.bound('pet-archive-meta-', 'pet-archive-meta-\\uffff'));\n      request.onsuccess = () => done((request.result as PetArchive[]).sort((a, b) => b.key - a.key));\n    });\n  }\n  async petArchive(key: number): Promise<SavedHabitat> {\n    if (!Number.isSafeInteger(key) || key < 1) throw new Error('Invalid recording archive.');\n    return this.transaction('readonly', (_traces, _metas, done, fail, habitats) => {\n      const request = habitats.get(`pet-archive-${key}`);\n      request.onsuccess = () => request.result ? done(request.result) : fail(new Error('This recording is unavailable.'));\n    });\n  }\n}\n","sourceCodeStart":149,"sourceCodeEnd":174,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/pet/src/ui/storage.ts#L149-L174","documentation":"petArchive(key) validates that the requested archive key is a safe positive integer before looking up the IndexedDB habitat store. It throws this Error when the key argument itself is malformed; a well-formed but absent key produces the distinct 'This recording is unavailable.' error instead.","triggerScenarios":"Calling petArchive(0), petArchive(-5), petArchive(1.5), petArchive(2**53), or petArchive(NaN) — any key failing Number.isSafeInteger(key) || key >= 1.","commonSituations":"Parsing an id from a URL query string without Number conversion, passing undefined/null from an unverified record field, or deserializing a corrupted archive reference.","solutions":["Coerce and validate the key with Number before calling: const k = Number(raw); if (!Number.isSafeInteger(k) || k < 1) ...","Guard the call site to only pass keys that came from a listed PetArchive record.","Handle the thrown error in the UI to show an invalid-link message."],"exampleFix":"// before\nawait store.petArchive(params.id);\n// after\nconst key = Number(params.id);\nif (!Number.isSafeInteger(key) || key < 1) return showError('Invalid archive id');\nawait store.petArchive(key);","handlingStrategy":"validation","validationCode":"function isValidArchiveKey(key) { return Number.isSafeInteger(key) && key >= 1; }\nif (!isValidArchiveKey(key)) throw new RangeError('archive key must be a positive safe integer');","typeGuard":"const isValidArchiveKey = (k: unknown): k is number => typeof k === 'number' && Number.isSafeInteger(k) && k >= 1;","tryCatchPattern":null,"preventionTips":["Coerce URL params with Number() and validate before storage calls.","Only pass keys sourced from stored PetArchive records.","Distinguish invalid-key errors from 'unavailable' errors in user messaging."],"tags":["validation","indexeddb","invalid-key"],"backgroundTag":"invalid-argument-value","analyzedSha":"433685b2024e7bc4c99e1e2e326bcad39b4d9d65","analyzedAt":"2026-09-15T12:24:24.634Z","contentChangedAt":"2026-09-15T12:24:24.634Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}