{"record":{"id":"6e56c55884f3d205","repo":"puppetlabs/puppet","slug":"cannot-have-fields-named-name","errorCode":null,"errorMessage":"Cannot have fields named %{name}","messagePattern":"Cannot have fields named %(.+?)","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/util/fileparsing.rb","lineNumber":45,"sourceCode":"# the text line again.\n\nmodule Puppet::Util::FileParsing\n  include Puppet::Util\n  attr_writer :line_separator, :trailing_separator\n\n  class FileRecord\n    include Puppet::Util\n    attr_accessor :absent, :joiner, :rts, :separator, :rollup, :name, :match, :block_eval\n\n    attr_reader :fields, :optional, :type\n\n    INVALID_FIELDS = [:record_type, :target, :on_disk]\n\n    # Customize this so we can do a bit of validation.\n    def fields=(fields)\n      @fields = fields.collect do |field|\n        r = field.intern\n        raise ArgumentError, _(\"Cannot have fields named %{name}\") % { name: r } if INVALID_FIELDS.include?(r)\n\n        r\n      end\n    end\n\n    def initialize(type,\n                   absent: nil,\n                   block_eval: nil,\n                   fields: nil,\n                   joiner: nil,\n                   match: nil,\n                   optional: nil,\n                   post_parse: nil,\n                   pre_gen: nil,\n                   rollup: nil,\n                   rts: nil,\n                   separator: nil,\n                   to_line: nil,","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/util/fileparsing.rb#L27-L63","documentation":"Puppet::Util::FileParsing records turn each parsed line into a hash keyed by field name, and three keys — :record_type, :target, and :on_disk — are reserved for Puppet's own bookkeeping (they carry the record kind, the target file, and the on-disk flag). FileRecord#fields= rejects those names with ArgumentError at provider-definition time, before any file is read.","triggerScenarios":"Writing record_line :myline, fields: %i[name target] (or :record_type / :on_disk) in a custom provider based on Puppet::Util::FileParsing or Puppet::Provider::ParsedFile — the pattern used by Puppet's own host, port, and mounting providers.","commonSituations":"Authoring a new parsed-file provider and naturally wanting a field literally named 'target' or 'record_type'; porting an old provider to a newer Puppet that added or extended the reserved list.","solutions":["Rename the field (e.g. :target to :destination, :record_type to :kind) and update any match/process/to_line hooks accordingly","If the value genuinely duplicates Puppet's metadata, drop the field and read details[:target] or details[:record_type] instead"],"exampleFix":"# before\nrecord_line :route, fields: %i[destination gateway target], separator: /\\s+/\n# => ArgumentError: Cannot have fields named target\n\n# after\nrecord_line :route, fields: %i[destination gateway interface], separator: /\\s+/","handlingStrategy":"validation","validationCode":"INVALID = %i[record_type target on_disk]\nfields = wanted_fields - INVALID\nrecord_line :myline, fields: fields","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never name provider fields :record_type, :target, or :on_disk — Puppet injects them into every parsed record","Check the reserved list before choosing field names for hash-returning APIs"],"tags":["puppet","provider","file-parsing","reserved-name"],"backgroundTag":"reserved-field-name","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}