Skip to content

Commit 14daf11

Browse files
author
“ramfox”
committed
refactor: start converting thiserror to snafu
1 parent 5713917 commit 14daf11

File tree

4 files changed

+49
-26
lines changed

4 files changed

+49
-26
lines changed

Cargo.lock

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ derive_more = { version = "2.0.1", features = ["from", "try_from", "into", "debu
1111
futures-lite = "2.6.0"
1212
quinn = { package = "iroh-quinn", version = "0.13.0" }
1313
n0-future = "0.1.2"
14+
n0-snafu = "0.2.0"
1415
n0-watcher = "0.2.0"
16+
nested_enum_utils = "0.2.1"
1517
range-collections = { version = "0.4.6", features = ["serde"] }
1618
redb = "2.4.0"
1719
smallvec = { version = "1", features = ["serde", "const_new"] }
18-
thiserror = "2.0.11"
20+
snafu = "0.8.5"
1921
tokio = { version = "1.43.0", features = ["full"] }
2022
tokio-util = { version = "0.7.13", features = ["full"] }
2123
tracing = "0.1.41"

src/get.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -243,23 +243,33 @@ pub mod fsm {
243243
}
244244

245245
/// Error that you can get from [`AtConnected::next`]
246-
#[derive(Debug, thiserror::Error)]
246+
#[common_fields({
247+
backtrace: Option<Backtrace>,
248+
#[snafu(implicit)]
249+
span_trace: n0_snafu::SpanTrace,
250+
})]
251+
#[allow(missing_docs)]
252+
#[derive(Debug, Snafu)]
253+
#[non_exhaustive]
254+
#[derive(Debug, snafu::Error)]
247255
pub enum ConnectedNextError {
248256
/// Error when serializing the request
249-
#[error("postcard ser: {0}")]
250-
PostcardSer(postcard::Error),
257+
#[snafu(display("postcard ser: {source}"))]
258+
PostcardSer { source: postcard::Error },
251259
/// The serialized request is too long to be sent
252-
#[error("request too big")]
260+
#[snafu(display("request too big"))]
253261
RequestTooBig,
254262
/// Error when writing the request to the [`SendStream`].
255-
#[error("write: {0}")]
256-
Write(#[from] iroh::endpoint::WriteError),
263+
#[snafu(display("write: {source}"))]
264+
Write { source: iroh::endpoint::WriteError },
257265
/// Quic connection is closed.
258-
#[error("closed")]
259-
Closed(#[from] quinn::ClosedStream),
266+
#[snafu(display("closed"))]
267+
Closed {
268+
source: iroh::endpoint::ClosedStream,
269+
},
260270
/// A generic io error
261-
#[error("io {0}")]
262-
Io(io::Error),
271+
#[snafu(transparent)]
272+
Io { source: io::Error },
263273
}
264274

265275
impl ConnectedNextError {

src/store/fs/meta.rs

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ use std::{
1111
use bao_tree::BaoTree;
1212
use bytes::Bytes;
1313
use irpc::channel::spsc;
14+
use n0_snafu::SpanTrace;
15+
use nested_enum_utils::common_fields;
1416
use redb::{Database, DatabaseError, ReadableTable};
17+
use snafu::{Backtrace, Snafu};
1518
use tokio::pin;
1619

1720
use crate::{
@@ -46,21 +49,28 @@ use crate::store::{Hash, IROH_BLOCK_SIZE, util::Tag};
4649
///
4750
/// What can go wrong are various things with redb, as well as io errors related
4851
/// to files other than redb.
49-
#[allow(clippy::large_enum_variant)]
50-
#[derive(Debug, thiserror::Error)]
52+
#[common_fields({
53+
backtrace: Option<Backtrace>,
54+
#[snafu(implicit)]
55+
span_trace: n0_snafu::SpanTrace,
56+
})]
57+
#[allow(missing_docs)]
58+
#[derive(Debug, Snafu)]
59+
#[non_exhaustive]
60+
#[derive(Debug, snafu::Error)]
5161
pub enum ActorError {
52-
#[error("table error: {0}")]
53-
Table(#[from] redb::TableError),
54-
#[error("database error: {0}")]
55-
Database(#[from] redb::DatabaseError),
56-
#[error("transaction error: {0}")]
57-
Transaction(#[from] redb::TransactionError),
58-
#[error("commit error: {0}")]
59-
Commit(#[from] redb::CommitError),
60-
#[error("storage error: {0}")]
61-
Storage(#[from] redb::StorageError),
62-
#[error("inconsistent database state: {0}")]
63-
Inconsistent(String),
62+
#[snafu(display("table error: {source}"))]
63+
Table { source: redb::TableError },
64+
#[snafu(display("database error: {source}"))]
65+
Database { source: redb::DatabaseError },
66+
#[snafu(display("transaction error: {source}"))]
67+
Transaction { source: redb::TransactionError },
68+
#[snafu(display("commit error: {source}"))]
69+
Commit { source: redb::CommitError },
70+
#[snafu(display("storage error: {source}"))]
71+
Storage { source: redb::StorageError },
72+
#[snafu(display("inconsistent database state: {source}"))]
73+
Inconsistent { source: String },
6474
}
6575

6676
impl From<ActorError> for io::Error {

0 commit comments

Comments
 (0)