{"record":{"id":"b52c868b3a79edaf","repo":"puppetlabs/puppet","slug":"invalid-argument-syntax-arg","errorCode":null,"errorMessage":"invalid argument syntax: '%{arg}'","messagePattern":"invalid argument syntax: '%(.+?)'","errorType":"exception","errorClass":"CommandlineError","httpStatus":null,"severity":"error","filePath":"lib/puppet/util/command_line/trollop.rb","lineNumber":360,"sourceCode":"                    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              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","sourceCodeStart":342,"sourceCodeEnd":378,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/util/command_line/trollop.rb#L342-L378","documentation":"During Parser#parse, each_arg yields every option-looking token and the case at trollop.rb:334-361 classifies it: a single-dash single-character short ('-x'), a negated long ('--no-name'), or a plain long whose first character after '--' is not a dash. A token that survives each_arg but fits none of these shapes — typically a long flag with three or more leading dashes — hits the else branch at line 360 and raises CommandlineError. Note that the arg terminator '--' is handled separately (trollop.rb:597) and short bundling like '-vh' is split by each_arg, so neither triggers this error.","triggerScenarios":"`mytool ---debug` (three dashes: each_arg yields '---debug', which matches no branch); any '--' immediately followed by another dash; a long flag assembled programmatically that prefixes '--' to a string already containing dashes.","commonSituations":"Manual typing or tab-completion inserting an extra leading dash; flags copied from documentation, chat, or rich text that mangled the dashes; generated command lines that double up the '--' prefix.","solutions":["Type the flag with exactly two dashes: `--debug`","Inspect the exact token named in the message for stray leading dashes","If you build flags programmatically, strip existing leading dashes before adding the '--' prefix","Run `<command> --help` and copy the exact spelling shown"],"exampleFix":"# before\n$ mytool ---verbose\nError: invalid argument syntax: '---verbose'\n\n# after\n$ mytool --verbose","handlingStrategy":"try-catch","validationCode":"# Reject malformed flag tokens before parsing (mirrors the classifier at trollop.rb:334-361)\nbad = argv.grep(/^--+/).select { |t| t !~ /^--no-([^-]\\S*)$/ && t !~ /^--([^-]\\S*)$/ && t !~ /^-([^-])$/ }\nabort \"Malformed argument(s): #{bad.join(' ')} - use exactly two leading dashes\" unless bad.empty?","typeGuard":null,"tryCatchPattern":"begin\n  opts = Puppet::Util::CommandLine::Trollop::Parser.new { /* opts */ }.parse(argv)\nrescue Puppet::Util::CommandLine::Trollop::CommandlineError => e\n  if e.message.include?('invalid argument syntax')\n    warn \"#{e.message} (check for extra leading dashes)\"\n    exit 64   # EX_USAGE\n  end\n  raise\nend","preventionTips":["Type long flags with exactly two leading dashes","When generating flags programmatically, strip existing dashes before adding '--'","Copy exact spellings from --help output rather than retyping from memory"],"tags":["puppet","trollop","cli","option-parsing","commandlineerror"],"backgroundTag":"malformed-cli-argument","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}