{"record":{"id":"c00e612fef2e4aa0","repo":"puppetlabs/puppet","slug":"illegal-radix-radix-expected-2-8-10-16-or","errorCode":null,"errorMessage":"Illegal radix: %{radix}, expected 2, 8, 10, 16, or default","messagePattern":"Illegal radix: %(.+?), expected 2, 8, 10, 16, or default","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/pops/types/types.rb","lineNumber":1191,"sourceCode":"        TypeAsserter.assert_instance_of('Integer.new', loader.load(:type, 'namedargs'), args_hash)\n      end\n\n      def on_error(from, radix = :default, abs = nil)\n        assert_radix(radix) unless radix == :default\n        if from.is_a?(String)\n          _(\"The string '%{str}' cannot be converted to Integer\") % { str: from }\n        else\n          t = TypeCalculator.singleton.infer(from).generalize\n          _(\"Value of type %{type} cannot be converted to Integer\") % { type: t }\n        end\n      end\n\n      def assert_radix(radix)\n        case radix\n        when 2, 8, 10, 16\n          # do nothing\n        else\n          raise ArgumentError, _(\"Illegal radix: %{radix}, expected 2, 8, 10, 16, or default\") % { radix: radix }\n        end\n        radix\n      end\n    end\n  end\n\n  DEFAULT = PIntegerType.new(-Float::INFINITY)\nend\n\n# @api public\n#\nclass PFloatType < PNumericType\n  def self.register_ptype(loader, ir)\n    create_ptype(loader, ir, 'NumericType')\n  end\n\n  def generalize\n    DEFAULT","sourceCodeStart":1173,"sourceCodeEnd":1209,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/pops/types/types.rb#L1173-L1209","documentation":"The new() function on Puppet's Integer type (Integer.new) converts values to Integer and takes an optional radix for string conversion (from_args calls Integer(from, radix)). assert_radix permits only the bases 2, 8, 10 and 16, or :default (auto-detect); anything else raises ArgumentError naming the bad radix. A radix passed as a String ('16' instead of 16) is rejected too, because only Integer case labels match.","triggerScenarios":"Integer.new('77', 9) in a manifest (9 is not a supported base); Integer.new($s, '16') where the radix arrives as a quoted string; supplying the radix from an unvalidated module parameter or Hiera value.","commonSituations":"A module exposes a base/radix parameter without constraining it; Hiera delivers the value as a quoted string; porting Ruby habits where Integer(str, base) accepts bases 2..36 but Puppet's type system only supports 2/8/10/16.","solutions":["Use 2, 8, 10 or 16, or omit the radix entirely for auto-detection.","Pass the radix as an Integer, not a String: Integer.new($s, Integer($radix)).","Constrain the parameter (e.g. Optional[Enum['2','8','10','16']] plus a cast) and fail early with your own message.","For arbitrary bases, do the conversion in a custom function instead of the type system."],"exampleFix":"# before (Puppet DSL)\nInteger.new('777', 9)   # ArgumentError: Illegal radix: 9, expected 2, 8, 10, 16, or default\n\n# after\nunless $radix == undef or $radix in [2, 8, 10, 16] {\n  fail(\"radix must be 2, 8, 10, or 16, got '${radix}'\")\n}\nInteger.new('777', $radix)","handlingStrategy":"validation","validationCode":"VALID_RADIXES = [2, 8, 10, 16].freeze\nradix = radix.to_i if radix.is_a?(String)  # '16' -> 16\nfail \"bad radix #{radix}\" unless radix.nil? || VALID_RADIXES.include?(radix)","typeGuard":"def valid_radix?(r)\n  r.nil? || r == :default || [2, 8, 10, 16].include?(r)\nend","tryCatchPattern":"begin\n  Integer.new(value, radix)\nrescue ArgumentError => e\n  raise unless e.message.include?('Illegal radix')\n  Integer.new(value)   # fall back to auto-detection\nend","preventionTips":["Whitelist the radix before calling Integer.new; Puppet supports only 2, 8, 10 and 16.","Cast string parameters to Integer before using them as a radix.","Keep exotic-base conversion in custom functions, not the type system."],"tags":["puppet","type-system","integer","radix","base-conversion"],"backgroundTag":"invalid-number-base","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}