{"record":{"id":"6c4eb73146012f5c","repo":"puppetlabs/puppet","slug":"illegal-format-actual-specified-for-value-of-6c4eb7","errorCode":null,"errorMessage":"Illegal format '#{actual}' specified for value of Undef type - expected one of the characters 'nudxXobBeEfgGaAvVsp'","messagePattern":"Illegal format '#(.+?)' specified for value of Undef type - expected one of the characters 'nudxXobBeEfgGaAvVsp'","errorType":"validation","errorClass":"Puppet::Pops::Types::StringConverter::FormatError","httpStatus":null,"severity":"error","filePath":"lib/puppet/pops/types/string_converter.rb","lineNumber":661,"sourceCode":"  def string_PUndefType(val_type, val, format_map, _)\n    f = get_format(val_type, format_map)\n    apply_string_flags(f, case f.format\n                          when :n\n                            f.alt? ? 'null' : 'nil'\n                          when :u\n                            f.alt? ? 'undefined' : 'undef'\n                          when :d, :x, :X, :o, :b, :B, :e, :E, :f, :g, :G, :a, :A\n                            'NaN'\n                          when :v\n                            'n/a'\n                          when :V\n                            'N/A'\n                          when :s\n                            f.alt? ? '\"\"' : ''\n                          when :p\n                            f.alt? ? '\"undef\"' : 'undef'\n                          else\n                            raise FormatError.new('Undef', f.format,\n                                                  'nudxXobBeEfgGaAvVsp')\n                          end)\n  end\n\n  # @api private\n  def string_PBooleanType(val_type, val, format_map, indentation)\n    f = get_format(val_type, format_map)\n    case f.format\n    when :t\n      # 'true'/'false' or 't'/'f' if in alt mode\n      str_bool = val.to_s\n      apply_string_flags(f, f.alt? ? str_bool[0] : str_bool)\n\n    when :T\n      # 'True'/'False' or 'T'/'F' if in alt mode\n      str_bool = val.to_s.capitalize\n      apply_string_flags(f, f.alt? ? str_bool[0] : str_bool)\n","sourceCodeStart":643,"sourceCodeEnd":679,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/pops/types/string_converter.rb#L643-L679","documentation":"StringConverter raises this FormatError when formatting an Undef value (nil in Puppet, `undef` in DSL) with a format letter outside the wide set 'nudxXobBeEfgGaAvVsp'. Undef is special-cased to render as 'nil'/'null' (n), 'NaN' for numeric letters (dxXobBeEfgGaA), 'n/a'/'N/A' (v/V), ''/'\"\"' (s) and 'undef'/'\"undef\"' (p); everything else hits the else at string_converter.rb:661. This is the most permissive member of the format family because undef can legitimately stand in for any scalar.","triggerScenarios":"`String(undef, '%t')`, `String(undef, '%c')`, `String(undef, '%h')` — any letter not in nudxXobBeEfgGaAvVsp; commonly a format like '%q' (legal for Object but not Undef) applied to an optional variable that is undef.","commonSituations":"Formatting optional data from Hiera where a lookup returns undef and the code applies a fixed format meant for present values; '%v' works for undef but '%t' or '%q' does not, surprising developers migrating between type-specific formats.","solutions":["Use '%s' (empty string / quoted with #) or '%n' ('nil') for undef","Default the variable first: String($x | default { 'n/a' }, '%s') or `$x = pick($x, 'n/a')`","Validate format letters against the allowed set when formats are dynamic"],"exampleFix":"# before\n$str = String($maybe_undef, '%t')\n# after\n$str = String($maybe_undef, '%s')","handlingStrategy":"validation","validationCode":"fmt = '%t'\nletter = fmt[/\\A%[#\\-+ 0\\d.]*([a-zA-Z])\\z/, 1]\nraise ArgumentError, \"#{fmt} invalid for undef\" unless %w[n u d x X o b B e E f g G a A v V s p].include?(letter)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use pick() or an if/else to substitute a placeholder before formatting optional values","Prefer %s or %n when a variable may be undef","Test formatting helpers against undef and default inputs, not just populated values"],"tags":["puppet","pops","string-conversion","format-error","undef"],"backgroundTag":"invalid-format-specifier","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}