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