{"record":{"id":"acd4f7ce31da48a3","repo":"puppetlabs/puppet","slug":"unknown-argument-arg","errorCode":null,"errorMessage":"unknown argument '%{arg}'","messagePattern":"unknown argument '%(.+?)'","errorType":"exception","errorClass":"CommandlineError","httpStatus":null,"severity":"error","filePath":"lib/puppet/util/command_line/trollop.rb","lineNumber":365,"sourceCode":"                end\n              when /^--([^-]\\S*)$/\n                possible_match = @long[::Regexp.last_match(1)] || @long[\"[no-]#{::Regexp.last_match(1)}\"]\n                if !possible_match\n                  partial_match = @long[::Regexp.last_match(1).tr('-', '_')] || @long[::Regexp.last_match(1).tr('_', '-')] || @long[\"[no-]#{::Regexp.last_match(1).tr('-', '_')}\"] || @long[\"[no-]#{::Regexp.last_match(1).tr('_', '-')}\"]\n                  if partial_match\n                    Puppet.deprecation_warning _(\"Partial argument match detected: correct argument is %{partial_match}, got %{arg}. Partial argument matching is deprecated and will be removed in a future release.\") % { arg: arg, partial_match: partial_match }\n                  end\n                  partial_match\n                else\n                  possible_match\n                end\n              else\n                raise CommandlineError, _(\"invalid argument syntax: '%{arg}'\") % { arg: arg }\n              end\n\n        unless sym\n          next 0 if ignore_invalid_options\n          raise CommandlineError, _(\"unknown argument '%{arg}'\") % { arg: arg } unless sym\n        end\n\n        if given_args.include?(sym) && !@specs[sym][:multi]\n          raise CommandlineError, _(\"option '%{arg}' specified multiple times\") % { arg: arg }\n        end\n\n        given_args[sym] ||= {}\n\n        given_args[sym][:arg] = arg\n        given_args[sym][:params] ||= []\n\n        # The block returns the number of parameters taken.\n        num_params_taken = 0\n\n        unless params.nil?\n          if SINGLE_ARG_TYPES.include?(@specs[sym][:type])\n            given_args[sym][:params] << params[0, 1]  # take the first parameter\n            num_params_taken = 1","sourceCodeStart":347,"sourceCodeEnd":383,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/util/command_line/trollop.rb#L347-L383","documentation":"When a token has valid option syntax but resolves to no registered long or short name (including the '[no-]' registry), sym is nil; unless the parser was put into ignore_invalid_options mode (PuppetOptionParser uses that for its first global pass because the target application is not yet known), parse raises CommandlineError at trollop.rb:365. A legacy fallback once matched underscore/dash variants with only a deprecation warning, but that partial matching is deprecated, so misspelled long options now fail. Inside the puppet executable the raw error is wrapped as PuppetOptionError 'Error parsing arguments' by puppet_option_parser.rb:77-78.","triggerScenarios":"`puppet agent --sever=puppet.example.com` (typo in --server); `--node_name` instead of `--node-name`; an option valid for one subcommand passed to another; a flag that was removed or renamed in a newer Puppet version.","commonSituations":"Typos in long flags; copying flags between puppet subcommands that do not share them; version drift after upgrades where an option no longer exists; long-standing scripts relying on underscore spelling via the deprecated partial matching.","solutions":["Check spelling against `puppet <subcommand> --help`","Use dashes, not underscores, in long option names","Consult the Puppet release notes if the flag worked on an older version — it may have been renamed or removed","As the developer, register the option with opt before parse, or enable ignore_invalid_options in your wrapper if unknown options should pass through"],"exampleFix":"# before\n$ puppet agent --sever=puppet.example.com --test\nError: Could not parse application options: invalid option: --sever\n\n# after\n$ puppet agent --server=puppet.example.com --test","handlingStrategy":"try-catch","validationCode":"# Validate argv against the registered long/short names before parse (partial-matching is deprecated)\nparser = Trollop::Parser.new\n# ... declare opts ...\nlong  = parser.instance_variable_get(:@long)\nshort = parser.instance_variable_get(:@short)\nargv.each do |t|\n  if (m = t.match(/^--(?:no-)?([^=]+)/))\n    abort \"Unknown option #{t}\" unless long.key?(m[1])\n  elsif (m = t.match(/^-(.)$/))\n    abort \"Unknown option #{t}\" unless short.key?(m[1])\n  end\nend","typeGuard":null,"tryCatchPattern":"begin\n  opts = parser.parse(argv)\nrescue Puppet::Util::CommandLine::Trollop::CommandlineError => e\n  raise unless e.message.include?(\"unknown argument\")\n  warn \"#{e.message} - run with --help to list valid options\"\n  exit 64\nend\n# Through Puppet's own wrapper, rescue instead:\n# rescue Puppet::Util::CommandLine::PuppetOptionParser::PuppetOptionError","preventionTips":["Use dashes in long option names - underscore partial matching is deprecated and will stop working","Verify flags with `puppet <subcommand> --help` before scripting them","After Puppet upgrades, smoke-test wrapper scripts for removed or renamed flags","As a developer, set ignore_invalid_options only for genuine pass-through phases, never the final parse"],"tags":["puppet","trollop","cli","option-parsing","typo"],"backgroundTag":"unknown-cli-option","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}