From dfe1f20a7cbd077a01a8142332027548d31b01f9 Mon Sep 17 00:00:00 2001 From: Philippe GASSMANN Date: Tue, 23 Jan 2024 09:47:21 +0100 Subject: [PATCH] Implement Error trait for Error struct (with the help of thiserror) --- Cargo.lock | 3 ++- Cargo.toml | 1 + src/lib.rs | 30 ++++++++---------------------- 3 files changed, 11 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dc5112d..0964284 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -413,11 +413,12 @@ checksum = "604178f6c5c21f02dc555784810edfb88d34ac2c73b2eae109655649ee73ce3d" [[package]] name = "bdt" -version = "0.15.0" +version = "0.17.0" dependencies = [ "comfy-table 6.2.0", "datafusion", "structopt", + "thiserror", "tokio", ] diff --git a/Cargo.toml b/Cargo.toml index 3ac0d3f..81aaf97 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,3 +22,4 @@ comfy-table = "6.1.2" datafusion = { version = "33.0", features = ["avro"] } structopt = "0.3" tokio = "1.19" +thiserror = "1" diff --git a/src/lib.rs b/src/lib.rs index 846e8d9..6501374 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,30 +6,16 @@ pub mod convert; pub mod parquet; pub mod utils; -#[derive(Debug)] +#[derive(Debug, thiserror::Error)] pub enum Error { + #[error("{0}")] General(String), - DataFusion(DataFusionError), - Parquet(ParquetError), - IoError(std::io::Error), -} - -impl From for Error { - fn from(e: DataFusionError) -> Self { - Self::DataFusion(e) - } -} - -impl From for Error { - fn from(e: ParquetError) -> Self { - Self::Parquet(e) - } -} - -impl From for Error { - fn from(e: std::io::Error) -> Self { - Self::IoError(e) - } + #[error("Data Fusion error: {0}")] + DataFusion(#[from] DataFusionError), + #[error("Parquet error: {0}")] + Parquet(#[from] ParquetError), + #[error("I/O error: {0}")] + IoError(#[from] std::io::Error), } #[derive(Debug)]