mirror of
https://github.com/hexedtech/codemp.git
synced 2024-12-23 05:14:54 +01:00
chore: migrate errors to thiserror
This commit is contained in:
parent
95ece68ae6
commit
e85833a40f
2 changed files with 13 additions and 22 deletions
11
Cargo.toml
11
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"]
|
||||
|
|
|
@ -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<T> = StdResult<T, Error>;
|
|||
|
||||
// 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<tonic::Status> for Error {
|
||||
|
|
Loading…
Reference in a new issue