jackwener/OpenCLI · error · ArgumentError

must be "local" or "session"

Error message

must be "local" or "session"

What it means

ArgumentError raised by pickStore in clis/kimi/storage.js when the 'storage' argument is neither 'local' nor 'session' (case-insensitive). pickStore normalizes the value and maps it to localStorage/sessionStorage; anything else is rejected. It is reached through the store-reading storage commands.

Source

Thrown at clis/kimi/storage.js:21

//   storage-keys [--storage local|session] [--filter]
//   storage-get <key> [--storage] [--max-bytes]
//   cookies         — list JS-visible cookies
//   idb-list        — list IndexedDB databases on kimi.com

import { cli, Strategy } from '@jackwener/opencli/registry';
import {
    ArgumentError,
    CommandExecutionError,
    EmptyResultError,
} from '@jackwener/opencli/errors';
import { KIMI_DOMAIN, ensureOnKimi } from './_utils.js';

const STORAGE_COLUMNS = ['Field', 'Value', 'Index', 'Key', 'Bytes', 'Name', 'Preview', 'Database', 'Version'];

function pickStore(args) {
    const s = String(args?.storage || 'local').trim().toLowerCase();
    if (s !== 'local' && s !== 'session') {
        throw new ArgumentError('storage', 'must be "local" or "session"');
    }
    return s === 'session' ? 'sessionStorage' : 'localStorage';
}

// -------- storage-keys --------
cli({
    site: 'kimi',
    name: 'storage-keys',
    access: 'read',
    description: 'List localStorage / sessionStorage keys on kimi.com (with byte sizes).',
    domain: KIMI_DOMAIN,
    strategy: Strategy.COOKIE,
    browser: true,
    siteSession: 'persistent',
    navigateBefore: false,
    args: [
        { name: 'storage', required: false, default: 'local', help: '"local" or "session"' },
        { name: 'filter', required: false, help: 'Case-insensitive substring filter over keys' },

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Use --storage local or --storage session exactly (case-insensitive)
  2. Omit the flag entirely to get the default 'local'
  3. Validate user-supplied storage names in your wrapper before calling the CLI

Example fix

// before
await kimi(['storage', 'keys', '--storage', 'cookie']);
// after
await kimi(['storage', 'keys', '--storage', 'local']);
// or use the cookies command for cookie data:
await kimi(['storage', 'cookies']);
Defensive patterns

Strategy: validation

Validate before calling

function assertStorage(s) {
  const v = String(s ?? 'local').trim().toLowerCase();
  if (v !== 'local' && v !== 'session') throw new Error(`--storage must be "local" or "session", got "${s}"`);
  return v;
}
assertStorage(userInput.storage);

Type guard

const isStorageKind = (v) => v === 'local' || v === 'session' || v === 'sessionStorage' || v === 'localStorage';

Try / catch

try {
  await kimi(['storage', 'keys', '--storage', opts.storage]);
} catch (e) {
  if (/must be "local" or "session"/.test(e.message)) {
    console.error('Allowed values: local, session');
    process.exit(2);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling a kimi storage command (e.g. storage-keys, storage-get) with --storage anything other than local/session, such as 'cookies', 'Local' misspellings like 'loca', 'sessionstorage', or an empty-but-nondefault value.

Common situations: Confusing the storage flag with the separate cookies command, typos in the enum value, or scripts passing a variable that holds an unsupported storage name.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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