Skip to main content

vigil_ui_protocol/
error.rs

1//! `UiError`:协议层错误(ADR 0008 §I-8.2:不得含真实 secret / 原始后端文本)。
2
3use serde::{Deserialize, Serialize};
4use thiserror::Error;
5
6/// UI 协议错误。所有变种**不得**含真实 secret 或原始 SQL / keyring 后端文本。
7/// `LedgerError` 只承载 `AuditError::Display` 的结果,`AuditError` 自身已结构化脱敏。
8#[derive(Debug, Clone, Error, Serialize, Deserialize, PartialEq, Eq)]
9#[serde(tag = "kind", content = "detail")]
10#[non_exhaustive]
11pub enum UiError {
12    /// 资源不存在(approval / session / profile / server)
13    #[error("not_found: {0}")]
14    NotFound(String),
15    /// 输入不合法 —— 稳定字符串 reason,不含 raw 输入
16    #[error("invalid: {0}")]
17    Invalid(&'static str),
18    /// 权限不足
19    #[error("capability_denied: required={required}")]
20    CapabilityDenied {
21        /// 需要的 capability(`ui.read` / `ui.write`)
22        required: &'static str,
23    },
24    /// Ledger 层错误转译;caller 应看 reason_code 而非原文
25    #[error("ledger_error: {reason_code}")]
26    LedgerError {
27        /// 稳定 reason code(audit 层已结构化)
28        reason_code: &'static str,
29    },
30    /// argv 含硬指纹 secret(D5 fail-closed 入口)
31    #[error("secret_in_argv: server={server_id} rule={rule}")]
32    SecretInArgv {
33        /// 触发的 server id(非敏感)
34        server_id: String,
35        /// 命中的规则名(github_token / openai_key / pem_private_key / ...)
36        rule: &'static str,
37    },
38    /// Sandbox profile JCS 规范化失败
39    #[error("profile_serialize_failed")]
40    ProfileSerializeFailed,
41}