puppetlabs/puppet · error · ArgumentError
Cannot have fields named %{name}
Error message
Cannot have fields named %{name} What it means
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.
Source
Thrown at lib/puppet/util/fileparsing.rb:45
# the text line again.
module Puppet::Util::FileParsing
include Puppet::Util
attr_writer :line_separator, :trailing_separator
class FileRecord
include Puppet::Util
attr_accessor :absent, :joiner, :rts, :separator, :rollup, :name, :match, :block_eval
attr_reader :fields, :optional, :type
INVALID_FIELDS = [:record_type, :target, :on_disk]
# Customize this so we can do a bit of validation.
def fields=(fields)
@fields = fields.collect do |field|
r = field.intern
raise ArgumentError, _("Cannot have fields named %{name}") % { name: r } if INVALID_FIELDS.include?(r)
r
end
end
def initialize(type,
absent: nil,
block_eval: nil,
fields: nil,
joiner: nil,
match: nil,
optional: nil,
post_parse: nil,
pre_gen: nil,
rollup: nil,
rts: nil,
separator: nil,
to_line: nil,View on GitHub (pinned to e227c27540)
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
Example fix
# before record_line :route, fields: %i[destination gateway target], separator: /\s+/ # => ArgumentError: Cannot have fields named target # after record_line :route, fields: %i[destination gateway interface], separator: /\s+/
Defensive patterns
Strategy: validation
Validate before calling
INVALID = %i[record_type target on_disk] fields = wanted_fields - INVALID record_line :myline, fields: fields
Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Invalid record type %{record_type}
- Field '%{field}' is required
- Process record type %{record_name} returned non-hash
- No record types defined; cannot parse lines
- Somehow got invalid line type %{record_type}
AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21).
Data as JSON: /api/errors/6e56c55884f3d205.
Report an issue: GitHub.