Skip to content

Commit 0353682

Browse files
committed
Remove the use of anyhow in EncodeError
Changed `EncodeError` from `struct` to `enum` and remove the use of anyhow but using thiserror instead. Signed-off-by: Gris Ge <[email protected]>
1 parent 414d14e commit 0353682

File tree

2 files changed

+9
-19
lines changed

2 files changed

+9
-19
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ readme = "README.md"
1111

1212

1313
[dependencies]
14-
anyhow = "1.0.31"
1514
byteorder = "1.3.2"
1615
pastey = "0.1.0"
1716
thiserror = "2"

src/errors.rs

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,24 @@
11
// SPDX-License-Identifier: MIT
22

3-
use anyhow::anyhow;
43
use thiserror::Error;
54

65
#[derive(Debug, Error)]
7-
#[error("Encode error occurred: {inner}")]
8-
pub struct EncodeError {
9-
inner: anyhow::Error,
6+
pub enum EncodeError {
7+
#[error(transparent)]
8+
Other(#[from] Box<dyn std::error::Error>),
109
}
1110

12-
impl From<&'static str> for EncodeError {
13-
fn from(msg: &'static str) -> Self {
14-
EncodeError {
15-
inner: anyhow!(msg),
16-
}
11+
impl From<&str> for EncodeError {
12+
fn from(msg: &str) -> Self {
13+
let error: Box<dyn std::error::Error> = msg.to_string().into();
14+
EncodeError::Other(error)
1715
}
1816
}
1917

2018
impl From<String> for EncodeError {
2119
fn from(msg: String) -> Self {
22-
EncodeError {
23-
inner: anyhow!(msg),
24-
}
25-
}
26-
}
27-
28-
impl From<anyhow::Error> for EncodeError {
29-
fn from(inner: anyhow::Error) -> EncodeError {
30-
EncodeError { inner }
20+
let error: Box<dyn std::error::Error> = msg.into();
21+
EncodeError::Other(error)
3122
}
3223
}
3324

0 commit comments

Comments
 (0)