Hmbown/CodeWhale · error · anyhow::Error

persistent command allow rules must not be empty

Error message

persistent command allow rules must not be empty

What it means

append_allow_rules (crates/config/src/lib.rs:5272) rejects a command allow rule whose command string trims to empty. An empty exact-match command is either a bug or a trivially-bypassed grant, so it never reaches permissions.toml.

Source

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

                bail!("append_allow_rules only accepts action = \"allow\"");
            }
            let Some(workspace) = rule
                .workspace
                .as_deref()
                .and_then(codewhale_execpolicy::normalize_workspace_scope)
            else {
                bail!("persistent allow rules must be scoped to a workspace");
            };
            if rule.command.is_some() && !rule.command_exact {
                bail!("persistent command allow rules must use exact matching");
            }
            if rule.command.is_none() && rule.path.is_none() {
                bail!("persistent allow rules must match an exact command or path");
            }
            if let Some(command) = rule.command.as_deref()
                && command.trim().is_empty()
            {
                bail!("persistent command allow rules must not be empty");
            }
            if let Some(path) = rule.path.as_deref()
                && codewhale_execpolicy::normalize_workspace_relative_path(path, &workspace)
                    .is_none_or(|path| path.is_empty())
            {
                bail!("persistent path allow rules must stay within the workspace");
            }
        }
        self.append_permission_rules(rules, PermissionAction::Allow)
    }

    fn append_permission_rules(
        &mut self,
        rules: &[ToolAskRule],
        expected_action: PermissionAction,
    ) -> Result<usize> {
        if rules.is_empty() {
            return Ok(0);

View on GitHub (pinned to 0c42157ee5)

Solutions

  1. Populate the exact non-empty command string before persisting
  2. Trim input at the UI boundary and reject empty submissions there
  3. If the command is genuinely empty, the rule has no meaning — drop it

Example fix

// before
let rule = ToolAskRule { command: Some(String::new()), command_exact: true, /* ... */ };

// after
let rule = ToolAskRule { command: Some(approved_command.trim().to_owned()), command_exact: true, /* ... */ };
Defensive patterns

Strategy: validation

Validate before calling

assert!(rule.command.as_deref().is_none_or(|c| !c.trim().is_empty())); // before append

Type guard

fn is_nonempty_command_rule(rule: &ToolAskRule) -> bool {
    rule.command.as_deref().is_none_or(|c| !c.trim().is_empty())
}

Prevention

When it happens

Trigger: A ToolAskRule with command = Some("" or " ") and command_exact = true passed to append_allow_rules — usually an unpopulated form field or a deserialized default.

Common situations: Automation persisting an approval event before the command string is filled in, string manipulation producing an empty command (e.g. splitting a shell line incorrectly).

Related errors


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