puppetlabs/puppet · error · Puppet::Pops::Types::StringConverter::FormatError
Illegal format '#{actual}' specified for value of Default ty
Error message
Illegal format '#{actual}' specified for value of Default type - expected one of the characters 'dDsp' What it means
StringConverter raises this FormatError when formatting the special `default` value (PDefaultType) with a format character outside 'dDsp': 'd'/'s' render 'default', 'D' renders 'Default', 'p' quotes per Puppet notation, with alt-flag (#) variants adding quotes. Any other letter hits the else at string_converter.rb:638 and raises FormatError('Default', f.format, 'dDsp').
Source
Thrown at lib/puppet/pops/types/string_converter.rb:638
# Basically string_PAnyType converts the value to a String and then formats it according
# to the resulting type
#
# @api private
def string_PAnyType(val_type, val, format_map, _)
f = get_format(val_type, format_map)
Kernel.format(f.orig_fmt, val)
end
def string_PDefaultType(val_type, val, format_map, _)
f = get_format(val_type, format_map)
apply_string_flags(f, case f.format
when :d, :s, :p
f.alt? ? '"default"' : 'default'
when :D
f.alt? ? '"Default"' : 'Default'
else
raise FormatError.new('Default', f.format, 'dDsp')
end)
end
# @api private
def string_PUndefType(val_type, val, format_map, _)
f = get_format(val_type, format_map)
apply_string_flags(f, case f.format
when :n
f.alt? ? 'null' : 'nil'
when :u
f.alt? ? 'undefined' : 'undef'
when :d, :x, :X, :o, :b, :B, :e, :E, :f, :g, :G, :a, :A
'NaN'
when :v
'n/a'
when :V
'N/A'
when :sView on GitHub (pinned to e227c27540)
Solutions
- Use '%d', '%D', '%s' or '%p' when stringifying `default`
- Branch before formatting: `if $v == default { ... } else { String($v, $fmt) }`
- Check the value against the allowed letters when the format is user/data supplied
Example fix
# before $str = String(default, '%v') # after $str = String(default, '%s')
Defensive patterns
Strategy: validation
Validate before calling
fmt = '%v'
letter = fmt[/\A%[#\-+ 0\d.]*([a-zA-Z])\z/, 1]
raise ArgumentError, "#{fmt} invalid for the default value" unless %w[d D s p].include?(letter) Prevention
- Handle `default` explicitly (case/if) before applying generic formatting to option values
- Remember %v is legal for Undef but illegal for Default
- Whitelist format letters per type when formats are data-driven
When it happens
Trigger: `String(default, '%v')`, `String(default, '%t')` or any conversion letter not in d/D/s/p applied to the Puppet `default` value; a format map applied uniformly to a data structure that happens to contain `default` entries.
Common situations: Iterating heterogeneous option hashes where one entry is `default` and applying a single format string to all values; porting sprintf-style templates that use %v (which is legal for Undef but not for Default).
Related errors
- Illegal format '#{actual}' specified for value of Object typ
- Illegal format '#{actual}' specified for value of Runtime ty
- Illegal format '#{actual}' specified for value of Undef type
- Illegal format '#{actual}' specified for value of Boolean ty
- Illegal format '#{actual}' specified for value of Integer ty
AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21).
Data as JSON: /api/errors/2edda4ed7fe65dce.
Report an issue: GitHub.