Skip to content

Commit

Permalink
Remove thiserror (extracted from #64) (#70)
Browse files Browse the repository at this point in the history
Remove the thiserror crate and replace with the same code that would be
generated.

This change was authored by @overcat in #64, and has been extracted to commit
separately.

Co-authored-by: Jun Luo <[email protected]>
  • Loading branch information
leighmcculloch and overcat authored Sep 10, 2024
1 parent 63a1d5e commit 00c7df7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = "Apache-2.0"
readme = "README.md"
version = "0.0.10"
edition = "2021"
rust-version = "1.67.0"
rust-version = "1.81.0"

[features]
default = []
Expand All @@ -28,5 +28,4 @@ proptest = "1.0.0"

[dependencies]
data-encoding = "2.6.0"
thiserror = "1.0.36"
clap = { version = "4.2.4", default-features = false, features = ["std", "derive", "usage", "help"], optional = true }
13 changes: 11 additions & 2 deletions src/bin/stellar-strkey/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@ use std::str::FromStr;
use clap::Args;
use stellar_strkey::DecodeError;

#[derive(thiserror::Error, Debug)]
#[derive(Debug)]
pub enum Error {
#[error("decoding {0:?}: {1}")]
Decode(String, DecodeError),
}

impl core::fmt::Display for Error {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
match self {
Error::Decode(s, inner) => f.write_fmt(format_args!("decoding {s:?}: {inner}")),
}
}
}

impl core::error::Error for Error {}

#[derive(Args, Debug, Clone)]
#[command()]
pub struct Cmd {
Expand Down
13 changes: 11 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
#[derive(thiserror::Error, Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
pub enum DecodeError {
// TODO: Add meaningful errors for each problem that can occur.
#[error("the strkey is invalid")]
Invalid,
}

impl core::fmt::Display for DecodeError {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
match self {
DecodeError::Invalid {} => f.write_str("the strkey is invalid"),
}
}
}

impl core::error::Error for DecodeError {}

0 comments on commit 00c7df7

Please sign in to comment.