Skip to content

Commit 75eae87

Browse files
dignifiedquirerklaehnmatheus23ramfox“ramfox”
authored
feat!: concrete errors (#3161)
## Description Fixes #2741 Uses `snafu` to create concrete errors with backtracing. We no longer use `anyhow` in our APIs, all errors returned from API functions and methods are concrete. We also use `n0-snafu` (an number 0 maintained crate that adds additional traits that work makes working with the concrete snafu errors easier) in place of `anyhow` or `testresult` in testing and examples. ## Breaking Changes `iroh` - `changed` - `iroh::discovery::Lagged` changed from a tuple to a struct - `iroh::watcher::Disconnected` is changed from a tuple to a struct - `iroh::watcher::Disconnected` is no longer `UnwindSafe` or `RefUnwindSafe` - `iroh::watcher::InitializedFut` is no longer `RefUnwindSafe` `iroh-base` - `changed` - `iroh_base::ticket::Error` is renamed to `iroh_base::ticket::ParseError` - `iroh_base::key::KeyParsingError` has changed from a `thiserror` error to a `snafu` error `iroh-relay` - `changed` - `iroh_relay::node_info::MaxLengthExceededError` is no longer `UnwindSafe` or `RefUnwindSafe` - `iroh_relay::node_info::MaxLengthExceededError` was changed from a `thiserror` to a `snafu` error - `iroh_relay::client::ConnSendError` is now `iroh_relay::client::SendError` - `iroh_relay::protos::stun::Error` is now `iroh_relay::protos::stun::StunError` ## Notes & open questions <!-- Any notes, remarks or open questions you have to make about the PR. --> ## Change checklist - [ ] Self-review. - [ ] Documentation updates following the [style guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text), if relevant. - [ ] Tests if relevant. - [ ] All breaking changes documented. --------- Co-authored-by: Rüdiger Klaehn <rklaehn@protonmail.com> Co-authored-by: Philipp Krüger <philipp.krueger1@gmail.com> Co-authored-by: Kasey <kasey@n0.computer> Co-authored-by: “ramfox” <“kasey@n0.computer”>
1 parent e36ac77 commit 75eae87

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+3659
-1948
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ env:
1616
RUST_BACKTRACE: 1
1717
RUSTFLAGS: -Dwarnings
1818
RUSTDOCFLAGS: -Dwarnings
19-
MSRV: "1.81"
19+
MSRV: "1.85"
2020
SCCACHE_CACHE_SIZE: "10G"
2121
IROH_FORCE_STAGING_RELAYS: "1"
2222

@@ -256,7 +256,7 @@ jobs:
256256
- uses: actions/checkout@v4
257257
- uses: dtolnay/rust-toolchain@master
258258
with:
259-
toolchain: nightly-2024-11-30
259+
toolchain: nightly-2025-02-20
260260
- name: Install sccache
261261
uses: mozilla-actions/sccache-action@v0.0.9
262262

.github/workflows/docs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
- uses: actions/checkout@v4
3333
- uses: dtolnay/rust-toolchain@master
3434
with:
35-
toolchain: nightly-2024-11-30
35+
toolchain: nightly-2025-02-20
3636
- name: Install sccache
3737
uses: mozilla-actions/sccache-action@v0.0.9
3838

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ env:
4040
RUST_BACKTRACE: 1
4141
RUSTFLAGS: -Dwarnings
4242
RUSTDOCFLAGS: -Dwarnings
43-
MSRV: "1.81"
43+
MSRV: "1.85"
4444
SCCACHE_CACHE_SIZE: "10G"
4545
BIN_NAMES: "iroh-relay,iroh-dns-server"
4646
RELEASE_VERSION: ${{ github.event.inputs.release_version }}

.github/workflows/test_relay_server.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ env:
1313
RUST_BACKTRACE: 1
1414
RUSTFLAGS: -Dwarnings
1515
RUSTDOCFLAGS: -Dwarnings
16-
MSRV: "1.81"
16+
MSRV: "1.85"
1717
SCCACHE_CACHE_SIZE: "10G"
1818
IROH_FORCE_STAGING_RELAYS: "1"
1919

Cargo.lock

Lines changed: 63 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

iroh-base/Cargo.toml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ authors = ["n0 team"]
99
repository = "https://github.com/n0-computer/iroh"
1010

1111
# Sadly this also needs to be updated in .github/workflows/ci.yml
12-
rust-version = "1.81"
12+
rust-version = "1.85"
1313

1414
[lints]
1515
workspace = true
@@ -23,7 +23,9 @@ url = { version = "2.5.3", features = ["serde"], optional = true }
2323
postcard = { version = "1", default-features = false, features = ["alloc", "use-std", "experimental-derive"], optional = true }
2424
rand_core = { version = "0.6.4", optional = true }
2525
serde = { version = "1", features = ["derive", "rc"] }
26-
thiserror = { version = "2", optional = true }
26+
snafu = { version = "0.8.5", features = ["rust_1_81"], optional = true }
27+
n0-snafu = "0.2.0"
28+
nested_enum_utils = "0.2.0"
2729

2830
[dev-dependencies]
2931
postcard = { version = "1", features = ["use-std"] }
@@ -41,15 +43,15 @@ key = [
4143
"dep:ed25519-dalek",
4244
"dep:url",
4345
"dep:derive_more",
44-
"dep:thiserror",
46+
"dep:snafu",
4547
"dep:data-encoding",
4648
"dep:rand_core",
4749
"relay",
4850
]
4951
relay = [
5052
"dep:url",
5153
"dep:derive_more",
52-
"dep:thiserror",
54+
"dep:snafu",
5355
]
5456

5557
[package.metadata.docs.rs]

iroh-base/src/key.rs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ use std::{
99
};
1010

1111
use curve25519_dalek::edwards::CompressedEdwardsY;
12-
pub use ed25519_dalek::Signature;
13-
use ed25519_dalek::{SignatureError, SigningKey, VerifyingKey};
12+
pub use ed25519_dalek::{Signature, SignatureError};
13+
use ed25519_dalek::{SigningKey, VerifyingKey};
14+
use nested_enum_utils::common_fields;
1415
use rand_core::CryptoRngCore;
1516
use serde::{Deserialize, Serialize};
17+
use snafu::{Backtrace, Snafu};
1618

1719
/// A public key.
1820
///
@@ -180,17 +182,26 @@ impl Display for PublicKey {
180182
}
181183

182184
/// Error when deserialising a [`PublicKey`] or a [`SecretKey`].
183-
#[derive(thiserror::Error, Debug)]
185+
#[common_fields({
186+
backtrace: Option<Backtrace>,
187+
#[snafu(implicit)]
188+
span_trace: n0_snafu::SpanTrace,
189+
})]
190+
#[derive(Snafu, Debug)]
191+
#[allow(missing_docs)]
192+
#[snafu(visibility(pub(crate)))]
184193
pub enum KeyParsingError {
185194
/// Error when decoding.
186-
#[error("decoding: {0}")]
187-
Decode(#[from] data_encoding::DecodeError),
195+
#[snafu(transparent)]
196+
Decode { source: data_encoding::DecodeError },
188197
/// Error when decoding the public key.
189-
#[error("key: {0}")]
190-
Key(#[from] ed25519_dalek::SignatureError),
198+
#[snafu(transparent)]
199+
Key {
200+
source: ed25519_dalek::SignatureError,
201+
},
191202
/// The encoded information had the wrong length.
192-
#[error("invalid length")]
193-
DecodeInvalidLength,
203+
#[snafu(display("invalid length"))]
204+
DecodeInvalidLength {},
194205
}
195206

196207
/// Deserialises the [`PublicKey`] from it's base32 encoding.
@@ -333,14 +344,14 @@ fn decode_base32_hex(s: &str) -> Result<[u8; 32], KeyParsingError> {
333344
let input = s.to_ascii_uppercase();
334345
let input = input.as_bytes();
335346
if data_encoding::BASE32_NOPAD.decode_len(input.len())? != bytes.len() {
336-
return Err(KeyParsingError::DecodeInvalidLength);
347+
return Err(DecodeInvalidLengthSnafu.build());
337348
}
338349
data_encoding::BASE32_NOPAD.decode_mut(input, &mut bytes)
339350
};
340351
match res {
341352
Ok(len) => {
342353
if len != PublicKey::LENGTH {
343-
return Err(KeyParsingError::DecodeInvalidLength);
354+
return Err(DecodeInvalidLengthSnafu.build());
344355
}
345356
}
346357
Err(partial) => return Err(partial.error.into()),

iroh-base/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ mod node_addr;
1515
mod relay_url;
1616

1717
#[cfg(feature = "key")]
18-
pub use self::key::{KeyParsingError, NodeId, PublicKey, SecretKey, Signature};
18+
pub use self::key::{KeyParsingError, NodeId, PublicKey, SecretKey, Signature, SignatureError};
1919
#[cfg(feature = "key")]
2020
pub use self::node_addr::NodeAddr;
2121
#[cfg(feature = "relay")]

0 commit comments

Comments
 (0)