{"record":{"id":"4393874c2392d271","repo":"Morganamilo/paru","slug":"key-does-not-belong-to-a-section","errorCode":null,"errorMessage":"key '{}' does not belong to a section","messagePattern":"key '(.+?)' does not belong to a section","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/config.rs","lineNumber":957,"sourceCode":"            let value = match value {\n                Some(value) => value,\n                None => bail!(tr!(\"value can not be empty for key '{}'\", key)),\n            };\n\n            let ini = std::fs::read_to_string(value)?;\n\n            let section = self.section.clone();\n            let section = section.as_deref();\n            let section = self\n                .parse_with_section(section, Some(value), &ini)?\n                .map(|s| s.to_string());\n            self.section = section;\n            return Ok(());\n        }\n\n        let section = match &self.section {\n            Some(section) => section.as_str(),\n            None => bail!(tr!(\"key '{}' does not belong to a section\", key)),\n        };\n\n        let section = section.to_string();\n\n        match section.as_str() {\n            \"options\" => self.parse_option(key, value),\n            \"bin\" => self.parse_bin(key, value),\n            \"env\" => self.parse_env(key, value),\n            repo => self.parse_repo(repo, key, value),\n        }\n    }\n\n    fn parse_repo(&mut self, repo: &str, key: &str, value: Option<&str>) -> Result<()> {\n        let value = value.context(tr!(\"key can not be empty\"));\n\n        let repo = self.pkgbuild_repos.repo_mut(repo).unwrap();\n\n        match key {","sourceCodeStart":939,"sourceCodeEnd":975,"githubUrl":"https://github.com/Morganamilo/paru/blob/9ac3578807a87858651e81a02586ceb947686e7c/src/config.rs#L939-L975","documentation":"src/config.rs:957 throws \"key '{}' does not belong to a section\" when parse_directive encounters a key=value pair while self.section is None — i.e. a directive appears before any [Section] header in the INI file. INI semantics here require every key to live inside a section (e.g. [options] or [repo-name]); a bare key at the top of the file is rejected rather than implicitly assigned.","triggerScenarios":"Parsing a pacman.conf where a `key = value` line occurs before the first `[section]` header — commonly caused by prepending lines above `[options]`, deleting the section header, or an Include'd file whose keys are expected to belong to the includer's section but start with their own un-sectioned keys.","commonSituations":"Manually adding a setting at the very top of pacman.conf; editing scripts that rewrite the file and accidentally drop the `[options]` line; concatenating config fragments without section headers; corruption during package merge of /etc/pacman.conf.pacnew.","solutions":["Move the offending key=value line under an existing section (usually `[options]` or the relevant `[repo]`).","Re-add the missing `[options]` (or other) section header above the key.","Compare against the distro default pacman.conf / .pacnew file to restore proper section structure.","Validate with `pacman-conf` before handing the file to the parser."],"exampleFix":"// before (pacman.conf)\nParallelDownloads = 5\n[options]\n...\n\n// after (pacman.conf)\n[options]\nParallelDownloads = 5\n...","handlingStrategy":"validation","validationCode":"// Ensure every key line appears after at least one [section] header\nfn validate_sections(path: &str) -> Result<(), String> {\n    let mut in_section = false;\n    for (n, line) in std::fs::read_to_string(path)?.lines().enumerate() {\n        let line = line.trim();\n        if line.is_empty() || line.starts_with('#') { continue; }\n        if line.starts_with('[') && line.ends_with(']') { in_section = true; continue; }\n        if !in_section {\n            return Err(format!(\"line {}: key outside any section: '{}'\", n + 1, line));\n        }\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always append settings inside the correct section, never at the top of the file.","After editing section headers, grep for `^\\[` to confirm one exists before the first key.","Validate with `pacman-conf` after merges or scripted rewrites.","Keep Include'd fragments inside their own explicit sections."],"tags":["config","ini-parsing","pacman","missing-section"],"backgroundTag":"missing-required-config-field","analyzedSha":"9ac3578807a87858651e81a02586ceb947686e7c","analyzedAt":"2026-09-12T04:57:59.861Z","contentChangedAt":"2026-09-12T04:57:59.861Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}