Skip to content

Commit 3841969

Browse files
committed
more fix fix fix
1 parent 1bd5271 commit 3841969

File tree

9 files changed

+37
-35
lines changed

9 files changed

+37
-35
lines changed

examples/compression.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
mod common;
66
use std::{fmt::Debug, path::PathBuf};
77

8-
use n0_error::Result;
98
use clap::Parser;
109
use common::setup_logging;
1110
use iroh::protocol::ProtocolHandler;
@@ -20,6 +19,7 @@ use iroh_blobs::{
2019
store::mem::MemStore,
2120
ticket::BlobTicket,
2221
};
22+
use n0_error::{Result, StdResultExt};
2323
use tracing::debug;
2424

2525
use crate::common::get_or_generate_secret_key;
@@ -200,15 +200,15 @@ async fn main() -> Result<()> {
200200
println!("Node is running. Press Ctrl-C to exit.");
201201
tokio::signal::ctrl_c().await?;
202202
println!("Shutting down.");
203-
router.shutdown().await?;
203+
router.shutdown().await.anyerr()?;
204204
}
205205
Args::Get { ticket, target } => {
206206
let store = MemStore::new();
207207
let conn = endpoint
208208
.connect(ticket.addr().clone(), lz4::Compression::ALPN)
209209
.await?;
210210
let connection_id = conn.stable_id() as u64;
211-
let (send, recv) = conn.open_bi().await?;
211+
let (send, recv) = conn.open_bi().await.anyerr()?;
212212
let send = compression.send_stream(send);
213213
let recv = compression.recv_stream(recv);
214214
let sp = StreamPair::new(connection_id, recv, send);

examples/custom-protocol.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ use std::{
4040
sync::{Arc, Mutex},
4141
};
4242

43-
use n0_error::Result;
4443
use clap::Parser;
4544
use iroh::{
4645
discovery::pkarr::PkarrResolver,
@@ -49,6 +48,7 @@ use iroh::{
4948
Endpoint, EndpointId,
5049
};
5150
use iroh_blobs::{api::Store, store::mem::MemStore, BlobsProtocol, Hash};
51+
use n0_error::{anyerr, Result, StdResultExt};
5252
mod common;
5353
use common::{get_or_generate_secret_key, setup_logging};
5454

@@ -110,7 +110,7 @@ async fn listen(text: Vec<String>) -> Result<()> {
110110

111111
// Wait for Ctrl-C to be pressed.
112112
tokio::signal::ctrl_c().await?;
113-
node.shutdown().await?;
113+
node.shutdown().await.anyerr()?;
114114
Ok(())
115115
}
116116

@@ -275,14 +275,14 @@ pub async fn query_remote(
275275
let blobs_conn = endpoint.connect(endpoint_id, iroh_blobs::ALPN).await?;
276276

277277
// Open a bi-directional in our connection.
278-
let (mut send, mut recv) = conn.open_bi().await?;
278+
let (mut send, mut recv) = conn.open_bi().await.anyerr()?;
279279

280280
// Send our query.
281-
send.write_all(query.as_bytes()).await?;
281+
send.write_all(query.as_bytes()).await.anyerr()?;
282282

283283
// Finish the send stream, signalling that no further data will be sent.
284284
// This makes the `read_to_end` call on the accepting side terminate.
285-
send.finish()?;
285+
send.finish().anyerr()?;
286286

287287
// In this example, we simply collect all results into a vector.
288288
// For real protocols, you'd usually want to return a stream of results instead.
@@ -298,7 +298,7 @@ pub async fn query_remote(
298298
// so in this case we break our loop.
299299
Err(iroh::endpoint::ReadExactError::FinishedEarly(_)) => break,
300300
// Other errors are connection errors, so we bail.
301-
Err(err) => return Err(err.into()),
301+
Err(err) => return Err(anyerr!(err)),
302302
Ok(_) => {}
303303
};
304304
// Upcast the raw bytes to the `Hash` type.
@@ -315,7 +315,7 @@ pub async fn query_remote(
315315
/// Read a blob from the local blob store and print it to STDOUT.
316316
async fn read_and_print(store: &Store, hash: Hash) -> Result<()> {
317317
let content = store.get_bytes(hash).await?;
318-
let message = String::from_utf8(content.to_vec())?;
318+
let message = String::from_utf8(content.to_vec()).anyerr()?;
319319
println!("{}: {message}", hash.fmt_short());
320320
Ok(())
321321
}

examples/get-blob.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use clap::Parser;
55
use common::setup_logging;
66
use iroh::discovery::pkarr::PkarrResolver;
77
use iroh_blobs::{get::request::GetBlobItem, ticket::BlobTicket, BlobFormat};
8+
use n0_error::bail_any;
89
use n0_future::StreamExt;
910
use tokio::io::AsyncWriteExt;
1011

@@ -54,10 +55,10 @@ async fn main() -> n0_error::Result<()> {
5455
break stats;
5556
}
5657
Some(GetBlobItem::Error(err)) => {
57-
n0_error::bail!("Error while streaming blob: {err}");
58+
bail_any!(err, "Error while streaming blob");
5859
}
5960
None => {
60-
n0_error::bail!("Stream ended unexpectedly.");
61+
bail_any!("Stream ended unexpectedly.");
6162
}
6263
}
6364
}

examples/limit.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use std::{
1818
},
1919
};
2020

21-
use n0_error::Result;
2221
use clap::Parser;
2322
use common::setup_logging;
2423
use iroh::{protocol::Router, EndpointAddr, EndpointId, SecretKey};
@@ -31,6 +30,7 @@ use iroh_blobs::{
3130
ticket::BlobTicket,
3231
BlobFormat, BlobsProtocol, Hash,
3332
};
33+
use n0_error::{Result, StdResultExt};
3434
use rand::rng;
3535

3636
use crate::common::get_or_generate_secret_key;
@@ -276,7 +276,7 @@ async fn main() -> Result<()> {
276276
}
277277

278278
tokio::signal::ctrl_c().await?;
279-
router.shutdown().await?;
279+
router.shutdown().await.anyerr()?;
280280
}
281281
Args::ByHash { paths } => {
282282
let store = MemStore::new();
@@ -304,7 +304,7 @@ async fn main() -> Result<()> {
304304
println!("{}: {ticket} ({permitted})", path.display());
305305
}
306306
tokio::signal::ctrl_c().await?;
307-
router.shutdown().await?;
307+
router.shutdown().await.anyerr()?;
308308
}
309309
Args::Throttle { paths, delay_ms } => {
310310
let store = MemStore::new();
@@ -316,7 +316,7 @@ async fn main() -> Result<()> {
316316
println!("{}: {ticket}", path.display());
317317
}
318318
tokio::signal::ctrl_c().await?;
319-
router.shutdown().await?;
319+
router.shutdown().await.anyerr()?;
320320
}
321321
Args::MaxConnections {
322322
paths,
@@ -331,7 +331,7 @@ async fn main() -> Result<()> {
331331
println!("{}: {ticket}", path.display());
332332
}
333333
tokio::signal::ctrl_c().await?;
334-
router.shutdown().await?;
334+
router.shutdown().await.anyerr()?;
335335
}
336336
}
337337
Ok(())

