Hmbown/CodeWhale · error

eligible allow rules are non-empty

Error message

eligible allow rules are non-empty

What it means

can_save_allow_rule() already checked persistent_allow_rules is non-empty, stakes are not Critical, and the prompt is not repo-law; allow_rule_save_preview's .then(...) only builds the preview when that guard returned true. The expect fires only if the eligibility check and the preview construction drift apart — an internal invariant break in approval state, never a data-driven condition.

Source

Thrown at crates/tui/src/tui/approval.rs:272

    }

    #[must_use]
    pub fn can_save_allow_rule(&self) -> bool {
        !self.persistent_allow_rules.is_empty()
            && self.stakes() != ApprovalStakes::Critical
            && !self.is_repo_law_prompt()
    }

    #[must_use]
    pub fn ask_rule_save_preview(&self) -> Option<PermissionRuleSavePreview> {
        build_save_preview(&self.persistent_ask_rules, SAVE_PREVIEW_MAX_ENTRIES)
    }

    #[must_use]
    pub fn allow_rule_save_preview(&self) -> Option<PermissionRuleSavePreview> {
        self.can_save_allow_rule().then(|| {
            build_save_preview(&self.persistent_allow_rules, SAVE_PREVIEW_MAX_ENTRIES)
                .expect("eligible allow rules are non-empty")
        })
    }

    #[must_use]
    #[cfg(test)]
    pub fn ask_rule_preview(&self) -> Option<String> {
        if self.persistent_ask_rules.is_empty() {
            return None;
        }
        let permissions = codewhale_config::PermissionsToml {
            rules: self.persistent_ask_rules.clone(),
        };
        toml::to_string_pretty(&permissions).ok()
    }

    /// Extract the most important params for the approval card.
    #[must_use]
    pub fn prominent_detail_items(&self, locale: Locale) -> Vec<ApprovalDetail> {

View on GitHub (pinned to 0c42157ee5)

Solutions

  1. Route all save-preview construction through can_save_allow_rule so the guard and expectation share one source of truth
  2. If new disqualifying conditions appear, add them to can_save_allow_rule, not as parallel checks
  3. Add a test asserting preview is Some exactly when can_save_allow_rule is true
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at crates/tui/src/tui/approval.rs:272 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/a6e6b42e1c6203e9. Report an issue: GitHub.