-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use thiserror for error handling (#51)
* Use thiserror for error handling * Prepare release
- Loading branch information
1 parent
737bded
commit faa8a2f
Showing
10 changed files
with
66 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "vegas-lattice" | ||
version = "0.6.0" | ||
version = "0.7.0" | ||
authors = ["Oscar David Arbeláez Echeverri <[email protected]>"] | ||
description = "CLI and library to work with lattices" | ||
documentation = "https://docs.rs/vegas-lattice" | ||
|
@@ -12,14 +12,10 @@ categories = ["command-line-utilities", "science", "simulation"] | |
license-file = "LICENSE.txt" | ||
edition = "2021" | ||
|
||
[badges] | ||
is-it-maintained-issue-resolution = { repository = "odarbelaeze/vegas-lattice-rs" } | ||
is-it-maintained-open-issues = { repository = "odarbelaeze/vegas-lattice-rs" } | ||
maintenance = { status = "actively-developed" } | ||
|
||
[dependencies] | ||
serde_json = "1.0" | ||
serde = { version = "1.0", features = ["derive"] } | ||
image = "0.24" | ||
rand = "0.8" | ||
clap = { version = "4.5.16", features = ["cargo"] } | ||
thiserror = "1.0.63" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,23 @@ | ||
//! Error handling for the lattice crate | ||
//! Error handling for the vegas lattice crate | ||
|
||
use serde_json::Error as SerdeError; | ||
use std::error::Error as StdError; | ||
use std::fmt; | ||
use std::io::Error as IoError; | ||
|
||
/// Error type for the lattice crate | ||
#[derive(Debug)] | ||
pub enum LatticeError { | ||
IoError(IoError), | ||
JsonParseError(SerdeError), | ||
ImageReadError(image::ImageError), | ||
use thiserror::Error; | ||
|
||
/// Error type for the vegas lattice crate | ||
#[derive(Error, Debug)] | ||
pub enum VegasLatticeError { | ||
#[error("IO error: {0}")] | ||
IoError(#[from] IoError), | ||
#[error("serialization error: {0}")] | ||
SerializationError(#[from] SerdeError), | ||
#[error("Formatter error: {0}")] | ||
ImageReadError(#[from] image::ImageError), | ||
#[error("inconsistent vertices")] | ||
InconsistentVertices, | ||
#[error("negative size")] | ||
NegativeSize, | ||
} | ||
|
||
impl StdError for LatticeError { | ||
fn description(&self) -> &str { | ||
match self { | ||
LatticeError::IoError(_) => "There was an error reading your file", | ||
LatticeError::JsonParseError(_) => "There was a problem parsing json", | ||
LatticeError::ImageReadError(_) => "There was a problem reading the image", | ||
LatticeError::InconsistentVertices => "These vertices are inconsistent", | ||
LatticeError::NegativeSize => "What are you up to don't give me a negative size", | ||
} | ||
} | ||
|
||
fn cause(&self) -> Option<&dyn StdError> { | ||
match self { | ||
LatticeError::IoError(err) => Some(err), | ||
LatticeError::JsonParseError(err) => Some(err), | ||
_ => None, | ||
} | ||
} | ||
} | ||
|
||
impl fmt::Display for LatticeError { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
match *self { | ||
LatticeError::IoError(_) => f.write_str("IoError"), | ||
LatticeError::JsonParseError(_) => f.write_str("JsonParseError"), | ||
LatticeError::ImageReadError(_) => f.write_str("ImageReadError"), | ||
LatticeError::InconsistentVertices => f.write_str("InconsistentVertices"), | ||
LatticeError::NegativeSize => f.write_str("NegativeSize"), | ||
} | ||
} | ||
} | ||
|
||
impl From<SerdeError> for LatticeError { | ||
fn from(err: SerdeError) -> Self { | ||
LatticeError::JsonParseError(err) | ||
} | ||
} | ||
|
||
impl From<IoError> for LatticeError { | ||
fn from(err: IoError) -> Self { | ||
LatticeError::IoError(err) | ||
} | ||
} | ||
|
||
impl From<image::ImageError> for LatticeError { | ||
fn from(err: image::ImageError) -> Self { | ||
LatticeError::ImageReadError(err) | ||
} | ||
} | ||
/// Result type for the vegas lattice crate | ||
pub type Result<T> = std::result::Result<T, VegasLatticeError>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters