From aae29170dc7ae7a8976699c4d1f7011f9f238a06 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Fri, 15 May 2026 23:52:12 +0800 Subject: Remove thiserror dependency and implement error types manually --- Cargo.lock | 1 - Cargo.toml | 8 +++- examples/example-async/Cargo.lock | 21 --------- examples/example-basic/Cargo.lock | 21 --------- examples/example-completion/Cargo.lock | 21 --------- examples/example-dispatch-tree/Cargo.lock | 21 --------- examples/example-exit-code/Cargo.lock | 21 --------- examples/example-general-renderer/Cargo.lock | 21 --------- examples/example-picker/Cargo.lock | 21 --------- mingling_core/Cargo.toml | 1 - mingling_core/src/asset/chain/error.rs | 29 ++++++++++-- mingling_core/src/program/error.rs | 2 - mingling_core/src/program/exec/error.rs | 70 +++++++++++++++++++++------- 13 files changed, 85 insertions(+), 173 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c3c399b..f9f2ff1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -310,7 +310,6 @@ dependencies = [ "serde", "serde_json", "serde_yaml", - "thiserror", "toml", ] diff --git a/Cargo.toml b/Cargo.toml index 916fc3b..8037fd6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,20 +14,24 @@ exclude = [ [workspace.dependencies] just_fmt = "0.1.2" +just_template = "0.1.3" once_cell = "1.21.4" -thiserror = "2" + serde = { version = "1.0", features = ["derive"] } serde_json = "1" serde_yaml = "0.9" toml = "1.1.2" ron = "0.12.1" + dirs = "6" + syn = { version = "2.0", features = ["full", "visit-mut"] } quote = "1.0" proc-macro2 = "1.0" + colored = "3.1.1" tokio = { version = "1", features = ["full"] } -just_template = "0.1.3" + log = "0.4" env_logger = "0.11" diff --git a/examples/example-async/Cargo.lock b/examples/example-async/Cargo.lock index b8d51ff..d1c2abb 100644 --- a/examples/example-async/Cargo.lock +++ b/examples/example-async/Cargo.lock @@ -73,7 +73,6 @@ version = "0.1.8" dependencies = [ "just_fmt", "once_cell", - "thiserror", ] [[package]] @@ -203,26 +202,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "thiserror" -version = "2.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "2.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "tokio" version = "1.52.1" diff --git a/examples/example-basic/Cargo.lock b/examples/example-basic/Cargo.lock index 48f5240..e09c178 100644 --- a/examples/example-basic/Cargo.lock +++ b/examples/example-basic/Cargo.lock @@ -29,7 +29,6 @@ version = "0.1.8" dependencies = [ "just_fmt", "once_cell", - "thiserror", ] [[package]] @@ -78,26 +77,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "thiserror" -version = "2.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "2.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "unicode-ident" version = "1.0.24" diff --git a/examples/example-completion/Cargo.lock b/examples/example-completion/Cargo.lock index 8923a98..1bde85a 100644 --- a/examples/example-completion/Cargo.lock +++ b/examples/example-completion/Cargo.lock @@ -40,7 +40,6 @@ dependencies = [ "just_fmt", "just_template", "once_cell", - "thiserror", ] [[package]] @@ -95,26 +94,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "thiserror" -version = "2.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "2.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "unicode-ident" version = "1.0.24" diff --git a/examples/example-dispatch-tree/Cargo.lock b/examples/example-dispatch-tree/Cargo.lock index ed1c6f1..735cb8b 100644 --- a/examples/example-dispatch-tree/Cargo.lock +++ b/examples/example-dispatch-tree/Cargo.lock @@ -39,7 +39,6 @@ dependencies = [ "just_fmt", "just_template", "once_cell", - "thiserror", ] [[package]] @@ -88,26 +87,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "thiserror" -version = "2.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "2.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "unicode-ident" version = "1.0.24" diff --git a/examples/example-exit-code/Cargo.lock b/examples/example-exit-code/Cargo.lock index efe8f6e..4759650 100644 --- a/examples/example-exit-code/Cargo.lock +++ b/examples/example-exit-code/Cargo.lock @@ -29,7 +29,6 @@ version = "0.1.8" dependencies = [ "just_fmt", "once_cell", - "thiserror", ] [[package]] @@ -78,26 +77,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "thiserror" -version = "2.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "2.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "unicode-ident" version = "1.0.24" diff --git a/examples/example-general-renderer/Cargo.lock b/examples/example-general-renderer/Cargo.lock index 6808db5..213a0db 100644 --- a/examples/example-general-renderer/Cargo.lock +++ b/examples/example-general-renderer/Cargo.lock @@ -79,7 +79,6 @@ dependencies = [ "serde", "serde_json", "serde_yaml", - "thiserror", "toml", ] @@ -220,26 +219,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "thiserror" -version = "2.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "2.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "toml" version = "1.1.2+spec-1.1.0" diff --git a/examples/example-picker/Cargo.lock b/examples/example-picker/Cargo.lock index 94de2f7..95e6d96 100644 --- a/examples/example-picker/Cargo.lock +++ b/examples/example-picker/Cargo.lock @@ -31,7 +31,6 @@ version = "0.1.8" dependencies = [ "just_fmt", "once_cell", - "thiserror", ] [[package]] @@ -92,26 +91,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "thiserror" -version = "2.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "2.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "tokio" version = "1.52.1" diff --git a/mingling_core/Cargo.toml b/mingling_core/Cargo.toml index 166e0d5..118813c 100644 --- a/mingling_core/Cargo.toml +++ b/mingling_core/Cargo.toml @@ -28,7 +28,6 @@ debug = ["dep:log", "dep:env_logger"] [dependencies] just_fmt.workspace = true -thiserror.workspace = true once_cell.workspace = true dirs = { workspace = true, optional = true } diff --git a/mingling_core/src/asset/chain/error.rs b/mingling_core/src/asset/chain/error.rs index e5c753d..39e4f62 100644 --- a/mingling_core/src/asset/chain/error.rs +++ b/mingling_core/src/asset/chain/error.rs @@ -1,12 +1,33 @@ use crate::error::ProgramInternalExecuteError; -#[derive(thiserror::Error, Debug)] +#[derive(Debug)] pub enum ChainProcessError { - #[error("Other error: {0}")] Other(String), + IO(std::io::Error), +} + +impl std::fmt::Display for ChainProcessError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + ChainProcessError::Other(s) => write!(f, "Other error: {}", s), + ChainProcessError::IO(e) => write!(f, "IO error: {}", e), + } + } +} - #[error("IO error: {0}")] - IO(#[from] std::io::Error), +impl std::error::Error for ChainProcessError { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + match self { + ChainProcessError::IO(e) => Some(e), + ChainProcessError::Other(_) => None, + } + } +} + +impl From for ChainProcessError { + fn from(e: std::io::Error) -> Self { + ChainProcessError::IO(e) + } } impl From for ChainProcessError { diff --git a/mingling_core/src/program/error.rs b/mingling_core/src/program/error.rs index a6874cf..03e9af6 100644 --- a/mingling_core/src/program/error.rs +++ b/mingling_core/src/program/error.rs @@ -1,9 +1,7 @@ use std::any::Any; use std::fmt; -use thiserror::Error; /// Error type returned when a panic occurs during execution. -#[derive(Error)] pub struct ProgramPanic { pub payload: Box, } diff --git a/mingling_core/src/program/exec/error.rs b/mingling_core/src/program/exec/error.rs index 2d806dc..2790a7b 100644 --- a/mingling_core/src/program/exec/error.rs +++ b/mingling_core/src/program/exec/error.rs @@ -1,33 +1,71 @@ use crate::error::{ChainProcessError, ProgramPanic}; +use std::fmt; -#[derive(thiserror::Error, Debug)] +#[derive(Debug)] pub enum ProgramExecuteError { - #[error("No Dispatcher Found")] DispatcherNotFound, - - #[error("No Renderer (`{0}`) Found")] RendererNotFound(String), + Panic(ProgramPanic), + Other(String), +} - #[error("Panic: {0:?}")] - Panic(#[from] ProgramPanic), +impl fmt::Display for ProgramExecuteError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + ProgramExecuteError::DispatcherNotFound => write!(f, "No Dispatcher Found"), + ProgramExecuteError::RendererNotFound(s) => { + write!(f, "No Renderer (`{}`) Found", s) + } + ProgramExecuteError::Panic(p) => write!(f, "Panic: {:?}", p), + ProgramExecuteError::Other(s) => write!(f, "Other error: {}", s), + } + } +} - #[error("Other error: {0}")] - Other(String), +impl std::error::Error for ProgramExecuteError {} + +impl From for ProgramExecuteError { + fn from(value: ProgramPanic) -> Self { + ProgramExecuteError::Panic(value) + } } -#[derive(thiserror::Error, Debug)] +#[derive(Debug)] pub enum ProgramInternalExecuteError { - #[error("No Dispatcher Found")] DispatcherNotFound, - - #[error("No Renderer (`{0}`) Found")] RendererNotFound(String), - - #[error("Other error: {0}")] Other(String), + IO(std::io::Error), +} - #[error("IO error: {0}")] - IO(#[from] std::io::Error), +impl fmt::Display for ProgramInternalExecuteError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + ProgramInternalExecuteError::DispatcherNotFound => { + write!(f, "No Dispatcher Found") + } + ProgramInternalExecuteError::RendererNotFound(s) => { + write!(f, "No Renderer (`{}`) Found", s) + } + ProgramInternalExecuteError::Other(s) => write!(f, "Other error: {}", s), + ProgramInternalExecuteError::IO(e) => write!(f, "IO error: {}", e), + } + } +} + +impl std::error::Error for ProgramInternalExecuteError { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + match self { + ProgramInternalExecuteError::IO(e) => Some(e), + _ => None, + } + } +} + +impl From for ProgramInternalExecuteError { + fn from(e: std::io::Error) -> Self { + ProgramInternalExecuteError::IO(e) + } } impl From for ProgramExecuteError { -- cgit