puppetlabs/puppet · error · IniParseError

Property with key outside of a section

Error message

Property with key %{key} outside of a section

What it means

Raised by Puppet::Util::IniConfig::File#parse when an INI line looks like a `key = value` property but appears before any [section] heading has been parsed, so there is no section to attach the key to. It is a structural error in the INI file being read (via read), not a runtime failure.

Solutions

  1. Add a [section] heading before the first `key = value` line in the INI file
  2. Check the file for a missing or misspelled section header above the offending key
  3. Move the orphaned key/value pair under an existing valid section
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at lib/puppet/util/inifile.rb:187 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at lib/puppet/util/inifile.rb:187

          end
        elsif l.match(INI_CONTINUATION) && section && optname
          # continuation line
          section[optname] += "\n#{l.chomp}"
        elsif (match = l.match(INI_SECTION_NAME))
          # section heading
          section.mark_clean if section

          section_name = match[1]

          section = add_section(section_name)
          optname = nil
        elsif (match = l.match(INI_PROPERTY))
          # the regex strips leading white space from the value, and here we strip the trailing white space as well
          key = match[1]
          val = match[2].rstrip

          if section.nil?
            raise IniParseError, _("Property with key %{key} outside of a section") % { key: key.inspect }
          end

          section[key] = val
          optname = key
        else
          raise IniParseError.new(_("Can't parse line '%{line}'") % { line: l.chomp }, @file, line_num)
        end
      end
      section.mark_clean unless section.nil?
    end

    # @return [Array<Puppet::Util::IniConfig::Section>] All sections defined in
    #   this file.
    def sections
      @contents.select { |entry| entry.is_a? Section }
    end

    # @return [Puppet::Util::IniConfig::Section, nil] The section with the

View on GitHub (pinned to e227c27540)