diff --git a/Cargo.toml b/Cargo.toml index ffe96fe..897b624 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,6 @@ humantime = "2.1.0" http = "1" http-body = "1" http-body-util = "0.1.0" -thiserror = "=0.0.1" autoerr = "0.0.3" chrono = { version = "0.4.38", features = ["serde"] } wasmer = { version = "5.0.1", default-features = false, features = ["sys", "cranelift"], optional = true } @@ -41,6 +40,3 @@ tokio = { version = "1", features = ["rt"] } wasm_transform = ["wasmer"] indev = [] tests-runtime = [] - -[patch.crates-io] -thiserror = { git = "https://github.com/dominikwerder/thiserror.git", branch = "cstm" } diff --git a/src/cbor_stream.rs b/src/cbor_stream.rs index 67cad49..1bc5f02 100644 --- a/src/cbor_stream.rs +++ b/src/cbor_stream.rs @@ -28,14 +28,15 @@ use std::time::Duration; const FRAME_HEAD_LEN: usize = 16; const FRAME_PAYLOAD_MAX: u32 = 1024 * 1024 * 80; -#[derive(Debug, thiserror::Error)] -#[cstm(name = "CborStream")] -pub enum Error { - FromSlice(#[from] std::array::TryFromSliceError), - Msg(String), - Ciborium(#[from] ciborium::de::Error), - CiboriumValue(#[from] ciborium::value::Error), -} +autoerr::create_error_v1!( + name(Error, "CborStream"), + enum variants { + FromSlice(#[from] std::array::TryFromSliceError), + Msg(String), + Ciborium(#[from] ciborium::de::Error), + CiboriumValue(#[from] ciborium::value::Error), + }, +); struct ErrMsg(E) where @@ -176,7 +177,7 @@ impl FramedBytesToChannelEventsStream { let n = u32::from_le_bytes(self.buf[..4].try_into()?); if n > FRAME_PAYLOAD_MAX { let e = ErrMsg(format!("frame too large {n}")).into(); - error!("{e}"); + error!("{}", e); return Err(e); } let frame_len = FRAME_HEAD_LEN + n as usize; diff --git a/src/frames.rs b/src/frames.rs index 36c469f..3933c3e 100644 --- a/src/frames.rs +++ b/src/frames.rs @@ -7,11 +7,12 @@ use futures_util::Stream; use futures_util::StreamExt; use items_2::framable::Framable; -#[derive(Debug, thiserror::Error)] -#[cstm(name = "FramedStreamError")] -pub enum Error { - MakeFrame(#[from] items_2::framable::Error), -} +autoerr::create_error_v1!( + name(Error, "FramedStreamError"), + enum variants { + MakeFrame(#[from] items_2::framable::Error), + }, +); pub fn frameable_stream_to_bytes_stream(stream: S) -> impl Stream> where diff --git a/src/frames/eventsfromframes.rs b/src/frames/eventsfromframes.rs index 28bfa5b..74e7236 100644 --- a/src/frames/eventsfromframes.rs +++ b/src/frames/eventsfromframes.rs @@ -14,10 +14,6 @@ use std::pin::Pin; use std::task::Context; use std::task::Poll; -#[derive(Debug, thiserror::Error)] -#[cstm(name = "FromFrames")] -pub enum Error {} - pub struct EventsFromFrames { inp: INP, dbgdesc: String, diff --git a/src/generators.rs b/src/generators.rs index 1c1ee15..1a039b2 100644 --- a/src/generators.rs +++ b/src/generators.rs @@ -26,13 +26,14 @@ use std::pin::Pin; use std::task::Context; use std::task::Poll; -#[derive(Debug, thiserror::Error)] -#[cstm(name = "Generator")] -pub enum Error { - UnsupportedIsEventBlobs, - Items2(#[from] items_2::Error), - BadChannelName, -} +autoerr::create_error_v1!( + name(Error, "Generator"), + enum variants { + UnsupportedIsEventBlobs, + Items2(#[from] items_2::Error), + BadChannelName, + }, +); fn make_sleep_fut() -> Pin + Send>> { todo!() @@ -45,7 +46,7 @@ pub fn make_test_channel_events_bytes_stream( ) -> Result { if subq.is_event_blobs() { let e = Error::UnsupportedIsEventBlobs; - error!("{e}"); + error!("{}", e); Err(e) } else { let stream = make_test_channel_events_stream_data(subq, node_count, node_ix)?; diff --git a/src/itemclone.rs b/src/itemclone.rs index 1b3055c..6ae9794 100644 --- a/src/itemclone.rs +++ b/src/itemclone.rs @@ -6,9 +6,12 @@ use std::pin::Pin; use std::task::Context; use std::task::Poll; -#[derive(Debug, thiserror::Error)] -#[cstm(name = "ItemClone")] -pub enum Error {} +autoerr::create_error_v1!( + name(Error, "ItemClone"), + enum variants { + Dummy, + }, +); #[pin_project::pin_project] pub struct Itemclone<'a, T, INP> diff --git a/src/json_stream.rs b/src/json_stream.rs index a8ad3eb..629c7c4 100644 --- a/src/json_stream.rs +++ b/src/json_stream.rs @@ -12,12 +12,13 @@ use netpod::log::*; use std::pin::Pin; use std::time::Duration; -#[derive(Debug, thiserror::Error)] -#[cstm(name = "JsonStream")] -pub enum Error { - Json(#[from] serde_json::Error), - Msg(String), -} +autoerr::create_error_v1!( + name(Error, "JsonStream"), + enum variants { + Json(#[from] serde_json::Error), + Msg(String), + }, +); pub struct ErrMsg(pub E) where diff --git a/src/needminbuffer.rs b/src/needminbuffer.rs index 330ada7..53e9896 100644 --- a/src/needminbuffer.rs +++ b/src/needminbuffer.rs @@ -7,9 +7,12 @@ use std::pin::Pin; use std::task::Context; use std::task::Poll; -#[derive(Debug, thiserror::Error)] -#[cstm(name = "NeedMinBuffer")] -pub enum Error {} +autoerr::create_error_v1!( + name(Error, "NeedMinBuffer"), + enum variants { + Dummy, + }, +); pub struct NeedMinBuffer { inp: Pin> + Send>>, diff --git a/src/tcprawclient.rs b/src/tcprawclient.rs index eea9a56..49a0321 100644 --- a/src/tcprawclient.rs +++ b/src/tcprawclient.rs @@ -36,18 +36,32 @@ use std::sync::Arc; pub const TEST_BACKEND: &str = "testbackend-00"; -#[derive(Debug, thiserror::Error)] -#[cstm(name = "TcpRawClient")] -pub enum Error { - IO(#[from] std::io::Error), - Msg(String), - Frame(#[from] items_2::frame::Error), - Framable(#[from] items_2::framable::Error), - Json(#[from] serde_json::Error), - Http(#[from] http::Error), - #[error("ServerError({0:?}, {1})")] - ServerError(http::response::Parts, String), - HttpBody(Box), +autoerr::create_error_v1!( + name(Error, "TcpRawClient"), + enum variants { + IO(#[from] std::io::Error), + Msg(String), + Frame(#[from] items_2::frame::Error), + Framable(#[from] items_2::framable::Error), + Json(#[from] serde_json::Error), + Http(#[from] http::Error), + ServerError(DisplayDebug, String), + // ServerError(http::response::Parts, String), + HttpBody(Box), + }, +); + +struct DisplayDebug(T); + +impl fmt::Debug for DisplayDebug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.0, fmt) + } +} +impl fmt::Display for DisplayDebug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.0, fmt) + } } struct ErrMsg(E) @@ -86,11 +100,12 @@ pub fn make_node_command_frame(query: EventsSubQuery) -> Result ( if false { debug!($($arg)*); } ) } +macro_rules! debug_first { ($($arg:expr),*) => ( if false { debug!($($arg),*); } ) } -macro_rules! trace2 { ($($arg:tt)*) => ( if false { trace!($($arg)*); } ) } +macro_rules! trace2 { ($($arg:expr),*) => ( if false { trace!($($arg),*); } ) } -macro_rules! trace3 { ($($arg:tt)*) => ( if false { trace!($($arg)*); } ) } +macro_rules! trace3 { ($($arg:expr),*) => ( if false { trace!($($arg),*); } ) } -#[derive(Debug, thiserror::Error)] -#[cstm(name = "TimeBinnedStream")] -pub enum Error { - MissingBinnerAfterProcessItem, - CreateEmpty, - NoBinnerAfterInputDone, - Msg(String), -} +autoerr::create_error_v1!( + name(Error, "TimeBinnedStream"), + enum variants { + MissingBinnerAfterProcessItem, + CreateEmpty, + NoBinnerAfterInputDone, + Msg(String), + }, +); type SitemtyStream = Pin> + Send>>; @@ -134,7 +135,7 @@ where Ok(Break(Ready(sitem_data(bins)))) } else { let e = Error::CreateEmpty; - error!("{e}"); + error!("{}", e); Err(e) } }