{"record":{"id":"310f51b441e4b38b","repo":"Hmbown/CodeWhale","slug":"rules-entry-was-inserted-above","errorCode":null,"errorMessage":"rules entry was inserted above","messagePattern":"rules entry was inserted above","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/config/src/lib.rs","lineNumber":5309,"sourceCode":"        }\n        if rules.iter().any(|rule| rule.action != expected_action) {\n            bail!(\n                \"permission rule action does not match requested {:?} persistence\",\n                expected_action\n            );\n        }\n\n        let path = checked_permissions_path_for_config_path(&self.path)?;\n        let (added, persisted) = config_document::with_config_write_lock(&path, |path| {\n            let (_, raw, mut permissions) = read_permissions_state(path)?;\n            let mut document = parse_permissions_document(path, &raw)?;\n\n            if !document.contains_key(\"rules\") {\n                document[\"rules\"] = toml_edit::Item::ArrayOfTables(toml_edit::ArrayOfTables::new());\n            }\n            let rules_item = document\n                .get_mut(\"rules\")\n                .expect(\"rules entry was inserted above\");\n\n            let mut added = 0;\n            for rule in rules {\n                if permissions.rules.contains(rule) {\n                    continue;\n                }\n                append_permission_rule(rules_item, rule)?;\n                permissions.rules.push(rule.clone());\n                added += 1;\n            }\n            if added == 0 {\n                return Ok((0, permissions));\n            }\n\n            let body = document.to_string();\n            let persisted = parse_generated_permissions(path, &body)?;\n            write_permissions_atomic(path, body.as_bytes())?;\n            Ok((added, persisted))","sourceCodeStart":5291,"sourceCodeEnd":5327,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/0c42157ee52f9d55af2b506d71b46249910f77d3/crates/config/src/lib.rs#L5291-L5327","documentation":"Invariant in the permissions persistence path: the code ensures a 'rules' array exists (inserting it if absent) before appending, so the subsequent lookup of that entry is expected to succeed. Firing means the insert or document mutation went wrong — a code bug, not a user-facing condition.","triggerScenarios":"Thrown at crates/config/src/lib.rs:5309 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the 'rules' key insertion logic in the permissions document writer","Report a bug including the permissions file contents that triggered it"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"0c42157ee52f9d55af2b506d71b46249910f77d3","analyzedAt":"2026-08-20T21:50:45.477Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}