puppetlabs/puppet · error · ArgumentError
Line type %{name} is already defined
Error message
Line type %{name} is already defined What it means
new_line_type registers a record type under its name in @record_types; registering the same name twice on one provider class raises ArgumentError. Both record_line and text_line funnel through it, so this fires at definition time for duplicate declarations.
Source
Thrown at lib/puppet/util/fileparsing.rb:392
def valid_attr?(type, attr)
type = type.intern
record = record_type(type)
if record && record.fields.include?(attr.intern)
true
else
attr.intern == :ensure
end
end
private
# Define a new type of record.
def new_line_type(record)
@record_types ||= {}
@record_order ||= []
raise ArgumentError, _("Line type %{name} is already defined") % { name: record.name } if @record_types.include?(record.name)
@record_types[record.name] = record
@record_order << record
record
end
# Retrieve the record object.
def record_type(type)
@record_types[type.intern]
end
end
View on GitHub (pinned to e227c27540)
Solutions
- Delete or rename the earlier duplicate definition
- Grep the provider and any monkey-patches from modules for the record name before re-declaring it
- In tests, define records once per class or use fresh anonymous subclasses per case
Example fix
# before record_line :myconf, fields: %i[k v] record_line :myconf, fields: %i[k v other] # => ArgumentError: Line type myconf is already defined # after record_line :myconf_v2, fields: %i[k v other]
Defensive patterns
Strategy: validation
Validate before calling
existing = provider.instance_variable_get(:@record_types)&.keys || []
raise ArgumentError, "#{name} already defined" if existing.include?(name)
record_line name, fields: %i[k v] Prevention
- One record_line per name per provider class
- When reopening provider classes in modules, check existing record names first
- Use fresh anonymous subclasses in specs to avoid leaking definitions between cases
When it happens
Trigger: Two record_line (or text_line) calls with the same name in one provider class — for example an edited provider where a renamed definition left the old one in place, or a class that gets reopened and evaluated twice.
Common situations: Copy-paste provider definitions, modules that ship two versions of the same provider file, and spec suites that re-eval provider classes without resetting the record registry.
Related errors
- Cannot have fields named %{name}
- Invalid record type %{record_type}
- Field '%{field}' is required
- Process record type %{record_name} returned non-hash
- No record types defined; cannot parse lines
AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21).
Data as JSON: /api/errors/fcdf117f00fe4182.
Report an issue: GitHub.