{"record":{"id":"80280cbb015a6c88","repo":"puppetlabs/puppet","slug":"option-arg-needs-a-floating-point-number","errorCode":null,"errorMessage":"option '%{arg}' needs a floating-point number","messagePattern":"option '%(.+?)' needs a floating-point number","errorType":"exception","errorClass":"CommandlineError","httpStatus":null,"severity":"error","filePath":"lib/puppet/util/command_line/trollop.rb","lineNumber":665,"sourceCode":"            return remains\n          else\n            remains << args[i]\n            i += 1\n          end\n        end\n      end\n\n      remains\n    end\n\n    def parse_integer_parameter param, arg\n      raise CommandlineError, _(\"option '%{arg}' needs an integer\") % { arg: arg } unless param =~ /^\\d+$/\n\n      param.to_i\n    end\n\n    def parse_float_parameter param, arg\n      raise CommandlineError, _(\"option '%{arg}' needs a floating-point number\") % { arg: arg } unless param =~ FLOAT_RE\n\n      param.to_f\n    end\n\n    def parse_io_parameter param, arg\n      case param\n      when /^(stdin|-)$/i; $stdin\n      else\n        require 'open-uri'\n        begin\n          URI.parse(param).open\n        rescue SystemCallError => e\n          raise CommandlineError, _(\"file or url for option '%{arg}' cannot be opened: %{value0}\") % { arg: arg, value0: e.message }, e.backtrace\n        end\n      end\n    end\n\n    def collect_argument_parameters args, start_at","sourceCodeStart":647,"sourceCodeEnd":683,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/util/command_line/trollop.rb#L647-L683","documentation":"Options typed :float or :floats validate each parameter against FLOAT_RE = /^-?((\\d+(\\.\\d+)?)|(\\.\\d+))([eE][-+]?\\d+)?$/ (trollop.rb:36) inside parse_float_parameter; a mismatch raises CommandlineError \"option '--x' needs a floating-point number\" at line 665. The regex accepts an optional leading minus, digits with an optional fractional part, or a bare fraction like '.5', plus an optional exponent — but not comma decimals, trailing dots without digits ('1.'), incomplete exponents ('1e'), or non-numeric strings.","triggerScenarios":"`--ratio abc`; `--ratio 1,5` (comma decimal separator); `--ratio 1.` (trailing dot, no digits); `--ratio 1e` (incomplete exponent); values with embedded whitespace.","commonSituations":"Locales that use a comma as the decimal separator; whitespace left in generated values; scientific notation with a malformed exponent.","solutions":["Pass a plain decimal such as `--ratio 0.75` or `--ratio -0.75`","Strip whitespace and normalize commas to dots before invoking the command","When generating command lines, validate values against a float regex in the caller first"],"exampleFix":"# before\n$ mytool --ratio 1,5\nError: option '--ratio' needs a floating-point number\n\n# after\n$ mytool --ratio 1.5","handlingStrategy":"validation","validationCode":"# Mirror FLOAT_RE = /^-?((\\d+(\\.\\d+)?)|(\\.\\d+))([eE][-+]?\\d+)?$/ before invoking\nFLOAT_RE = /^-?((\\d+(\\.\\d+)?)|(\\.\\d+))([eE][-+]?\\d+)?$/\nvalue = argv[i + 1]\nabort \"#{value.inspect} is not a valid float (watch commas and trailing dots)\" unless value =~ FLOAT_RE","typeGuard":"def trollop_float?(s)\n  s.is_a?(String) && s =~ /^-?((\\d+(\\.\\d+)?)|(\\.\\d+))([eE][-+]?\\d+)?$/\nend","tryCatchPattern":"begin\n  opts = parser.parse(argv)\nrescue Puppet::Util::CommandLine::Trollop::CommandlineError => e\n  raise unless e.message.include?('needs a floating-point number')\n  name = e.message[/option '(.+)' needs/, 1]\n  abort \"#{name} needs a decimal like 0.75, -0.75, .5, or 1e3 (no commas)\"\nend","preventionTips":["Normalize decimal commas to dots and strip whitespace before passing values on to CLIs","Never pass '1.' or '1e' - require at least one digit after the dot and in the exponent","Format floats in the caller with sprintf('%.<n>f', v) rather than to_s when locale matters"],"tags":["puppet","trollop","cli","option-parsing","numeric-parsing"],"backgroundTag":"invalid-numeric-option-value","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}