1use anyhow::{Result};
2pub type ForgeResult<T> = Result<T>;
4
5pub mod error_utils {
7 use super::*;
8
9 pub fn map_error<T, E: std::error::Error>(
11 result: Result<T, E>,
12 context: &str,
13 ) -> ForgeResult<T> {
14 result.map_err(|e| {
15 anyhow::anyhow!(format!("未知的错误 {}: {}", context, e))
16 })
17 }
18
19 pub fn state_error(msg: impl Into<String>) -> anyhow::Error {
21 anyhow::anyhow!(format!("状态错误 {:?}", msg.into()))
22 }
23
24 pub fn storage_error(msg: impl Into<String>) -> anyhow::Error {
26 anyhow::anyhow!(format!("存储相关错误 {:?}", msg.into()))
27 }
28
29 pub fn event_error(msg: impl Into<String>) -> anyhow::Error {
31 anyhow::anyhow!(format!("事件处理错误 {:?}", msg.into()))
32 }
33
34 pub fn plugin_error(msg: impl Into<String>) -> anyhow::Error {
36 anyhow::anyhow!(format!("插件相关错误 {:?}", msg.into()))
37 }
38
39 pub fn config_error(msg: impl Into<String>) -> anyhow::Error {
41 anyhow::anyhow!(format!("配置错误 {:?}", msg.into()))
42 }
43
44 pub fn transaction_error(msg: impl Into<String>) -> anyhow::Error {
46 anyhow::anyhow!(format!(" 事务处理错误 {:?}", msg.into()))
47 }
48
49 pub fn history_error(msg: impl Into<String>) -> anyhow::Error {
51 anyhow::anyhow!(format!(" 历史记录错误 {:?}", msg.into()))
52 }
53
54 pub fn engine_error(msg: impl Into<String>) -> anyhow::Error {
56 anyhow::anyhow!(format!(" 引擎错误 {:?}", msg.into()))
57 }
58
59 pub fn cache_error(msg: impl Into<String>) -> anyhow::Error {
61 anyhow::anyhow!(format!(" 缓存错误 {:?}", msg.into()))
62 }
63
64 pub fn middleware_error(msg: impl Into<String>) -> anyhow::Error {
66 anyhow::anyhow!(format!(" 中间件错误 {:?}", msg.into()))
67 }
68}