{"record":{"id":"fcdf117f00fe4182","repo":"puppetlabs/puppet","slug":"line-type-name-is-already-defined","errorCode":null,"errorMessage":"Line type %{name} is already defined","messagePattern":"Line type %(.+?) is already defined","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/util/fileparsing.rb","lineNumber":392,"sourceCode":"\n  def valid_attr?(type, attr)\n    type = type.intern\n    record = record_type(type)\n    if record && record.fields.include?(attr.intern)\n      true\n    else\n      attr.intern == :ensure\n    end\n  end\n\n  private\n\n  # Define a new type of record.\n  def new_line_type(record)\n    @record_types ||= {}\n    @record_order ||= []\n\n    raise ArgumentError, _(\"Line type %{name} is already defined\") % { name: record.name } if @record_types.include?(record.name)\n\n    @record_types[record.name] = record\n    @record_order << record\n\n    record\n  end\n\n  # Retrieve the record object.\n  def record_type(type)\n    @record_types[type.intern]\n  end\nend\n","sourceCodeStart":374,"sourceCodeEnd":405,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/util/fileparsing.rb#L374-L405","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\nrecord_line :myconf, fields: %i[k v]\nrecord_line :myconf, fields: %i[k v other]\n# => ArgumentError: Line type myconf is already defined\n\n# after\nrecord_line :myconf_v2, fields: %i[k v other]","handlingStrategy":"validation","validationCode":"existing = provider.instance_variable_get(:@record_types)&.keys || []\nraise ArgumentError, \"#{name} already defined\" if existing.include?(name)\nrecord_line name, fields: %i[k v]","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["puppet","provider","file-parsing","duplicate","definition"],"backgroundTag":"duplicate-registration","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}