jackwener/OpenCLI · error · ArgumentError

is required

Error message

is required

What it means

ArgumentError thrown by the kimi storage get command when the required 'key' argument is missing or trims to an empty string. The func re-checks the positional/flag value defensively before touching the page.

Source

Thrown at clis/kimi/storage.js:86

cli({
    site: 'kimi',
    name: 'storage-get',
    access: 'read',
    description: 'Read a single localStorage / sessionStorage value on kimi.com. Auto-decodes JSON.',
    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 },

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass the key explicitly: kimi storage get --key "myKey"
  2. Check shell quoting/variable expansion so the key isn't lost
  3. Validate the key is non-empty in your wrapper before invoking

Example fix

// before
const key = cfg.storageKey; // may be undefined
await kimi(['storage', 'get', '--key', key]);
// after
if (!cfg.storageKey) throw new Error('cfg.storageKey is required');
await kimi(['storage', 'get', '--key', cfg.storageKey]);
Defensive patterns

Strategy: validation

Validate before calling

function assertKey(key) {
  const k = String(key ?? '').trim();
  if (!k) throw new Error('storage get requires --key');
  return k;
}
assertKey(opts.key);

Type guard

const hasKey = (v) => typeof v === 'string' && v.trim().length > 0;

Try / catch

try {
  await kimi(['storage', 'get', '--key', key]);
} catch (e) {
  if (/is required/.test(e.message) && /key/.test(e.message)) {
    console.error('Usage: kimi storage get --key <key> [--storage local|session]');
    process.exit(2);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling `kimi storage get` without --key, with --key "", or with a whitespace-only value so String(kwargs?.key||'').trim() is empty.

Common situations: Shell quoting dropping the argument, a wrapper passing an empty variable, or forgetting that key is required while storage (default 'local') is optional.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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