aboutsummaryrefslogtreecommitdiff
path: root/mingling_core
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-05-15 23:52:12 +0800
committer魏曹先生 <1992414357@qq.com>2026-05-15 23:52:12 +0800
commitaae29170dc7ae7a8976699c4d1f7011f9f238a06 (patch)
treeb15e73d4b73b23ed41df555f962cbcdfd2b254ad /mingling_core
parentde448a04dc594f0938210abaa12de0e168f5741a (diff)
Remove thiserror dependency and implement error types manually
Diffstat (limited to 'mingling_core')
-rw-r--r--mingling_core/Cargo.toml1
-rw-r--r--mingling_core/src/asset/chain/error.rs29
-rw-r--r--mingling_core/src/program/error.rs2
-rw-r--r--mingling_core/src/program/exec/error.rs70
4 files changed, 79 insertions, 23 deletions
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<std::io::Error> for ChainProcessError {
+ fn from(e: std::io::Error) -> Self {
+ ChainProcessError::IO(e)
+ }
}
impl From<ProgramInternalExecuteError> 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<dyn Any + Send>,
}
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<ProgramPanic> 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<std::io::Error> for ProgramInternalExecuteError {
+ fn from(e: std::io::Error) -> Self {
+ ProgramInternalExecuteError::IO(e)
+ }
}
impl From<ProgramInternalExecuteError> for ProgramExecuteError {