Hmbown/CodeWhale · error

rules entry was inserted above

Error message

rules entry was inserted above

What it means

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.

Source

Thrown at crates/config/src/lib.rs:5309

        }
        if rules.iter().any(|rule| rule.action != expected_action) {
            bail!(
                "permission rule action does not match requested {:?} persistence",
                expected_action
            );
        }

        let path = checked_permissions_path_for_config_path(&self.path)?;
        let (added, persisted) = config_document::with_config_write_lock(&path, |path| {
            let (_, raw, mut permissions) = read_permissions_state(path)?;
            let mut document = parse_permissions_document(path, &raw)?;

            if !document.contains_key("rules") {
                document["rules"] = toml_edit::Item::ArrayOfTables(toml_edit::ArrayOfTables::new());
            }
            let rules_item = document
                .get_mut("rules")
                .expect("rules entry was inserted above");

            let mut added = 0;
            for rule in rules {
                if permissions.rules.contains(rule) {
                    continue;
                }
                append_permission_rule(rules_item, rule)?;
                permissions.rules.push(rule.clone());
                added += 1;
            }
            if added == 0 {
                return Ok((0, permissions));
            }

            let body = document.to_string();
            let persisted = parse_generated_permissions(path, &body)?;
            write_permissions_atomic(path, body.as_bytes())?;
            Ok((added, persisted))

View on GitHub (pinned to 0c42157ee5)

Solutions

  1. Verify the 'rules' key insertion logic in the permissions document writer
  2. Report a bug including the permissions file contents that triggered it
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at crates/config/src/lib.rs:5309 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Hmbown/CodeWhale@0c42157ee5 (2026-08-20). Data as JSON: /api/errors/310f51b441e4b38b. Report an issue: GitHub.