{"record":{"id":"b27168adcf31d7fb","repo":"puppetlabs/puppet","slug":"illegal-format-actual-specified-for-value-of-b27168","errorCode":null,"errorMessage":"Illegal format '#{actual}' specified for value of Hash type - expected one of the characters 'hasp'","messagePattern":"Illegal format '#(.+?)' specified for value of Hash type - expected one of the characters 'hasp'","errorType":"validation","errorClass":"Puppet::Pops::Types::StringConverter::FormatError","httpStatus":null,"severity":"error","filePath":"lib/puppet/pops/types/string_converter.rb","lineNumber":1094,"sourceCode":"        padding = children_indentation.padding\n      end\n      buf << delims[0]\n      buf << cond_break # break after opening delimiter if pretty printing\n      buf << val.map do |k, v|\n        key_type = TypeCalculator.infer_set(k)\n        val_type = TypeCalculator.infer_set(v)\n        key = _convert(key_type, k, is_container?(key_type) ? format_map : string_formats, children_indentation)\n        val = _convert(val_type, v, is_container?(val_type) ? format_map : string_formats, children_indentation)\n        \"#{padding}#{key}#{assoc}#{val}\"\n      end.join(sep)\n      if format.alt?\n        buf << cond_break\n        buf << indentation.padding\n      end\n      buf << delims[1]\n      buf\n    else\n      raise FormatError.new('Hash', format.format, 'hasp')\n    end\n  end\n\n  # @api private\n  def string_PStructType(val_type, val, format_map, indentation)\n    string_PHashType(val_type, val, format_map, indentation)\n  end\n\n  # @api private\n  def string_PTypeType(val_type, val, format_map, _)\n    f = get_format(val_type, format_map)\n    case f.format\n    when :s\n      str_val = f.alt? ? \"\\\"#{val}\\\"\" : val.to_s\n      Kernel.format(f.orig_fmt, str_val)\n    when :p\n      Kernel.format(f.orig_fmt.tr('p', 's'), val.to_s)\n    else","sourceCodeStart":1076,"sourceCodeEnd":1112,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/pops/types/string_converter.rb#L1076-L1112","documentation":"StringConverter raises this FormatError when formatting a Hash (or Struct, which delegates to string_PHashType) with a container format letter outside 'hasp': 'h' (key => value rendering with per-key/per-value formats), 'a' (array-of-pairs rendering), 's' and 'p' (string/Puppet-notation forms). The else at string_converter.rb:1094 raises FormatError('Hash', format.format, 'hasp'). Struct values follow the same rule since string_PStructType forwards here.","triggerScenarios":"`String({a => 1}, '%d')` — scalar letter used as container letter; likewise for Struct-typed values. Per-key and per-value formats belong inside the container format specification, not as the leading letter.","commonSituations":"Pretty-printing option hashes for logs/reports and copying a value format as the top-level letter; converting Struct-validated data with a format designed for its values.","solutions":["Use '%h' for key => value output, '%a' for array-of-pairs, '%s'/'%p' for plain forms","Specify key/value element formats inside the container format options rather than as the leading letter","Whitelist the container letter against %w[h a s p]"],"exampleFix":"# before\n$str = String({a => 1}, '%d')\n# after\n$str = String({a => 1}, '%h')","handlingStrategy":"validation","validationCode":"fmt = '%d'\nletter = fmt[/\\A%[#\\-+ 0\\d.]*([a-zA-Z])\\z/, 1]\nraise ArgumentError, \"#{fmt} invalid for Hash/Struct (container letter must be h/a/s/p)\" unless %w[h a s p].include?(letter)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use %h for key => value rendering; %a for array-of-pairs","Put key/value element formats inside the container format spec, not as the leading letter","Remember Struct values format through the Hash rules"],"tags":["puppet","pops","string-conversion","format-error","hash","struct"],"backgroundTag":"invalid-format-specifier","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}