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

  1. Delete or rename the earlier duplicate definition
  2. Grep the provider and any monkey-patches from modules for the record name before re-declaring it
  3. 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

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


AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21). Data as JSON: /api/errors/fcdf117f00fe4182. Report an issue: GitHub.