{"record":{"id":"a813bd0ba3c55d7f","repo":"Hmbown/CodeWhale","slug":"unknown-or-empty-option-use-help","errorCode":null,"errorMessage":"Unknown or empty option. Use --help.","messagePattern":"Unknown or empty option\\. Use --help\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"pet/scripts/pet.mjs","lineNumber":20,"sourceCode":"/** Read-only adapter: existing Whalesong ingestion is the only event parser. */\nimport { readFile, stat, open } from 'node:fs/promises';\nimport { watch } from 'node:fs';\nimport { basename, dirname } from 'node:path';\nimport { importTrace } from '../dist/core/ingest.js';\nimport { compilePetTelemetry, encodePetJSONL, encodePetTSV } from '../dist/core/pet-telemetry.js';\nimport { petDemoEvents } from '../dist/core/pet-demo.js';\nimport { followRuntime } from './lib/pet-runtime.mjs';\nimport { createPetRecorder } from './lib/pet-recorder.mjs';\n\nconst args = process.argv.slice(2);\nconst option = name => args.find(a => a.startsWith(`--${name}=`))?.slice(name.length + 3);\nif (args.includes('--help')) {\n  console.log('node scripts/pet.mjs --input=trace.jsonl --output=pet.jsonl [--trace=ID] [--format=jsonl|tsv] [--watch]\\nnode scripts/pet.mjs --runtime=http://127.0.0.1:7878 --thread=ID --output=pet.jsonl [--segment-buckets=216000] [--resume]\\nUse --demo instead of --input for synthetic telemetry. Output must not already exist unless --resume is used for live recording. A resumed recorder preserves the previous segment and starts unknown at the same path.\\nLive recording rotates at 216000 buckets or 64 MiB into OUTPUT.segment-NNNNNN.jsonl and continues at the same live path. All archives are retained.\\nRuntime reads only the existing local event journal. Optional authentication comes from CODEWHALE_RUNTIME_TOKEN; never put a token in the URL. No agent or provider is started.');\n  process.exit(0);\n}\nlet output, recorder, monitor, timer, runtime;\ntry {\n  for (const a of args) if (!['--demo', '--watch', '--resume'].includes(a) && !/^--(input|output|trace|format|runtime|thread|segment-buckets)=.+/.test(a)) throw new Error('Unknown or empty option. Use --help.');\n  const input = option('input'), runtimeURL = option('runtime'), path = option('output'), format = option('format') ?? 'jsonl', live = args.includes('--watch') || !!runtimeURL;\n  if (!path || [!!input, args.includes('--demo'), !!runtimeURL].filter(Boolean).length !== 1\n    || !['jsonl', 'tsv'].includes(format) || live && format !== 'jsonl' || args.includes('--watch') && !input\n    || !!runtimeURL !== !!option('thread') || option('trace') && !input || option('segment-buckets') && !live || args.includes('--resume') && !live)\n    throw new Error('Choose one input source, an unused --output path (or --resume), and JSONL for live recording. Runtime requires --thread.');\n  const load = async () => {\n    if (!input) return { events: petDemoEvents(), duration: 80_000 };\n    if ((await stat(input)).size > 64 * 1024 * 1024) throw new Error('Input exceeds 64 MiB.');\n    const traces = importTrace(await readFile(input, 'utf8'), input, { privacy: 'metadata' });\n    const trace = option('trace') ? traces.find(t => t.id === option('trace')) : traces.length === 1 ? traces[0] : undefined;\n    if (!trace) throw new Error('Select an existing --trace ID when input contains multiple traces.');\n    return trace;\n  };\n  let trace = runtimeURL ? undefined : await load(), buckets = compilePetTelemetry(trace?.events ?? [], trace?.duration ?? 0);\n  if (live) recorder = await createPetRecorder(path, { resume: args.includes('--resume'), maxBuckets: option('segment-buckets') === undefined ? 216_000 : Number(option('segment-buckets')), report: text => console.error(text) });\n  else output = await open(path, 'wx', 0o600);\n  if (runtimeURL) runtime = await followRuntime({ baseUrl: runtimeURL, threadId: option('thread'),\n    token: process.env.CODEWHALE_RUNTIME_TOKEN, report: text => console.error(text) });","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/pet/scripts/pet.mjs#L2-L38","documentation":"scripts/pet.mjs validates every CLI argument: only bare flags --demo, --watch, --resume are allowed, and every other option must be --name=value with a non-empty value drawn from the known set (input, output, trace, format, runtime, thread, segment-buckets). Anything else — an unknown option, a bare --name without =value, or an empty value — throws this error and the script exits.","triggerScenarios":"Passing an unrecognized flag (e.g. --verbose), passing an option without a value (--input with nothing after it), a misspelled option (--outpt=...), or a positional argument that doesn't start with --.","commonSituations":"Typos in long option names; copying examples that use --input value (space-separated) instead of --input=value; shell scripts passing through extra flags; old documentation referencing renamed options.","solutions":["Run node scripts/pet.mjs --help and use only the documented options.","Rewrite space-separated options to = form: --input trace.jsonl becomes --input=trace.jsonl.","Fix typos so the option name matches the regex ^--(input|output|trace|format|runtime|thread|segment-buckets)=.+","Remove stray positional arguments or unsupported flags from the invoking script."],"exampleFix":"// before\nnode scripts/pet.mjs --input trace.jsonl --verbose\n// after\nnode scripts/pet.mjs --input=trace.jsonl --output=pet.jsonl","handlingStrategy":"validation","validationCode":"const KNOWN_FLAGS = ['--demo', '--watch', '--resume'];\nconst KNOWN_OPTS = /^(--)(input|output|trace|format|runtime|thread|segment-buckets)=.+$/;\nargs.forEach(a => { if (!KNOWN_FLAGS.includes(a) && !KNOWN_OPTS.test(a)) console.error(`bad arg: ${a}`); });","typeGuard":null,"tryCatchPattern":"try {\n  await main(process.argv.slice(2));\n} catch (err) {\n  if (err.message.startsWith('Unknown or empty option')) {\n    console.error(err.message); process.exit(2);\n  }\n  throw err;\n}","preventionTips":["Run --help before composing unfamiliar invocations.","Always use the --name=value form with a non-empty value.","Copy options from the help text rather than memory to avoid typos.","Shell-quote values containing spaces."],"tags":["cli","argument-parsing","validation"],"backgroundTag":"invalid-cli-argument","analyzedSha":"433685b2024e7bc4c99e1e2e326bcad39b4d9d65","analyzedAt":"2026-09-15T12:24:24.634Z","contentChangedAt":"2026-09-15T12:24:24.634Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}