Skip to main content

mini_chat_sdk/
error.rs

1use thiserror::Error;
2
3/// Errors returned by `MiniChatModelPolicyPluginClientV1` methods.
4#[derive(Debug, Error)]
5pub enum MiniChatModelPolicyPluginError {
6    #[error("policy not found for the given tenant/version")]
7    NotFound,
8
9    #[error("internal policy plugin error: {0}")]
10    Internal(String),
11}
12
13/// Errors returned by `MiniChatAuditPluginClientV1` methods.
14///
15/// Mirrors `PublishError` transient/permanent classification so callers can
16/// decide whether to retry or record the failure as permanent.
17#[derive(Debug, Error)]
18pub enum MiniChatAuditPluginError {
19    /// Transient failure — safe to retry (network timeout, broker unavailable).
20    #[error("transient audit plugin error: {0}")]
21    Transient(String),
22
23    /// Permanent failure — do not retry (schema mismatch, auth rejected).
24    #[error("permanent audit plugin error: {0}")]
25    Permanent(String),
26
27    /// The plugin emit future exceeded its deadline; treated as transient so
28    /// the outbox will retry the message on the next cycle.
29    #[error("audit plugin timed out")]
30    PluginTimeout,
31}
32
33impl MiniChatAuditPluginError {
34    #[must_use]
35    pub fn is_transient(&self) -> bool {
36        matches!(self, Self::Transient(_) | Self::PluginTimeout)
37    }
38
39    #[must_use]
40    pub fn is_permanent(&self) -> bool {
41        matches!(self, Self::Permanent(_))
42    }
43}
44
45/// Errors returned by `publish_usage()`.
46#[derive(Debug, Error)]
47pub enum PublishError {
48    /// Transient failure — safe to retry.
49    #[error("transient publish error: {0}")]
50    Transient(String),
51
52    /// Permanent failure — do not retry.
53    #[error("permanent publish error: {0}")]
54    Permanent(String),
55}
56
57impl PublishError {
58    #[must_use]
59    pub fn is_transient(&self) -> bool {
60        matches!(self, Self::Transient(_))
61    }
62
63    #[must_use]
64    pub fn is_permanent(&self) -> bool {
65        matches!(self, Self::Permanent(_))
66    }
67}