diff --git a/Cargo.lock b/Cargo.lock index 92169d96..1a6be9b8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -618,26 +618,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "thiserror" -version = "1.0.61" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.61" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "tskit" version = "0.15.0-alpha.3" @@ -656,7 +636,6 @@ dependencies = [ "serde-pickle", "serde_json", "streaming-iterator", - "thiserror", "tskit-derive", ] diff --git a/Cargo.toml b/Cargo.toml index a43a771d..14ed5dd5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,6 @@ lto = "fat" codegen-units=1 [dependencies] -thiserror = "1.0" libc = "0.2.155" streaming-iterator = "0.1.5" serde = {version = "1.0.203", features = ["derive"], optional = true} diff --git a/src/sys/mod.rs b/src/sys/mod.rs index f508f090..89ef5fb6 100644 --- a/src/sys/mod.rs +++ b/src/sys/mod.rs @@ -1,5 +1,3 @@ -use thiserror::Error; - mod macros; #[allow(dead_code)] @@ -47,52 +45,76 @@ pub use treeseq::TreeSequence; use traits::TskTeardown; -#[derive(Error, Debug)] #[non_exhaustive] +#[derive(Debug)] pub enum TskitError { /// Returned when conversion attempts fail - #[error("range error: {}", *.0)] RangeError(String), /// Used when bad input is encountered. - #[error("we received {} but expected {}",*got, *expected)] ValueError { got: String, expected: String }, /// Used when array access is out of range. /// Typically, this is used when accessing /// arrays allocated on the C side. - #[error("Invalid index")] IndexError, /// Raised when samples are requested from /// [`crate::Tree`] objects, but sample lists are /// not being updated. - #[error("Not tracking samples in Trees")] NotTrackingSamples, /// Wrapper around tskit C API error codes. - #[error("{}", get_tskit_error_message(*code))] ErrorCode { code: i32 }, /// A redirection of [``crate::metadata::MetadataError``] - #[error("{value:?}")] MetadataError { /// The redirected error - #[from] value: MetadataError, }, /// General error variant - #[error("{}", *.0)] LibraryError(String), } -#[derive(Error, Debug)] +impl std::fmt::Display for TskitError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Self::RangeError(msg) => write!(f, "range error: {}", msg), + Self::ValueError { got, expected } => { + write!(f, "we received {} but expected {}", got, expected) + } + Self::IndexError => write!(f, "Invalid index"), + Self::NotTrackingSamples => write!(f, "Not tracking samples in Trees"), + Self::ErrorCode { code } => write!(f, "{}", get_tskit_error_message(*code)), + Self::MetadataError { value } => write!(f, "meta data error: {}", value), + Self::LibraryError(msg) => write!(f, "library error: {msg}"), + } + } +} + +impl From for TskitError { + fn from(value: MetadataError) -> Self { + Self::MetadataError { value } + } +} + +impl std::error::Error for TskitError {} + +#[derive(Debug)] #[non_exhaustive] pub enum MetadataError { /// Error related to types implementing /// metadata serialization. - #[error("{}", *value)] RoundtripError { - #[from] value: Box, }, } +impl std::fmt::Display for MetadataError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Self::RoundtripError { value } => write!(f, "metadata round trip error: {value:?}"), + } + } +} + +impl std::error::Error for MetadataError {} + //#[non_exhaustive] //#[derive(Error, Debug)] //pub enum Error {