{"record":{"id":"c39fe2bd1ea6770c","repo":"puppetlabs/puppet","slug":"can-t-parse-line-line","errorCode":null,"errorMessage":"Can't parse line '%{line}'","messagePattern":"Can't parse line '%(.+?)'","errorType":"exception","errorClass":"Puppet::Util::IniConfig::IniParseError","httpStatus":null,"severity":"error","filePath":"lib/puppet/util/inifile.rb","lineNumber":193,"sourceCode":"          section.mark_clean if section\n\n          section_name = match[1]\n\n          section = add_section(section_name)\n          optname = nil\n        elsif (match = l.match(INI_PROPERTY))\n          # the regex strips leading white space from the value, and here we strip the trailing white space as well\n          key = match[1]\n          val = match[2].rstrip\n\n          if section.nil?\n            raise IniParseError, _(\"Property with key %{key} outside of a section\") % { key: key.inspect }\n          end\n\n          section[key] = val\n          optname = key\n        else\n          raise IniParseError.new(_(\"Can't parse line '%{line}'\") % { line: l.chomp }, @file, line_num)\n        end\n      end\n      section.mark_clean unless section.nil?\n    end\n\n    # @return [Array<Puppet::Util::IniConfig::Section>] All sections defined in\n    #   this file.\n    def sections\n      @contents.select { |entry| entry.is_a? Section }\n    end\n\n    # @return [Puppet::Util::IniConfig::Section, nil] The section with the\n    #   given name if it exists, else nil.\n    def get_section(name)\n      @contents.find { |entry| entry.is_a? Section and entry.name == name }\n    end\n\n    def format","sourceCodeStart":175,"sourceCodeEnd":211,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/util/inifile.rb#L175-L211","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\n[main]\nmy server = puppet.example.com   # key with space -> IniParseError\n\n# after\n[main]\nserver = puppet.example.com","handlingStrategy":"validation","validationCode":"INI_OK = [/^\\s*$/, /^[#;]/, /^\\s*rem\\s/i, /^\\[[^\\]]+\\]$/, /^\\s*[^\\s=]+\\s*=\\s*.*$/]\ndef inifile_line_valid?(line)\n INI_OK.any? { |re| line.match(re) }\nend\nbad = File.foreach(path).each_with_index.reject { |l, i| inifile_line_valid?(l) }\n# report bad lines before IniFile#read","typeGuard":null,"tryCatchPattern":"begin\n  ini.read\nrescue Puppet::Util::IniConfig::IniParseError => e\n  # message embeds the offending line; file/line may be attached\n  raise \"invalid config #{path}: #{e.message}\"\nend","preventionTips":["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"],"tags":["ini","config-parsing","inifile","puppet"],"backgroundTag":"malformed-config-file","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}