{"record":{"id":"9ab66ffefd9cd773","repo":"jackwener/OpenCLI","slug":"key-is-required","errorCode":null,"errorMessage":"key is required","messagePattern":"key is required","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/antigravity/storage.js","lineNumber":129,"sourceCode":"\n// ====== Renderer-side: storage-get ======\ncli({\n    site: 'antigravity',\n    name: 'storage-get',\n    access: 'read',\n    description: 'Read a single localStorage / sessionStorage value on the Antigravity renderer.',\n    domain: '127.0.0.1',\n    strategy: Strategy.UI,\n    browser: true,\n    args: [\n        { name: 'key', positional: true, required: true, help: 'Storage key name' },\n        { name: 'storage', required: false, default: 'local', help: '\"local\" or \"session\"' },\n        { name: 'max-bytes', type: 'int', required: false, default: 4000, help: 'Truncate value to this many chars' },\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        const s = String(kwargs?.storage || 'local').trim().toLowerCase();\n        const store = s === 'session' ? 'sessionStorage' : 'localStorage';\n        const raw = unwrapEvaluateResult(await page.evaluate(`${store}.getItem(${JSON.stringify(key)})`));\n        if (raw === null) throw new CommandExecutionError(`Key not found in ${store}: ${key}`, '');\n        const max = Number.isInteger(kwargs['max-bytes']) && kwargs['max-bytes'] > 0 ? kwargs['max-bytes'] : 4000;\n        let parsed = raw, kind = 'string';\n        try { parsed = JSON.parse(raw); kind = Array.isArray(parsed) ? 'array' : typeof parsed; } 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    },\n});","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/antigravity/storage.js#L111-L147","documentation":"storage-get requires a non-empty positional --key argument naming the storage entry to read. The command trims the value and throws ArgumentError when it is empty or whitespace. Unlike the CLI's declared 'required: true', the func defensively re-validates because empty strings can slip through argument parsing.","triggerScenarios":"Calling `opencli antigravity storage-get` with no positional key, `--key ''`, `--key '   '`, or invoking the underlying func programmatically with kwargs lacking a key field.","commonSituations":"Shell variables that expand to empty ($KEY unset), copy/paste losing the key token, or wrapping scripts that drop positional args when forwarding options.","solutions":["Pass the key as a positional argument: `opencli antigravity storage-get my.key`.","Quote keys containing spaces or dots in your shell.","Verify the variable holding the key is non-empty before invoking.","Use storage-keys first to confirm the exact key name."],"exampleFix":"// before\nopencli antigravity storage-get --key \"$KEY\"   # KEY empty\n// after\n: \"${KEY:?KEY must be set}\"\nopencli antigravity storage-get \"$KEY\"","handlingStrategy":"validation","validationCode":"const key = process.argv[2];\nif (typeof key !== 'string' || !key.trim()) throw new Error('storage-get requires a non-empty key, e.g. opencli antigravity storage-get my.key');","typeGuard":"function hasKey(args) {\n  return typeof args?.key === 'string' && args.key.trim().length > 0;\n}","tryCatchPattern":"try {\n  execSync(`opencli antigravity storage-get ${JSON.stringify(key)}`);\n} catch (e) {\n  if (/key is required/.test(e.message)) {\n    console.error('Pass the key positionally: storage-get <key>');\n  } else throw e;\n}","preventionTips":["Always pass the key as the first positional argument.","Guard shell variables with : \"${KEY:?key required}\".","Quote keys containing spaces or dots.","Verify non-empty after trim, not just truthiness of the raw variable."],"tags":["argument-validation","missing-argument","cli","antigravity"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}