jackwener/OpenCLI · error · CommandExecutionError

Key not found in ${store}: ${key}

Error message

Key not found in ${store}: ${key}

What it means

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.

Source

Thrown at clis/kimi/storage.js:91

    domain: KIMI_DOMAIN,
    strategy: Strategy.COOKIE,
    browser: true,
    siteSession: 'persistent',
    navigateBefore: false,
    args: [
        { name: 'key', positional: true, required: true, help: 'Storage key' },
        { name: 'storage', required: false, default: 'local' },
        { name: 'max-bytes', type: 'int', required: false, default: 4000 },
    ],
    columns: STORAGE_COLUMNS,
    func: async (page, kwargs) => {
        const key = String(kwargs?.key || '').trim();
        if (!key) throw new ArgumentError('key', 'is required');
        await ensureOnKimi(page);
        const store = pickStore(kwargs);
        const raw = await page.evaluate(`${store}.getItem(${JSON.stringify(key)})`);
        if (raw === null || raw === undefined) {
            throw new CommandExecutionError(`Key not found in ${store}: ${key}`, '');
        }
        const max = Number.isInteger(kwargs['max-bytes']) && kwargs['max-bytes'] > 0 ? kwargs['max-bytes'] : 4000;
        let parsed = raw;
        let kind = 'string';
        try {
            parsed = JSON.parse(raw);
            kind = Array.isArray(parsed) ? 'array' : typeof parsed;
        } catch {}
        const text = kind === 'string' ? parsed : JSON.stringify(parsed, null, 2);
        const truncated = text.length > max;
        return [
            { Field: 'Key', Value: key },
            { Field: 'Store', Value: store },
            { Field: 'Type', Value: kind },
            { Field: 'Size', Value: `${text.length} chars${truncated ? ' (truncated)' : ''}` },
            { Field: 'Value', Value: truncated ? text.slice(0, max) + '\n...(truncated)' : text },
        ];
    },

View on GitHub (pinned to 49907e53dc)

Solutions

  1. List available keys first with kimi storage keys and use an exact key name from that output
  2. Try the other store: --storage session vs --storage local
  3. Ensure you are on the same origin/profile where the key was written (ensureOnKimi navigates to Kimi, but cookies/profile matter)
  4. If the value may legitimately be absent, catch this error and treat it as a miss rather than a crash

Example fix

// before
const val = await kimi(['storage', 'get', '--key', 'theme']);
// after
try {
  const val = await kimi(['storage', 'get', '--key', 'theme']);
} catch (e) {
  if (/Key not found/.test(e.message)) {
    const keys = await kimi(['storage', 'keys']);
    // pick the correct key or fall back to a default
  } else throw e;
}
Defensive patterns

Strategy: fallback

Validate before calling

// verify the key exists before getting it
const keys = await kimi(['storage', 'keys', '--storage', store]);
if (!keys.some(k => k.Key === key)) console.warn(`key "${key}" not in ${store}`);

Type guard

const keyExists = (rows, key) => Array.isArray(rows) && rows.some((r) => r.Key === key);

Try / catch

try {
  return await kimi(['storage', 'get', '--key', key, '--storage', store]);
} catch (e) {
  if (/Key not found/.test(e.message)) {
    // try the other store, then default value
    return store === 'local'
      ? await kimi(['storage', 'get', '--key', key, '--storage', 'session'])
      : defaultValue;
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/6737b8238c919d45. Report an issue: GitHub.