Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
50 changes: 36 additions & 14 deletions src/sys/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use thiserror::Error;

mod macros;

#[allow(dead_code)]
Expand Down Expand Up @@ -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<MetadataError> 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<dyn std::error::Error + Send + Sync>,
},
}

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 {
Expand Down
Loading