{"record":{"id":"1cead7e2a156983e","repo":"google-gemini/gemini-cli","slug":"failed-to-parse-arguments","errorCode":null,"errorMessage":"Failed to parse arguments","messagePattern":"Failed to parse arguments","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/config/config.ts","lineNumber":512,"sourceCode":"        .option('accept-raw-output-risk', {\n          type: 'boolean',\n          description: 'Suppress the security warning when using --raw-output.',\n        }),\n    )\n    .version(await getVersion()) // This will enable the --version flag based on package.json\n    .alias('v', 'version')\n    .help()\n    .alias('h', 'help')\n    .strict()\n    .demandCommand(0, 0) // Allow base command to run with no subcommands\n    .exitProcess(false);\n\n  yargsInstance.wrap(yargsInstance.terminalWidth());\n  let result;\n  try {\n    const parsed = await yargsInstance.parse();\n    if (!isRecord(parsed)) {\n      throw new Error('Failed to parse arguments');\n    }\n    result = parsed;\n    if (result['skip-trust']) {\n      process.env['GEMINI_CLI_TRUST_WORKSPACE'] = 'true';\n    }\n  } catch (e) {\n    const msg = getErrorMessage(e);\n    debugLogger.error(msg);\n    yargsInstance.showHelp();\n    await runExitCleanup();\n    process.exit(1);\n  }\n\n  // Handle help and version flags manually since we disabled exitProcess\n  if (result['help'] || result['version']) {\n    await runExitCleanup();\n    process.exit(0);\n  }","sourceCodeStart":494,"sourceCodeEnd":530,"githubUrl":"https://github.com/google-gemini/gemini-cli/blob/5024443c7217464a66e98f80d73172a26440bd8f/packages/cli/src/config/config.ts#L494-L530","documentation":"Thrown defensively after `yargsInstance.parse()` when the parsed result fails the `isRecord` type guard (i.e. yargs returned something that is not a plain object). This should not happen under normal yargs behavior — yargs always returns an object — so it guards against a malformed parser, a custom coerce that returns a non-object, or a corrupted yargs plugin chain.","triggerScenarios":"A `coerce` function on some option returning a non-object value that propagates; a yargs version regression where `parse()` returns undefined; corrupted argv state from an upstream middleware.","commonSituations":"After upgrading yargs to a version with a breaking change; after registering a custom coerce that throws silently; in test harnesses that mock yargs incorrectly; extremely unlikely in normal use.","solutions":["Re-run the command with `DEBUG=1` to capture the upstream yargs error logged just before exit.","Check for custom yargs plugins or coerce functions that may return non-object values.","Pin or upgrade the `yargs` dependency to a known-good version."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"import { isRecord } from '<core utils>';\nfunction isParsedArgs(v: unknown): v is Record<string, unknown> {\n  return isRecord(v);\n}","tryCatchPattern":"try {\n  const parsed = await yargsInstance.parse();\n  if (!isRecord(parsed)) throw new Error('Failed to parse arguments');\n  // ...\n} catch (e) {\n  debugLogger.error(getErrorMessage(e));\n  yargsInstance.showHelp();\n  await runExitCleanup();\n  process.exit(1);\n}","preventionTips":["Pin `yargs` to a tested version range.","Audit any custom `coerce` functions to ensure they return primitives or plain objects.","Run smoke tests after upgrading yargs."],"tags":["cli","yargs","argument","defensive"],"backgroundTag":null,"analyzedSha":"5024443c7217464a66e98f80d73172a26440bd8f","analyzedAt":"2026-08-12T06:01:53.711Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}