{"record":{"id":"a6e6b42e1c6203e9","repo":"Hmbown/CodeWhale","slug":"eligible-allow-rules-are-non-empty","errorCode":null,"errorMessage":"eligible allow rules are non-empty","messagePattern":"eligible allow rules are non-empty","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/tui/approval.rs","lineNumber":272,"sourceCode":"    }\n\n    #[must_use]\n    pub fn can_save_allow_rule(&self) -> bool {\n        !self.persistent_allow_rules.is_empty()\n            && self.stakes() != ApprovalStakes::Critical\n            && !self.is_repo_law_prompt()\n    }\n\n    #[must_use]\n    pub fn ask_rule_save_preview(&self) -> Option<PermissionRuleSavePreview> {\n        build_save_preview(&self.persistent_ask_rules, SAVE_PREVIEW_MAX_ENTRIES)\n    }\n\n    #[must_use]\n    pub fn allow_rule_save_preview(&self) -> Option<PermissionRuleSavePreview> {\n        self.can_save_allow_rule().then(|| {\n            build_save_preview(&self.persistent_allow_rules, SAVE_PREVIEW_MAX_ENTRIES)\n                .expect(\"eligible allow rules are non-empty\")\n        })\n    }\n\n    #[must_use]\n    #[cfg(test)]\n    pub fn ask_rule_preview(&self) -> Option<String> {\n        if self.persistent_ask_rules.is_empty() {\n            return None;\n        }\n        let permissions = codewhale_config::PermissionsToml {\n            rules: self.persistent_ask_rules.clone(),\n        };\n        toml::to_string_pretty(&permissions).ok()\n    }\n\n    /// Extract the most important params for the approval card.\n    #[must_use]\n    pub fn prominent_detail_items(&self, locale: Locale) -> Vec<ApprovalDetail> {","sourceCodeStart":254,"sourceCodeEnd":290,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/0c42157ee52f9d55af2b506d71b46249910f77d3/crates/tui/src/tui/approval.rs#L254-L290","documentation":"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.","triggerScenarios":"Thrown at crates/tui/src/tui/approval.rs:272 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Route all save-preview construction through can_save_allow_rule so the guard and expectation share one source of truth","If new disqualifying conditions appear, add them to can_save_allow_rule, not as parallel checks","Add a test asserting preview is Some exactly when can_save_allow_rule is true"],"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-14T05:17:10.506Z"}