jackwener/OpenCLI · error · CommandExecutionError

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

Error message

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

What it means

CommandExecutionError from `storage-get` when `localStorage`/`sessionStorage.getItem(key)` returns null in the Trae renderer, i.e. the key does not exist in the selected storage area at read time. The error message embeds both the store name and the requested key.

Source

Thrown at clis/trae-solo/renderer-storage.js:95

    site: 'trae-solo',
    name: 'storage-get',
    access: 'read',
    description: 'Read a single localStorage / sessionStorage value on the Trae SOLO renderer.',
    domain: 'localhost',
    strategy: Strategy.UI,
    browser: true,
    args: [
        { name: 'key', positional: true, required: true, help: 'Storage key (use storage-keys to discover)' },
        { name: 'storage', required: false, default: 'local', help: '"local" or "session"' },
        { name: 'max-bytes', type: 'int', required: false, default: 4000, help: 'Truncate value to this many chars' },
    ],
    columns: ['Field', 'Value'],
    func: async (page, kwargs) => {
        const key = String(kwargs?.key || '').trim();
        if (!key) throw new ArgumentError('key', 'is required');
        const store = pickStore(kwargs);
        const raw = await page.evaluate(`${store}.getItem(${JSON.stringify(key)})`);
        if (raw === null) 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, 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 },
        ];
    },
});

// -------- cookies --------
cli({
    site: 'trae-solo',

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Confirm the exact key with storage-keys (try both storage=local and storage=session).
  2. Check key spelling and case — getItem is case-sensitive.
  3. Trigger the app action that writes the key (log in, change a setting) before reading.
  4. Add a fallback that tries the other storage area before giving up.

Example fix

// before
const v = await cli('trae-solo', 'storage-get', { key: 'authToken' });
// after
function get(store) { return cli('trae-solo', 'storage-get', { key: 'authToken', storage: store }); }
let v; try { v = await get('local'); } catch { v = await get('session'); }
Defensive patterns

Strategy: fallback

Validate before calling

const keys = await cli('trae-solo', 'storage-keys', { storage });
if (!keys.some(k => k.Key === key)) {
  throw new Error(`'${key}' not in ${storage}. Existing: ${keys.map(k => k.Key).join(', ')}`);
}

Type guard

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

Try / catch

try {
  val = await cli('trae-solo', 'storage-get', { key, storage: 'local' });
} catch (e) {
  if (/Key not found/.test(e.message)) {
    val = await cli('trae-solo', 'storage-get', { key, storage: 'session' });
  } else throw e;
}

Prevention

When it happens

Trigger: Reading a key that was never written, was deleted (logout clears session data), exists only in sessionStorage while reading localStorage (default) or vice versa, or key name differs in case/spelling — Web Storage keys are case-sensitive.

Common situations: Assuming a token is in localStorage when the app uses sessionStorage; inspecting before login/first-run wrote the key; Trae updated and renamed internal keys; reading the wrong window/page state.

Related errors


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