{"record":{"id":"5c97e80a1896edcb","repo":"puppetlabs/puppet","slug":"error-parsing-arguments","errorCode":null,"errorMessage":"Error parsing arguments","messagePattern":"Error parsing arguments","errorType":"validation","errorClass":"Puppet::Util::CommandLine::PuppetOptionError","httpStatus":null,"severity":"error","filePath":"lib/puppet/util/command_line/puppet_option_parser.rb","lineNumber":78,"sourceCode":"          case type\n          when :REQUIRED\n            options[:type] = :string\n          when :NONE\n            options[:type] = :flag\n          else\n            raise PuppetOptionError, _(\"Unsupported type: '%{type}'\") % { type: type }\n          end\n\n          @parser.opt long.sub(\"^--\", \"\").intern, desc, options\n        end\n\n        def parse(*args)\n          args = args[0] if args.size == 1 and args[0].is_a?(Array)\n          args_copy = args.dup\n          begin\n            @parser.parse args_copy\n          rescue Puppet::Util::CommandLine::Trollop::CommandlineError => err\n            raise PuppetOptionError.new(_(\"Error parsing arguments\"), err)\n          end\n        end\n\n        def pass_only_last_value_on_to(block)\n          ->(values) { block.call(values.is_a?(Array) ? values.last : values) }\n        end\n        private :pass_only_last_value_on_to\n      end\n    end\n  end\nend\n","sourceCodeStart":60,"sourceCodeEnd":90,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/util/command_line/puppet_option_parser.rb#L60-L90","documentation":"Raised as Puppet::Util::CommandLine::PuppetOptionError by PuppetOptionParser#parse (lib/puppet/util/command_line/puppet_option_parser.rb) when the vendored Trollop parser rejects the argument list. The real reason (unknown option, option missing its value, bad value for a typed option) lives on the wrapped Puppet::Util::CommandLine::Trollop::CommandlineError, passed as the second constructor argument, so it appears as the exception's cause. This is puppet's single wrapper for every CLI argument-parsing failure.","triggerScenarios":"Calling PuppetOptionParser#parse (directly or via any puppet application/face startup) with an unregistered option like --nope; supplying an option that requires a value with no following word (--server with nothing after it); a malformed --key=value pair. Trollop raises CommandlineError and it is immediately re-wrapped here.","commonSituations":"A typo'd long flag on a puppet subcommand; an option removed in a puppet upgrade still passed by a wrapper script; shell scripts forwarding unquoted user input into a puppet command line; gems embedding puppet's CLI parser with arbitrary ARGV.","solutions":["Inspect the wrapped cause (e.cause.message, also logged as the child error) for the exact Trollop reason before changing anything","Run the subcommand with --help and diff the accepted options against your command line","Fix or remove the offending argument; quote arguments containing spaces","If driving the parser programmatically for pre-dispatch parsing (where app-specific options are not yet registered), set ignore_invalid_options = true on the parser"],"exampleFix":"# before\nparser.parse(['--sever', 'puppet.example.com']) # typo'd flag -> PuppetOptionError\n\n# after\nbegin\n  parser.parse(['--server', 'puppet.example.com'])\nrescue Puppet::Util::CommandLine::PuppetOptionError => e\n  warn \"argument error: #{e.cause.message}\"\n  exit 1\nend","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"begin\n  options = parser.parse(args)\nrescue Puppet::Util::CommandLine::PuppetOptionError => e\n  # real reason is on the wrapped Trollop error\n  warn \"usage error: #{e.cause.message}\"\n  exit 64 # EX_USAGE\nend","preventionTips":["Never forward untrusted user input verbatim as puppet CLI arguments; whitelist the flags your wrapper accepts","Quote all arguments when shelling out so spaces cannot split into bogus options","Log e.cause.message, not just the generic wrapper text, so the actual Trollop reason is visible"],"tags":["cli","argument-parsing","trollop","puppet"],"backgroundTag":"invalid-command-line-arguments","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}