Skip to content

Commit

Permalink
feat: replace failure dependency by thiserror
Browse files Browse the repository at this point in the history
  • Loading branch information
iTrooz committed Oct 18, 2023
1 parent 1fb03c2 commit 7a96063
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 144 deletions.
148 changes: 24 additions & 124 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion efivar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ edition = "2018"
[dependencies]
byteorder = "1.4.3"
bitflags = "2.3.3"
failure = "0.1.8"

base64 = { version = "0.21.2", optional = true }
serde = { version = "1.0.171", optional = true }
Expand All @@ -26,6 +25,7 @@ toml = { version = "0.7.6", optional = true }
uuid = { version = "1.4.1", features = ["serde"] }
lazy_static = "1.4.0"
ntapi = "0.4.1"
thiserror = "1.0.49"

[features]
store = ["base64", "serde", "serde_derive", "toml"]
Expand Down
28 changes: 14 additions & 14 deletions efivar/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,35 @@ use std::io;
use crate::efi::Variable;

/// Describes an error returned by EFI variable operations
#[derive(Debug, Fail)]
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[fail(display = "failed to parse variable name: {}", name)]
#[error("failed to parse variable name: {}", name)]
InvalidVarName { name: String },
#[fail(display = "variable not found: {}", name)]
#[error("variable not found: {}", name)]
VarNotFound { name: Variable },
#[fail(display = "permission denied for variable: {}", name)]
#[error("permission denied for variable: {}", name)]
PermissionDenied { name: Variable },
#[fail(display = "unknown i/o error for variable: {}", name)]
#[error("unknown i/o error for variable: {}", name)]
VarUnknownError { name: Variable, error: io::Error },
#[fail(display = "base64 decoding error: {}", error)]
#[error("base64 decoding error: {}", error)]
#[cfg(feature = "store")]
Base64DecodeError { error: base64::DecodeError },
#[fail(display = "base64 decoding error: {}", error)]
#[error("base64 decoding error: {}", error)]
#[cfg(feature = "store")]
Base64DecodeSliceError { error: base64::DecodeSliceError },
#[fail(display = "unknown i/o error")]
#[error("unknown i/o error")]
UnknownIoError { error: io::Error },
#[fail(display = "unknown EFI variable flag: '{}'", flag)]
#[error("unknown EFI variable flag: '{}'", flag)]
UnknownFlag { flag: String },
#[fail(display = "failed to decode name as valid UTF-8")]
#[error("failed to decode name as valid UTF-8")]
InvalidUTF8,
#[fail(display = "buffer too small for variable: {}", name)]
#[error("buffer too small for variable: {}", name)]
BufferTooSmall { name: Variable },
#[fail(display = "failed to decode uuid: {}", error)]
#[error("failed to decode uuid: {}", error)]
UuidError { error: uuid::Error },
#[fail(display = "failed to parse variable content (invalid content)")]
#[error("failed to parse variable content (invalid content)")]
VarParseError,
#[fail(display = "failed to parse string: {}", 0)]
#[error("failed to parse string: {}", 0)]
StringParseError(crate::utils::StringParseError),
}

Expand Down
2 changes: 0 additions & 2 deletions efivar/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
#[macro_use]
extern crate bitflags;
#[macro_use]
extern crate failure;
#[macro_use]
extern crate lazy_static;
#[cfg(feature = "store")]
#[macro_use]
Expand Down
6 changes: 3 additions & 3 deletions efivar/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use byteorder::{LittleEndian, ReadBytesExt};

#[derive(Debug, Fail)]
#[derive(Debug, thiserror::Error)]
pub enum StringParseError {
/// occurs when you get an error while reading the data
#[fail(display = "Buffer read error: {}", 0)]
#[error("Buffer read error: {}", 0)]
Read(std::io::Error),
/// occurs when the bytes are not a valid UTF-16 string
#[fail(display = "Buffer parse error: {}", 0)]
#[error("Buffer parse error: {}", 0)]
Parse(std::string::FromUtf16Error),
}

Expand Down

0 comments on commit 7a96063

Please sign in to comment.