{"record":{"id":"6737b8238c919d45","repo":"jackwener/OpenCLI","slug":"key-not-found-in-store-key-6737b8","errorCode":null,"errorMessage":"Key not found in ${store}: ${key}","messagePattern":"Key not found in (.+?): (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/kimi/storage.js","lineNumber":91,"sourceCode":"    domain: KIMI_DOMAIN,\n    strategy: Strategy.COOKIE,\n    browser: true,\n    siteSession: 'persistent',\n    navigateBefore: false,\n    args: [\n        { name: 'key', positional: true, required: true, help: 'Storage key' },\n        { name: 'storage', required: false, default: 'local' },\n        { name: 'max-bytes', type: 'int', required: false, default: 4000 },\n    ],\n    columns: STORAGE_COLUMNS,\n    func: async (page, kwargs) => {\n        const key = String(kwargs?.key || '').trim();\n        if (!key) throw new ArgumentError('key', 'is required');\n        await ensureOnKimi(page);\n        const store = pickStore(kwargs);\n        const raw = await page.evaluate(`${store}.getItem(${JSON.stringify(key)})`);\n        if (raw === null || raw === undefined) {\n            throw new CommandExecutionError(`Key not found in ${store}: ${key}`, '');\n        }\n        const max = Number.isInteger(kwargs['max-bytes']) && kwargs['max-bytes'] > 0 ? kwargs['max-bytes'] : 4000;\n        let parsed = raw;\n        let kind = 'string';\n        try {\n            parsed = JSON.parse(raw);\n            kind = Array.isArray(parsed) ? 'array' : typeof parsed;\n        } catch {}\n        const text = kind === 'string' ? parsed : JSON.stringify(parsed, null, 2);\n        const truncated = text.length > max;\n        return [\n            { Field: 'Key', Value: key },\n            { Field: 'Store', Value: store },\n            { Field: 'Type', Value: kind },\n            { Field: 'Size', Value: `${text.length} chars${truncated ? ' (truncated)' : ''}` },\n            { Field: 'Value', Value: truncated ? text.slice(0, max) + '\\n...(truncated)' : text },\n        ];\n    },","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/kimi/storage.js#L73-L109","documentation":"CommandExecutionError thrown by kimi storage get when localStorage/sessionStorage.getItem(key) returns null/undefined, i.e. the key does not exist in the chosen store on the Kimi page. This is distinct from a validation failure — the argument was fine but the data simply isn't there.","triggerScenarios":"Reading a key that was never set, reading from the wrong store (key is in sessionStorage but --storage local was used), reading on a different origin/profile than where the key was written, or the key being cleared by session expiry.","commonSituations":"Key names that differ by case or prefix, data stored under sessionStorage that vanishes in a new tab/session, switching browser profiles, or assuming Kimi persists a value it keeps only for the session.","solutions":["List available keys first with kimi storage keys and use an exact key name from that output","Try the other store: --storage session vs --storage local","Ensure you are on the same origin/profile where the key was written (ensureOnKimi navigates to Kimi, but cookies/profile matter)","If the value may legitimately be absent, catch this error and treat it as a miss rather than a crash"],"exampleFix":"// before\nconst val = await kimi(['storage', 'get', '--key', 'theme']);\n// after\ntry {\n  const val = await kimi(['storage', 'get', '--key', 'theme']);\n} catch (e) {\n  if (/Key not found/.test(e.message)) {\n    const keys = await kimi(['storage', 'keys']);\n    // pick the correct key or fall back to a default\n  } else throw e;\n}","handlingStrategy":"fallback","validationCode":"// verify the key exists before getting it\nconst keys = await kimi(['storage', 'keys', '--storage', store]);\nif (!keys.some(k => k.Key === key)) console.warn(`key \"${key}\" not in ${store}`);","typeGuard":"const keyExists = (rows, key) => Array.isArray(rows) && rows.some((r) => r.Key === key);","tryCatchPattern":"try {\n  return await kimi(['storage', 'get', '--key', key, '--storage', store]);\n} catch (e) {\n  if (/Key not found/.test(e.message)) {\n    // try the other store, then default value\n    return store === 'local'\n      ? await kimi(['storage', 'get', '--key', key, '--storage', 'session'])\n      : defaultValue;\n  }\n  throw e;\n}","preventionTips":["Use exact key names from kimi storage keys output","Check both local and session stores","Ensure the same browser profile/origin that wrote the key","Treat missing keys as expected misses with defaults"],"tags":["key-not-found","web-storage","kimi"],"backgroundTag":"storage-key-not-found","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}