{"id":"78b79d151908a4c4","repo":"tj/commander.js","slug":"passthroughoptions-cannot-be-used-for-this-nam","errorCode":null,"errorMessage":"passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)","messagePattern":"passThroughOptions cannot be used for '(.+?)' without turning on enablePositionalOptions for parent command\\(s\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/command.js","lineNumber":882,"sourceCode":"   * @return {Command} `this` command for chaining\n   */\n  passThroughOptions(passThrough = true) {\n    this._passThroughOptions = !!passThrough;\n    this._checkForBrokenPassThrough();\n    return this;\n  }\n\n  /**\n   * @private\n   */\n\n  _checkForBrokenPassThrough() {\n    if (\n      this.parent &&\n      this._passThroughOptions &&\n      !this.parent._enablePositionalOptions\n    ) {\n      throw new Error(\n        `passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`,\n      );\n    }\n  }\n\n  /**\n   * Whether to store option values as properties on command object,\n   * or store separately (specify false). In both cases the option values can be accessed using .opts().\n   *\n   * @param {boolean} [storeAsProperties=true]\n   * @return {Command} `this` command for chaining\n   */\n\n  storeOptionsAsProperties(storeAsProperties = true) {\n    if (this.options.length) {\n      throw new Error('call .storeOptionsAsProperties() before adding options');\n    }\n    if (Object.keys(this._optionValues).length) {","sourceCodeStart":864,"sourceCodeEnd":900,"githubUrl":"https://github.com/tj/commander.js/blob/ba6d13ddb4243e5913367734f8c159089ffe7834/lib/command.js#L864-L900","documentation":"Thrown by Command._checkForBrokenPassThrough() at lib/command.js:876-886 when a subcommand has passThroughOptions enabled but its parent chain does not have enablePositionalOptions on. passThrough means unknown options are forwarded as positional tokens to the subcommand; that only works if the parent is in positional mode, otherwise the tokens would be consumed/misinterpreted upstream.","triggerScenarios":"`program.command('child').passThroughOptions()` without first calling `program.enablePositionalOptions()`. The check walks this.parent._enablePositionalOptions and throws if falsy. Also triggered retroactively when addCommand registers a child whose passThroughOptions was set before the parent enabled positional.","commonSituations":"Building a 'passthrough' wrapper command that delegates flags to a downstream tool (git-style); enabling passThrough on a subcommand during a refactor without updating the root; ordering bug where .passThroughOptions() is called before .enablePositionalOptions() on the parent.","solutions":["Enable positional options on the parent: `program.enablePositionalOptions();` before registering/calling the child.","Ensure every ancestor in the chain has enablePositionalOptions if the subcommand uses passThrough.","If passThrough was unintended, remove the `.passThroughOptions()` call."],"exampleFix":"// before (throws)\nconst child = new Command('child').passThroughOptions();\nprogram.addCommand(child);\n\n// after\nprogram.enablePositionalOptions();\nprogram.addCommand(child);","handlingStrategy":"validation","validationCode":"function enablePassThrough(program, child) {\n  if (!program._enablePositionalOptions) {\n    throw new Error('Call program.enablePositionalOptions() before passThroughOptions on a child');\n  }\n  child.passThroughOptions();\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always set program.enablePositionalOptions() first if any child uses passThroughOptions.","Configure the root command before adding subcommands.","Add a smoke test that builds the full command tree to surface ordering bugs at startup."],"tags":["commander","positional-options","passthrough","configuration"],"analyzedSha":"ba6d13ddb4243e5913367734f8c159089ffe7834","analyzedAt":"2026-08-03T20:26:04.326Z","schemaVersion":2}