Skip to content

Commit 3f0a661

Browse files
committed
Refactor the GetError to be just a list of things that can go wrong.
Also make the whole get fsm generic so it can be used with an arbitrary stream, not just a quinn/iroh RecvStream.
1 parent f399e2b commit 3f0a661

File tree

4 files changed

+254
-472
lines changed

4 files changed

+254
-472
lines changed

src/api/remote.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@ use n0_future::{io, Stream, StreamExt};
88
use n0_snafu::SpanTrace;
99
use nested_enum_utils::common_fields;
1010
use ref_cast::RefCast;
11-
use snafu::{Backtrace, IntoError, Snafu};
11+
use snafu::{Backtrace, IntoError, ResultExt, Snafu};
1212

1313
use super::blobs::{Bitfield, ExportBaoOptions};
1414
use crate::{
1515
api::{blobs::WriteProgress, ApiClient},
16-
get::{fsm::DecodeError, BadRequestSnafu, GetError, GetResult, LocalFailureSnafu, Stats},
16+
get::{
17+
fsm::DecodeError,
18+
get_error::{BadRequestSnafu, LocalFailureSnafu},
19+
GetError, GetResult, Stats,
20+
},
1721
protocol::{
1822
GetManyRequest, ObserveItem, ObserveRequest, PushRequest, Request, RequestType,
1923
MAX_MESSAGE_SIZE,
@@ -508,7 +512,7 @@ impl Remote {
508512
let local = self
509513
.local(content)
510514
.await
511-
.map_err(|e| LocalFailureSnafu.into_error(e.into()))?;
515+
.map_err(|e: anyhow::Error| LocalFailureSnafu.into_error(e.into()))?;
512516
if local.is_complete() {
513517
return Ok(Default::default());
514518
}
@@ -685,7 +689,7 @@ impl Remote {
685689
.await
686690
.map_err(|e| LocalFailureSnafu.into_error(e.into()))?,
687691
)
688-
.map_err(|source| BadRequestSnafu.into_error(source.into()))?;
692+
.context(BadRequestSnafu)?;
689693
// let mut hash_seq = LazyHashSeq::new(store.blobs().clone(), root);
690694
loop {
691695
let at_start_child = match next_child {

0 commit comments

Comments
 (0)