puppetlabs/puppet · error · ArgumentError

Field '%{field}' is required

Error message

Field '%{field}' is required

What it means

When a FileParsing provider regenerates a file, FileRecord#join serializes each record back into a line; any field whose value is :absent, [:absent], or nil must be covered. If the field is not listed in :optional, join raises ArgumentError 'Field ... is required' and the write is aborted mid-generation.

Source

Thrown at lib/puppet/util/fileparsing.rb:114

          instance_eval(&block)
        else
          meta_def(@block_eval, &block)
        end
      end
    end

    # Convert a record into a line by joining the fields together appropriately.
    # This is pulled into a separate method so it can be called by the hooks.
    def join(details)
      joinchar = self.joiner

      fields.filter_map { |field|
        # If the field is marked absent, use the appropriate replacement
        if details[field] == :absent or details[field] == [:absent] or details[field].nil?
          if self.optional.include?(field)
            self.absent
          else
            raise ArgumentError, _("Field '%{field}' is required") % { field: field }
          end
        else
          details[field].to_s
        end
      }.join(joinchar)
    end

    # Customize this so we can do a bit of validation.
    def optional=(optional)
      @optional = optional.collect(&:intern)
    end

    # Create a hook that modifies the hash resulting from parsing.
    def post_parse=(block)
      meta_def(:post_parse, &block)
    end

    # Create a hook that modifies the hash just prior to generation.

View on GitHub (pinned to e227c27540)

Solutions

  1. Fix or normalize the source file so every required field is present
  2. Declare genuinely omissible fields as optional in record_line: optional: %i[dump pass]
  3. Pre-validate the record hash and fill defaults before serialization

Example fix

# before
record_line :fstab, fields: %i[device mount fstype options dump pass], separator: /\s+/
# line 'tmpfs /tmp tmpfs defaults' => ArgumentError: Field 'dump' is required

# after
record_line :fstab, fields: %i[device mount fstype options dump pass], separator: /\s+/,
  optional: %i[dump pass], absent: '0'
Defensive patterns

Strategy: validation

Validate before calling

filled = details.reject { |_, v| v.nil? || v == :absent || v == [:absent] }
missing = record.fields - record.optional - filled.keys
raise ArgumentError, "missing #{missing.join(', ')}" unless missing.empty?

Prevention

When it happens

Trigger: A parsed record missing a column that was declared required — for example an /etc/fstab line with only four fields while the provider's record_line declared five (like :dump or :pass) — and Puppet then rewrites the file to add or remove an entry. Also a custom process/to_line hook leaving a required field nil.

Common situations: Malformed system files (fstab entries missing the dump/pass columns), hand-edited config lines, and providers moving between Puppet versions whose optional lists changed.

Understand the failure class

Background: "Missing required field" and "field is required" errors: why libraries reject payloads that omit mandatory fields — this error's family across 20 libraries.

Related errors


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