examples/mdns-discovery.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
//! Run that command on another machine in the same local network, replacing [FILE_PATH] to the path on which you want to save the transferred content.
1414
use std::path::{Path, PathBuf};
1515

16-
use n0_error::{ensure, Result};
1716
use clap::{Parser, Subcommand};
1817
use iroh::{
1918
discovery::mdns::MdnsDiscovery, protocol::Router, Endpoint, PublicKey, RelayMode, SecretKey,
2019
};
2120
use iroh_blobs::{store::mem::MemStore, BlobsProtocol, Hash};
21+
use n0_error::{ensure, Result, StdResultExt};
2222

2323
mod common;
2424
use common::{get_or_generate_secret_key, setup_logging};
@@ -74,15 +74,15 @@ async fn accept(path: &Path) -> Result<()> {
7474

7575
if !path.is_file() {
7676
println!("Content must be a file.");
77-
node.shutdown().await?;
77+
node.shutdown().await.anyerr()?;
7878
return Ok(());
7979
}
8080
let absolute = path.canonicalize()?;
8181
println!("Adding {} as {}...", path.display(), absolute.display());
8282
let tag = store.add_path(absolute).await?;
8383
println!("To fetch the blob:\n\tcargo run --example mdns-discovery --features examples -- connect {} {} -o [FILE_PATH]", node.endpoint().id(), tag.hash);
8484
tokio::signal::ctrl_c().await?;
85-
node.shutdown().await?;
85+
node.shutdown().await.anyerr()?;
8686
Ok(())
8787
}
8888

examples/random_store.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::{env, path::PathBuf, str::FromStr};
22

