puppetlabs/puppet · error · Puppet::Util::IniConfig::IniParseError
Can't parse line '%{line}'
Error message
Can't parse line '%{line}' What it means
Puppet::Util::IniConfig::IniFile#parse raises IniParseError (with the file and 1-based line number attached) when a line is none of: blank, a comment (#, ;, or rem prefix), a [section] header, a continuation line inside a section, or a 'key = value' property whose key is a non-empty token with no whitespace or '='. The message embeds the offending line (chomped) so the file can be fixed directly.
Source
Thrown at lib/puppet/util/inifile.rb:193
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
# given name if it exists, else nil.
def get_section(name)
@contents.find { |entry| entry.is_a? Section and entry.name == name }
end
def formatView on GitHub (pinned to e227c27540)
Solutions
- Open the file at the reported line number and reformat the entry as 'key = value' with a space-free key, or delete the stray text
- Convert 'key: value' entries to 'key = value'
- Rename keys containing spaces to single-token keys (my_key), since the property regex forbids whitespace in keys
- If the line is documentation, prefix it with # or ; so it matches the comment pattern
Example fix
# before [main] my server = puppet.example.com # key with space -> IniParseError # after [main] server = puppet.example.com
Defensive patterns
Strategy: validation
Validate before calling
INI_OK = [/^\s*$/, /^[#;]/, /^\s*rem\s/i, /^\[[^\]]+\]$/, /^\s*[^\s=]+\s*=\s*.*$/]
def inifile_line_valid?(line)
INI_OK.any? { |re| line.match(re) }
end
bad = File.foreach(path).each_with_index.reject { |l, i| inifile_line_valid?(l) }
# report bad lines before IniFile#read Try / catch
begin
ini.read
rescue Puppet::Util::IniConfig::IniParseError => e
# message embeds the offending line; file/line may be attached
raise "invalid config #{path}: #{e.message}"
end Prevention
- Write INI files programmatically (key = value with token keys) instead of templating prose into them
- Lint generated INI with the four legal line patterns in CI
- Keep keys single-token (letters, digits, underscore) — the parser forbids spaces and '=' in keys
When it happens
Trigger: Feeding IniFile#read/#parse a file containing a key with spaces ('my key = v'), a bare word with no '=' ('server'), an empty key ('= value'), or any stray text matching none of the INI_COMMENT/INI_CONTINUATION/INI_SECTION_NAME/INI_PROPERTY patterns.
Common situations: Hand-edited INI files (device.conf and other files managed through Puppet::Util::IniConfig) with stray text; files written by tools using 'key: value' YAML/JSON-style syntax; keys containing spaces; copy-paste artifacts like rulers or arrows.
Related errors
- Section %{name} is already defined, cannot redefine
- puppet.tasks/missing-implementation
- puppet.tasks/no-implementation
- PathPatterns cannot be created with a zero byte.
- Request to Puppet Forge failed. Detail: %{detail}.
AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21).
Data as JSON: /api/errors/c39fe2bd1ea6770c.
Report an issue: GitHub.