{"id":"7dd7fa19a37ee764","repo":"tj/commander.js","slug":"unexpected-parse-option-from-parseoptions-fr","errorCode":null,"errorMessage":"unexpected parse option { from: '${parseOptions.from}' }","messagePattern":"unexpected parse option (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/command.js","lineNumber":1045,"sourceCode":"        userArgs = argv.slice(2);\n        break;\n      case 'electron':\n        // @ts-ignore: because defaultApp is an unknown property\n        if (process.defaultApp) {\n          this._scriptPath = argv[1];\n          userArgs = argv.slice(2);\n        } else {\n          userArgs = argv.slice(1);\n        }\n        break;\n      case 'user':\n        userArgs = argv.slice(0);\n        break;\n      case 'eval':\n        userArgs = argv.slice(1);\n        break;\n      default:\n        throw new Error(\n          `unexpected parse option { from: '${parseOptions.from}' }`,\n        );\n    }\n\n    // Find default name for program from arguments.\n    if (!this._name && this._scriptPath)\n      this.nameFromFilename(this._scriptPath);\n    this._name = this._name || 'program';\n\n    return userArgs;\n  }\n\n  /**\n   * Parse `argv`, setting options and invoking commands when defined.\n   *\n   * Use parseAsync instead of parse if any of your action handlers are async.\n   *\n   * Call with no parameters to parse `process.argv`. Detects Electron and special node options like `node --eval`. Easy mode!","sourceCodeStart":1027,"sourceCodeEnd":1063,"githubUrl":"https://github.com/tj/commander.js/blob/ba6d13ddb4243e5913367734f8c159089ffe7834/lib/command.js#L1027-L1063","documentation":"Thrown by Command._prepareUserArgs() at lib/command.js:1044-1048 when parseOptions.from is not one of the supported values ('node', 'electron', 'user', or undefined for auto). The switch has a default branch that rejects anything else, including case-typos like 'User' or invented modes like 'webpack'.","triggerScenarios":"`program.parse(argv, { from: 'browser' })`, `{ from: 'User' }` (wrong case), `{ from: 'node-modules' }`. The internal 'eval' mode exists but is not documented/public.","commonSituations":"Guessing a `from` value not in the docs; copy-paste from another CLI tool with different mode names; version skew where an older/newer Commander supported a different set.","solutions":["Use one of the documented values: 'node' (default), 'electron', or 'user'.","Omit `from` entirely to let Commander auto-detect node/electron/eval.","Check the installed Commander version's docs for the supported set."],"exampleFix":"// before (throws)\nprogram.parse(argv, { from: 'User' });\n\n// after\nprogram.parse(argv, { from: 'user' });","handlingStrategy":"type-guard","validationCode":"const FROM_VALUES = ['node', 'electron', 'user'];\nfunction safeParse(cmd, argv, opts) {\n  if (opts?.from && !FROM_VALUES.includes(opts.from)) {\n    throw new TypeError(`parseOptions.from must be one of ${FROM_VALUES.join(', ')}`);\n  }\n  return cmd.parse(argv, opts);\n}","typeGuard":"type ParseFrom = 'node' | 'electron' | 'user';\nfunction isParseFrom(v: unknown): v is ParseFrom {\n  return v === 'node' || v === 'electron' || v === 'user';\n}","tryCatchPattern":null,"preventionTips":["Restrict `from` to the documented set; omit it for auto-detect when unsure.","Drive the value from a typed const, not a free string.","Pin Commander version to align with the supported `from` set."],"tags":["commander","parse","parse-options","api-misuse"],"analyzedSha":"ba6d13ddb4243e5913367734f8c159089ffe7834","analyzedAt":"2026-08-03T20:26:04.326Z","schemaVersion":2}