puppetlabs/puppet · error · Puppet::Pops::Types::StringConverter::FormatError
Illegal format '#{actual}' specified for value of Type type
Error message
Illegal format '#{actual}' specified for value of Type type - expected one of the characters 'sp' What it means
StringConverter raises this FormatError when formatting a Type value (PTypeType — the value itself is a type like Integer[0,10]) with a conversion letter other than 's' (type's string form, quoted with alt flag) or 'p' (same via Kernel.format). The else at string_converter.rb:1113 raises FormatError('Type', f.format, 'sp'). Types stringify to their notation (e.g. 'Integer[0, 10]') and support no other conversions.
Source
Thrown at lib/puppet/pops/types/string_converter.rb:1113
end
end
# @api private
def string_PStructType(val_type, val, format_map, indentation)
string_PHashType(val_type, val, format_map, indentation)
end
# @api private
def string_PTypeType(val_type, val, format_map, _)
f = get_format(val_type, format_map)
case f.format
when :s
str_val = f.alt? ? "\"#{val}\"" : val.to_s
Kernel.format(f.orig_fmt, str_val)
when :p
Kernel.format(f.orig_fmt.tr('p', 's'), val.to_s)
else
raise FormatError.new('Type', f.format, 'sp')
end
end
# @api private
def string_PURIType(val_type, val, format_map, indentation)
f = get_format(val_type, format_map)
case f.format
when :p
fmt = TypeFormatter.singleton
indentation = indentation.indenting(f.alt? || indentation.is_indenting?)
fmt = fmt.indented(indentation.level, 2) if indentation.is_indenting?
fmt.string(val)
when :s
str_val = val.to_s
Kernel.format(f.orig_fmt, f.alt? ? puppet_quote(str_val) : str_val)
else
raise FormatError.new('URI', f.format, 'sp')
endView on GitHub (pinned to e227c27540)
Solutions
- Use '%s' or '%p' when stringifying a Type value
- If you need the inner type's features, extract and format its parameters instead of the type itself
- Whitelist dynamic format letters against %w[s p]
Example fix
# before $str = String($type, '%d') # after $str = String($type, '%s')
Defensive patterns
Strategy: validation
Validate before calling
fmt = '%d'
letter = fmt[/\A%[#\-+ 0\d.]*([a-zA-Z])\z/, 1]
raise ArgumentError, "#{fmt} invalid for Type values" unless %w[s p].include?(letter) Prevention
- Only %s and %p render Type values
- When generating messages about types, interpolate with String($type, '%p')
- Keep type objects out of data destined for numeric/other formatting
When it happens
Trigger: `String(Integer, '%d')`, `String($type_var, '%q')` — any letter except s/p applied to a value whose inferred type is Type[...]; common when echoing parameter types in error messages or generated docs.
Common situations: Building validation error text that interpolates the expected type with a generic formatter; debug output walking heterogeneous data that includes type objects.
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 Default ty
- Illegal format '#{actual}' specified for value of Undef type
- Illegal format '#{actual}' specified for value of Boolean ty
AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21).
Data as JSON: /api/errors/4cc5cf18572a5357.
Report an issue: GitHub.