mf_state/
error.rs

1use anyhow::Result;
2
3/// A type alias for Result that uses anyhow::Error as the error type.
4pub type StateResult<T> = Result<T>;
5
6/// Helper functions for creating common error types
7#[allow(clippy::module_inception)]
8pub mod error {
9    use anyhow::anyhow;
10
11    /// Creates a plugin initialization error
12    pub fn plugin_init_error(msg: impl Into<String>) -> anyhow::Error {
13        anyhow!("插件状态初始化失败: {}", msg.into())
14    }
15
16    /// Creates a plugin apply error
17    pub fn plugin_apply_error(msg: impl Into<String>) -> anyhow::Error {
18        anyhow!("插件状态应用失败: {}", msg.into())
19    }
20
21    /// Creates a transaction error
22    pub fn transaction_error(msg: impl Into<String>) -> anyhow::Error {
23        anyhow!("事务应用失败: {}", msg.into())
24    }
25
26    /// Creates a configuration error
27    pub fn configuration_error(msg: impl Into<String>) -> anyhow::Error {
28        anyhow!("配置错误: {}", msg.into())
29    }
30
31    /// Creates a field operation error
32    pub fn field_error(msg: impl Into<String>) -> anyhow::Error {
33        anyhow!("字段操作失败: {}", msg.into())
34    }
35
36    /// Creates a schema error
37    pub fn schema_error(msg: impl Into<String>) -> anyhow::Error {
38        anyhow!("Schema错误: {}", msg.into())
39    }
40
41    /// Creates a plugin not found error
42    pub fn plugin_not_found(msg: impl Into<String>) -> anyhow::Error {
43        anyhow!("插件未找到: {}", msg.into())
44    }
45
46    /// Creates an invalid plugin state error
47    pub fn invalid_plugin_state(msg: impl Into<String>) -> anyhow::Error {
48        anyhow!("插件状态无效: {}", msg.into())
49    }
50
51    /// Creates a serialization error
52    pub fn serialize_error(msg: impl Into<String>) -> anyhow::Error {
53        anyhow!("序列化失败: {}", msg.into())
54    }
55
56    /// Creates a deserialization error
57    pub fn deserialize_error(msg: impl Into<String>) -> anyhow::Error {
58        anyhow!("反序列化失败: {}", msg.into())
59    }
60}