gaia_types/errors/
display.rs1use super::*;
2
3impl Error for GaiaError {}
7
8impl Debug for GaiaError {
12 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
13 Debug::fmt(&self.kind, f)
14 }
15}
16
17impl Display for GaiaError {
21 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
22 Display::fmt(&self.kind, f)
23 }
24}
25
26impl Display for GaiaErrorKind {
30 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
31 match self {
32 GaiaErrorKind::InvalidInstruction { instruction, architecture } => {
33 write!(f, "无效指令 '{}' 在架构 '{}'", instruction, architecture)?;
34 }
35 GaiaErrorKind::UnsupportedArchitecture { architecture } => {
36 write!(f, "不支持的架构: {}", architecture)?;
37 }
38 GaiaErrorKind::InvalidRange { length, expect } => {
39 write!(f, "无效范围: 实际长度 {},期望长度 {}", length, expect)?;
40 }
41 GaiaErrorKind::SyntaxError { message, location } => {
42 write!(f, "语法错误在 {:?}: {}", location.url, message)?;
43 }
44 GaiaErrorKind::IoError { io_error, url } => {
45 if let Some(url) = url {
46 write!(f, "IO错误在 {}: {}", url, io_error)?;
47 }
48 else {
49 write!(f, "IO错误: {}", io_error)?;
50 }
51 }
52 GaiaErrorKind::StageError { location } => {
53 write!(f, "阶段错误在 {:?}", location)?;
54 }
55 GaiaErrorKind::NotImplemented { feature } => {
56 write!(f, "功能未实现: {}", feature)?;
57 }
58 GaiaErrorKind::CustomError { message } => {
59 write!(f, "自定义错误: {}", message)?;
60 }
61 GaiaErrorKind::AdapterError { adapter_name, message, source } => {
62 write!(f, "适配器错误 [{}]: {}", adapter_name, message)?;
63 if let Some(source) = source {
64 write!(f, " (源错误: {})", source)?;
65 }
66 }
67 GaiaErrorKind::PlatformUnsupported { platform, operation } => {
68 write!(f, "平台 '{}' 不支持操作: {}", platform, operation)?;
69 }
70 GaiaErrorKind::ConfigError { config_path, message } => {
71 if let Some(path) = config_path {
72 write!(f, "配置错误在 '{}': {}", path, message)?;
73 }
74 else {
75 write!(f, "配置错误: {}", message)?;
76 }
77 }
78 GaiaErrorKind::UnsupportedTarget { target } => {
79 write!(f, "不支持的编译目标: {:?}", target)?;
80 }
81 GaiaErrorKind::CompilationFailed { target, message } => {
82 write!(f, "编译失败 (目标: {:?}): {}", target, message)?;
83 }
84 GaiaErrorKind::SaveError { format, message } => {
85 write!(f, "保存错误 (格式: {}): {}", format, message)?;
86 }
87 GaiaErrorKind::UnsupportedFeature { feature, location } => {
88 write!(f, "不支持的功能 '{}' 在位置 {:?}", feature, location)?;
89 }
90 GaiaErrorKind::UnreachableError { location } => {
91 write!(f, "不可达错误: {}", location)?;
92 }
93 }
94 Ok(())
95 }
96}