puppetlabs/puppet · error · ArgumentError
Illegal radix: %{radix}, expected 2, 8, 10, 16, or default
Error message
Illegal radix: %{radix}, expected 2, 8, 10, 16, or default What it means
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.
Source
Thrown at lib/puppet/pops/types/types.rb:1191
TypeAsserter.assert_instance_of('Integer.new', loader.load(:type, 'namedargs'), args_hash)
end
def on_error(from, radix = :default, abs = nil)
assert_radix(radix) unless radix == :default
if from.is_a?(String)
_("The string '%{str}' cannot be converted to Integer") % { str: from }
else
t = TypeCalculator.singleton.infer(from).generalize
_("Value of type %{type} cannot be converted to Integer") % { type: t }
end
end
def assert_radix(radix)
case radix
when 2, 8, 10, 16
# do nothing
else
raise ArgumentError, _("Illegal radix: %{radix}, expected 2, 8, 10, 16, or default") % { radix: radix }
end
radix
end
end
end
DEFAULT = PIntegerType.new(-Float::INFINITY)
end
# @api public
#
class PFloatType < PNumericType
def self.register_ptype(loader, ir)
create_ptype(loader, ir, 'NumericType')
end
def generalize
DEFAULTView on GitHub (pinned to e227c27540)
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.
Example fix
# before (Puppet DSL)
Integer.new('777', 9) # ArgumentError: Illegal radix: 9, expected 2, 8, 10, 16, or default
# after
unless $radix == undef or $radix in [2, 8, 10, 16] {
fail("radix must be 2, 8, 10, or 16, got '${radix}'")
}
Integer.new('777', $radix) Defensive patterns
Strategy: validation
Validate before calling
VALID_RADIXES = [2, 8, 10, 16].freeze
radix = radix.to_i if radix.is_a?(String) # '16' -> 16
fail "bad radix #{radix}" unless radix.nil? || VALID_RADIXES.include?(radix) Type guard
def valid_radix?(r) r.nil? || r == :default || [2, 8, 10, 16].include?(r) end
Try / catch
begin
Integer.new(value, radix)
rescue ArgumentError => e
raise unless e.message.include?('Illegal radix')
Integer.new(value) # fall back to auto-detection
end Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Illegal format '#{actual}' specified for value of Integer ty
- Only Runtime type 'ruby' is supported, got #{type.runtime}
- #{my_caller.class}(): wrong argument type (#{obj.class}; is
- Init cannot be parameterized with an undefined type and addi
- Creation of new instance of type '%{type_name}' is not suppo
AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21).
Data as JSON: /api/errors/c00e612fef2e4aa0.
Report an issue: GitHub.