Skip to content

feat!: concrete errors #3161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 61 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
a673d59
wip: concrete errors for iroh-relay
dignifiedquire Jan 31, 2025
c36d53e
fixup
dignifiedquire Apr 24, 2025
3f7f209
use git dependency for n0-snafu
dignifiedquire Apr 24, 2025
deca8f8
convert iroh-base to snafu
dignifiedquire Apr 24, 2025
a26857c
use macro to DRY the snafu error enum (#3275)
rklaehn Apr 28, 2025
45bb23c
refactor: convert iroh::disco to snafu
dignifiedquire Apr 28, 2025
f35d33c
refactor(iroh): switch thiserror to snafu
dignifiedquire Apr 28, 2025
42a8d73
refactor(iroh): convert reportgen/hairpin
dignifiedquire Apr 28, 2025
481b05d
prepare endoint.rs for conversion
dignifiedquire Apr 29, 2025
958c917
explicit use of anyhow::Result in magicsock
dignifiedquire Apr 29, 2025
d6cd802
use explicit anyhow::Result in the rest of iroh
dignifiedquire Apr 29, 2025
9a1cc49
refactor(iroh): transform magicsock/relay-actor
dignifiedquire Apr 29, 2025
d3589e0
start refactoring magicsock
dignifiedquire Apr 29, 2025
9e3c48b
refactor(iroh): introduce AddNodeaddrError
dignifiedquire Apr 29, 2025
dd6f59e
refactor(iroh): introduce netreporterror
dignifiedquire Apr 29, 2025
c8ca621
refactor(iroh): make Actor::run infallible
dignifiedquire Apr 29, 2025
0a04f6f
refactor: endpoint.rs is free
dignifiedquire Apr 29, 2025
e29d5ae
feat(iroh-relay): Convert all client-side errors to snafu (#3283)
matheus23 Apr 30, 2025
ba32bc6
Merge remote-tracking branch 'origin/main' into feat-relay-errors
matheus23 Apr 30, 2025
877200e
Fix types after merge
matheus23 Apr 30, 2025
ed3ed0d
Make `iroh-base` use snafu more similar to other code (#3285)
matheus23 Apr 30, 2025
4f92aa7
refactor: net_report.rs is free
dignifiedquire Apr 30, 2025
7c0b111
refactor(iroh): start conversion of reportgen
dignifiedquire Apr 30, 2025
8b7fe74
probes: custom erroor
dignifiedquire Apr 30, 2025
fa1e1c3
net_report is free
dignifiedquire Apr 30, 2025
3d347ab
feat(iroh-relay): replace `anyhow` with `snafu` in the server side of…
ramfox May 1, 2025
f99ca2a
feat(iroh): convert `discovery` module to use `snafu` errors (#3287)
ramfox May 2, 2025
fe1d922
feat: make Router::spawn sync and infallible
dignifiedquire May 2, 2025
dc47f65
feat: make make_client_config infallible
dignifiedquire May 2, 2025
a0f67a1
refactor protocol error handling
dignifiedquire May 2, 2025
4742774
iroh: anyhow is now a dev dependency
dignifiedquire May 2, 2025
11b39f4
spelling
May 2, 2025
ea81665
improve discovery errors
dignifiedquire May 2, 2025
1797a14
fix clippy in endpoint.rs
dignifiedquire May 2, 2025
a5b6280
update dep
dignifiedquire May 2, 2025
2da8c10
fixup errors
dignifiedquire May 2, 2025
445b4f0
fix relay proto decoding
dignifiedquire May 2, 2025
9b23464
Cleanup unused `snafu(visibility(pub(crate)))` (#3289)
matheus23 May 5, 2025
f69a63c
use published n0-snafu
dignifiedquire May 5, 2025
f9af46e
refactor(relay): drop anyhow and testresult
dignifiedquire May 5, 2025
445e533
refactor: convert iroh-dns-server
dignifiedquire May 5, 2025
6e4a311
fixups in iroh-relay
dignifiedquire May 5, 2025
c288607
fixup: bench
dignifiedquire May 5, 2025
16de8ca
convert discovery tests from `anyhow` to `snafu`
May 5, 2025
05f3686
missed some in `discovery.rs`
May 5, 2025
8440102
replace `anyhow` with `n0_snafu` in `magicsock` tests
May 5, 2025
8f6a09c
Merge branch 'main' into feat-relay-errors
May 5, 2025
9b0ccfc
refactor: convert iroh/bench
dignifiedquire May 6, 2025
ff23a7a
chore(iroh): Convert tests to using `n0_snafu::TestResult` (#3291)
matheus23 May 6, 2025
c35dda8
move anyhow to examples
dignifiedquire May 6, 2025
17b5237
drop thiserror
dignifiedquire May 6, 2025
73aeceb
test: remove remaining usages of testresult
dignifiedquire May 6, 2025
fc14fc3
fix: downgrade redb for MSRV stability
dignifiedquire May 6, 2025
757d161
Merge remote-tracking branch 'origin/main' into feat-relay-errors
dignifiedquire May 7, 2025
ac8b174
Merge remote-tracking branch 'origin/main' into feat-relay-errors
dignifiedquire May 13, 2025
63ad858
Merge remote-tracking branch 'origin/main' into feat-relay-errors
May 20, 2025
6cc2483
merge cleanup
May 21, 2025
6ee45e0
replace `context` with `e` in `iroh-dns-server` where the context doe…
May 22, 2025
e96c74b
rename `TestError`, `TestResult`, `TestResultExt` to `Error`, `Result…
May 24, 2025
fee934f
Merge branch 'main' into feat-relay-errors
May 26, 2025
c67641f
change all error types named `Error` to a more specific name
May 26, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 69 additions & 20 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ unexpected_cfgs = { level = "warn", check-cfg = ["cfg(iroh_docsrs)", "cfg(iroh_l

[workspace.lints.clippy]
unused-async = "warn"

[patch.crates-io]
n0-snafu = { git = "https://github.com/n0-computer/n0-snafu", branch = "expand-test-error" }
Comment on lines +44 to +45
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to remember to replace this with a published version

8 changes: 5 additions & 3 deletions iroh-base/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ url = { version = "2.5.3", features = ["serde"], optional = true }
postcard = { version = "1", default-features = false, features = ["alloc", "use-std", "experimental-derive"], optional = true }
rand_core = { version = "0.6.4", optional = true }
serde = { version = "1", features = ["derive", "rc"] }
thiserror = { version = "2", optional = true }
snafu = { version = "0.8.5", features = ["rust_1_81"], optional = true }
n0-snafu = "0.1.0"
nested_enum_utils = "0.2.0"

[dev-dependencies]
postcard = { version = "1", features = ["use-std"] }
Expand All @@ -41,15 +43,15 @@ key = [
"dep:ed25519-dalek",
"dep:url",
"dep:derive_more",
"dep:thiserror",
"dep:snafu",
"dep:data-encoding",
"dep:rand_core",
"relay",
]
relay = [
"dep:url",
"dep:derive_more",
"dep:thiserror",
"dep:snafu",
]

[package.metadata.docs.rs]
Expand Down
33 changes: 22 additions & 11 deletions iroh-base/src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ use std::{
};

use curve25519_dalek::edwards::CompressedEdwardsY;
pub use ed25519_dalek::Signature;
use ed25519_dalek::{SignatureError, SigningKey, VerifyingKey};
pub use ed25519_dalek::{Signature, SignatureError};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will there be any regrets about re-exporting these without wrapping?

use ed25519_dalek::{SigningKey, VerifyingKey};
use nested_enum_utils::common_fields;
use rand_core::CryptoRngCore;
use serde::{Deserialize, Serialize};
use snafu::{Backtrace, Snafu};

/// A public key.
///
Expand Down Expand Up @@ -180,17 +182,26 @@ impl Display for PublicKey {
}

/// Error when deserialising a [`PublicKey`] or a [`SecretKey`].
#[derive(thiserror::Error, Debug)]
#[common_fields({
backtrace: Option<Backtrace>,
#[snafu(implicit)]
span_trace: n0_snafu::SpanTrace,
})]
#[derive(Snafu, Debug)]
#[allow(missing_docs)]
#[snafu(visibility(pub(crate)))]
pub enum KeyParsingError {
/// Error when decoding.
#[error("decoding: {0}")]
Decode(#[from] data_encoding::DecodeError),
#[snafu(transparent)]
Decode { source: data_encoding::DecodeError },
/// Error when decoding the public key.
#[error("key: {0}")]
Key(#[from] ed25519_dalek::SignatureError),
#[snafu(transparent)]
Key {
source: ed25519_dalek::SignatureError,
},
/// The encoded information had the wrong length.
#[error("invalid length")]
DecodeInvalidLength,
#[snafu(display("invalid length"))]
DecodeInvalidLength {},
}

/// Deserialises the [`PublicKey`] from it's base32 encoding.
Expand Down Expand Up @@ -333,14 +344,14 @@ fn decode_base32_hex(s: &str) -> Result<[u8; 32], KeyParsingError> {
let input = s.to_ascii_uppercase();
let input = input.as_bytes();
if data_encoding::BASE32_NOPAD.decode_len(input.len())? != bytes.len() {
return Err(KeyParsingError::DecodeInvalidLength);
return Err(DecodeInvalidLengthSnafu.build());
}
data_encoding::BASE32_NOPAD.decode_mut(input, &mut bytes)
};
match res {
Ok(len) => {
if len != PublicKey::LENGTH {
return Err(KeyParsingError::DecodeInvalidLength);
return Err(DecodeInvalidLengthSnafu.build());
}
}
Err(partial) => return Err(partial.error.into()),
Expand Down
2 changes: 1 addition & 1 deletion iroh-base/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mod node_addr;
mod relay_url;

#[cfg(feature = "key")]
pub use self::key::{KeyParsingError, NodeId, PublicKey, SecretKey, Signature};
pub use self::key::{KeyParsingError, NodeId, PublicKey, SecretKey, Signature, SignatureError};
#[cfg(feature = "key")]
pub use self::node_addr::NodeAddr;
#[cfg(feature = "relay")]
Expand Down
Loading
Loading