3-
use n0_error::{Context, Result};
43
use clap::{Parser, Subcommand};
54
use iroh::{discovery::static_provider::StaticProvider, SecretKey};
65
use iroh_blobs::{
@@ -12,6 +11,7 @@ use iroh_blobs::{
1211
};
1312
use iroh_tickets::endpoint::EndpointTicket;
1413
use irpc::RpcMessage;
14+
use n0_error::{Result, StackResultExt, StdResultExt};
1515
use n0_future::StreamExt;
1616
use rand::{rngs::StdRng, Rng, SeedableRng};
1717
use tokio::signal::ctrl_c;
@@ -247,7 +247,7 @@ async fn provide(args: ProvideArgs) -> n0_error::Result<()> {
247247
println!("Node address: {addr:?}");
248248
println!("ticket:\n{ticket}");
249249
ctrl_c().await?;
250-
router.shutdown().await?;
250+
router.shutdown().await.anyerr()?;
251251
dump_task.abort();
252252
Ok(())
253253
}

examples/transfer-collection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//! $ cargo run --example transfer-collection
88
use std::collections::HashMap;
99

10-
use n0_error::{Context, Result};
1110
use iroh::{
1211
discovery::static_provider::StaticProvider, protocol::Router, Endpoint, EndpointAddr, RelayMode,
1312
};
@@ -17,6 +16,7 @@ use iroh_blobs::{
1716
store::mem::MemStore,
1817
BlobsProtocol, Hash, HashAndFormat,
1918
};
19+
use n0_error::{Result, StackResultExt};
2020

2121
/// Node is something you'd define in your application. It can contain whatever
2222
/// shared state you'd want to couple with network operations.

examples/transfer.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::path::PathBuf;
22

33
use iroh::{protocol::Router, Endpoint};
44
use iroh_blobs::{store::mem::MemStore, ticket::BlobTicket, BlobsProtocol};
5+
use n0_error::StdResultExt;
56

67
#[tokio::main]
78
async fn main() -> n0_error::Result<()> {
@@ -21,7 +22,7 @@ async fn main() -> n0_error::Result<()> {
2122

2223
match arg_refs.as_slice() {
2324
["send", filename] => {
24-
let filename: PathBuf = filename.parse()?;
25+
let filename: PathBuf = filename.parse().anyerr()?;
2526
let abs_path = std::path::absolute(&filename)?;
2627

2728
println!("Hashing file.");
@@ -49,12 +50,12 @@ async fn main() -> n0_error::Result<()> {
4950

5051
// Gracefully shut down the node
5152
println!("Shutting down.");
52-
router.shutdown().await?;
53+
router.shutdown().await.anyerr()?;
5354
}
5455
["receive", ticket, filename] => {
55-
let filename: PathBuf = filename.parse()?;
56+
let filename: PathBuf = filename.parse().anyerr()?;
5657
let abs_path = std::path::absolute(filename)?;
57-
let ticket: BlobTicket = ticket.parse()?;
58+
let ticket: BlobTicket = ticket.parse().anyerr()?;
5859

5960
// For receiving files, we create a "downloader" that allows us to fetch files
6061
// from other nodes via iroh connections

src/util/connection_pool.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -553,8 +553,8 @@ mod tests {
553553
protocol::{AcceptError, ProtocolHandler, Router},
554554
Endpoint, EndpointAddr, EndpointId, RelayMode, SecretKey, TransportAddr, Watcher,
555555
};
556+
use n0_error::{AnyError, Result, StdResultExt};
556557
use n0_future::{io, stream, BufferedStreamExt, StreamExt};
557-
use n0_snafu::ResultExt;
558558
use testresult::TestResult;
559559
use tracing::trace;
560560

@@ -588,14 +588,14 @@ mod tests {
588588
}
589589
}
590590

591-
async fn echo_client(conn: &Connection, text: &[u8]) -> n0_snafu::Result<Vec<u8>> {
591+
async fn echo_client(conn: &Connection, text: &[u8]) -> Result<Vec<u8>> {
592592
let conn_id = conn.stable_id();
593-
let id = conn.remote_id().e()?;
593+
let id = conn.remote_id().anyerr()?;
594594
trace!(%id, %conn_id, "Sending echo request");
595-
let (mut send, mut recv) = conn.open_bi().await.e()?;
596-
send.write_all(text).await.e()?;
597-
send.finish().e()?;
598-
let response = recv.read_to_end(1000).await.e()?;
595+
let (mut send, mut recv) = conn.open_bi().await.anyerr()?;
596+
send.write_all(text).await.anyerr()?;
597+
send.finish().anyerr()?;
598+
let response = recv.read_to_end(1000).await.anyerr()?;
599599
trace!(%id, %conn_id, "Received echo response");
600600
Ok(response)
601601
}
@@ -653,7 +653,7 @@ mod tests {
653653
&self,
654654
id: EndpointId,
655655
text: Vec<u8>,
656-
) -> Result<Result<(usize, Vec<u8>), n0_snafu::Error>, PoolConnectError> {
656+
) -> Result<Result<(usize, Vec<u8>), AnyError>, PoolConnectError> {
657657
let conn = self.pool.get_or_connect(id).await?;
658658
let id = conn.stable_id();
659659
match echo_client(&conn, &text).await {

0 commit comments

Comments
 (0)