diff --git a/Cargo.toml b/Cargo.toml index c5f1c91..d6b38ad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ crate-type = ["cdylib"] [dependencies] # core tracing = "0.1" +thiserror = { version = "1.0.57" } # woot codemp-woot = { git = "ssh://git@github.com/hexedtech/woot.git", features = ["serde"], tag = "v0.1.2" } # proto @@ -34,13 +35,9 @@ tracing-subscriber = { version = "0.3.18", optional = true } # glue (java) jni = { version = "0.21.1", features = ["invocation"], optional = true } -jni-sys = { version = "0.3.0", optional = true } -rifgen = { git = "https://github.com/Kofituo/rifgen.git", rev = "d27d9785b2febcf5527f1deb6a846be5d583f7d7", optional = true } -log = { version = "0.4.21", optional = true } - +#jni-sys = { version = "0.3.0", optional = true } # glue (lua) mlua = { version = "0.9.6", features = ["module", "luajit", "send"], optional = true } -thiserror = { version = "1.0.57", optional = true } derive_more = { version = "0.99.17", optional = true } # glue (js) @@ -64,8 +61,8 @@ pyo3-build-config = { version = "0.19.2", optional = true } [features] default = [] -lua = ["mlua", "thiserror", "derive_more", "lazy_static", "tracing-subscriber"] -java = ["lazy_static", "jni", "jni-sys", "flapigen", "rifgen", "log"] +lua = ["mlua", "derive_more", "lazy_static", "tracing-subscriber"] +java = ["lazy_static", "jni", "tracing-subscriber"] java-artifact = ["java"] # also builds the jar js = ["napi-build", "tracing-subscriber", "rmpv", "napi", "napi-derive", "futures"] python = ["pyo3", "pyo3-asyncio", "tracing-subscriber", "pyo3-build-config"] diff --git a/src/errors.rs b/src/errors.rs index 4668c24..e792dd3 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -2,7 +2,7 @@ //! //! library error helpers and types -use std::{result::Result as StdResult, error::Error as StdError, fmt::Display}; +use std::result::Result as StdResult; use tracing::warn; @@ -45,36 +45,30 @@ pub type Result = StdResult; // TODO split this into specific errors for various parts of the library /// codemp error type for library issues -#[derive(Debug)] +#[derive(Debug, thiserror::Error)] pub enum Error { /// errors caused by tonic http layer + #[error("tonic error (status: {status}, message: {message})")] Transport { status: String, message: String, }, + /// errors caused by async channels + #[error("channel error, send: {send}")] Channel { send: bool }, + /// errors caused by wrong usage of library objects + #[error("invalid state error: {msg}")] InvalidState { msg: String, }, /// errors caused by wrong interlocking, safe to retry - Deadlocked, -} - -impl StdError for Error {} - -impl Display for Error { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - Self::Transport { status, message } => write!(f, "Transport error: ({}) {}", status, message), - Self::Channel { send } => write!(f, "Channel error (send:{})", send), - _ => write!(f, "Unknown error"), - } - } + #[error("deadlocked error")] + Deadlocked } impl From for Error {