{"record":{"id":"480b1ba332055a9c","repo":"puppetlabs/puppet","slug":"unknown-plist-format-format","errorCode":null,"errorMessage":"Unknown plist format #{format}","messagePattern":"Unknown plist format #(.+?)","errorType":"validation","errorClass":"Puppet::Util::Plist::FormatError","httpStatus":null,"severity":"error","filePath":"lib/puppet/util/plist.rb","lineNumber":141,"sourceCode":"\n    # Helper method to assist in reading a file with an offset value. It's its\n    # own method for stubbing purposes\n    #\n    # @api private\n    def read_file_with_offset(file_path, offset)\n      IO.read(file_path, offset)\n    end\n\n    def to_format(format)\n      case format.to_sym\n      when :xml\n        CFPropertyList::List::FORMAT_XML\n      when :binary\n        CFPropertyList::List::FORMAT_BINARY\n      when :plain\n        CFPropertyList::List::FORMAT_PLAIN\n      else\n        raise FormatError, \"Unknown plist format #{format}\"\n      end\n    end\n\n    # This method will write a plist file using a specified format (or XML\n    # by default)\n    def write_plist_file(plist, file_path, format = :xml)\n      plist_to_save       = CFPropertyList::List.new\n      plist_to_save.value = CFPropertyList.guess(plist)\n      plist_to_save.save(file_path, to_format(format), :formatted => true)\n    rescue IOError => e\n      Puppet.err(_(\"Unable to write the file %{file_path}. %{error}\") % { file_path: file_path, error: e.inspect })\n    end\n\n    def dump_plist(plist_data, format = :xml)\n      plist_to_save       = CFPropertyList::List.new\n      plist_to_save.value = CFPropertyList.guess(plist_data)\n      plist_to_save.to_str(to_format(format), :formatted => true)\n    end","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/util/plist.rb#L123-L159","documentation":"Puppet::Util::Plist.to_format (plist.rb:141) maps a format symbol to a CFPropertyList constant; only :xml, :binary, and :plain are recognized, anything else raises FormatError. It is reached through Puppet::Util::Plist.write_plist_file(plist, file_path, format), used by Puppet's macOS providers (directoryservice writes :binary, launchd writes the default :xml).","triggerScenarios":"Plist.write_plist_file(data, path, :json); Plist.write_plist_file(data, path, 'XML') (case mismatch after to_sym); Plist.write_plist_file(data, path, :bplist) or :xml1 (made-up names); passing a format through a config string that was never whitelisted.","commonSituations":"Custom macOS provider code adding new plist output; configuration-driven format selection where users type 'xml-1.0' or 'binary-plist'; copying example code from CFPropertyList docs that uses its own format constants.","solutions":["Use one of the three supported symbols: :xml, :binary, :plain (omitting format defaults to :xml).","Whitelist-validate at the boundary: raise your own error for anything outside %i[xml binary plain].","Normalize user input: format.to_s.strip.downcase.to_sym before passing.","Rescue Puppet::Util::Plist::FormatError and report the supported formats."],"exampleFix":"// before\nPuppet::Util::Plist.write_plist_file(plist, path, requested_format) # requested_format = 'XML'\n\n// after\nfmt = requested_format.to_s.strip.downcase.to_sym\nraise ArgumentError, \"format must be xml|binary|plain\" unless %i[xml binary plain].include?(fmt)\nPuppet::Util::Plist.write_plist_file(plist, path, fmt)","handlingStrategy":"validation","validationCode":"fmt = fmt.to_s.strip.downcase.to_sym\nraise ArgumentError, 'format must be :xml, :binary or :plain' unless %i[xml binary plain].include?(fmt)","typeGuard":"def plist_format?(f)\n  %i[xml binary plain].include?(f.to_s.strip.downcase.to_sym)\nend","tryCatchPattern":"begin\n  Puppet::Util::Plist.write_plist_file(data, path, fmt)\nrescue Puppet::Util::Plist::FormatError => e\n  Puppet.err(\"#{e.message}; defaulting to :xml\")\n  Puppet::Util::Plist.write_plist_file(data, path, :xml)\nend","preventionTips":["Normalize user-supplied formats (downcase + to_sym) and whitelist to %i[xml binary plain].","Remember write_plist_file already defaults to :xml; omit the argument unless a specific format is required."],"tags":["macos","plist","cfpropertylist","puppet","file-format","validation"],"backgroundTag":"unsupported-file-format","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}