From 1b569a8fd42f203b3bea8d30fd33fd6f6d4bd709 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 19 May 2022 17:57:11 +0200 Subject: [PATCH] chore: Consistently use anyhow::Result for example main fn's When an `Err` is propagated out of `main`, it will be printed using `Debug`, which is much easier to read in anyhow::Error's case. See also https://docs.rs/anyhow/latest/anyhow/struct.Error.html#display-representations --- crates/matrix-sdk/examples/cross_signing_bootstrap.rs | 6 ++++-- crates/matrix-sdk/examples/emoji_verification.rs | 6 ++++-- crates/matrix-sdk/examples/get_profiles.rs | 2 +- crates/matrix-sdk/examples/image_bot.rs | 2 +- crates/matrix-sdk/examples/login.rs | 6 ++++-- crates/matrix-sdk/examples/timeline.rs | 2 +- 6 files changed, 15 insertions(+), 9 deletions(-) diff --git a/crates/matrix-sdk/examples/cross_signing_bootstrap.rs b/crates/matrix-sdk/examples/cross_signing_bootstrap.rs index 3dd788ef2..eb4d1975c 100644 --- a/crates/matrix-sdk/examples/cross_signing_bootstrap.rs +++ b/crates/matrix-sdk/examples/cross_signing_bootstrap.rs @@ -72,7 +72,7 @@ async fn login( } #[tokio::main] -async fn main() -> Result<(), matrix_sdk::Error> { +async fn main() -> anyhow::Result<()> { tracing_subscriber::fmt::init(); let (homeserver_url, username, password) = @@ -87,5 +87,7 @@ async fn main() -> Result<(), matrix_sdk::Error> { } }; - login(homeserver_url, &username, &password).await + login(homeserver_url, &username, &password).await?; + + Ok(()) } diff --git a/crates/matrix-sdk/examples/emoji_verification.rs b/crates/matrix-sdk/examples/emoji_verification.rs index 4e9112157..b4572227a 100644 --- a/crates/matrix-sdk/examples/emoji_verification.rs +++ b/crates/matrix-sdk/examples/emoji_verification.rs @@ -201,7 +201,7 @@ async fn login( } #[tokio::main] -async fn main() -> Result<(), matrix_sdk::Error> { +async fn main() -> anyhow::Result<()> { tracing_subscriber::fmt::init(); let (homeserver_url, username, password) = @@ -216,5 +216,7 @@ async fn main() -> Result<(), matrix_sdk::Error> { } }; - login(homeserver_url, &username, &password).await + login(homeserver_url, &username, &password).await?; + + Ok(()) } diff --git a/crates/matrix-sdk/examples/get_profiles.rs b/crates/matrix-sdk/examples/get_profiles.rs index 677db3fe0..3c8edc6ea 100644 --- a/crates/matrix-sdk/examples/get_profiles.rs +++ b/crates/matrix-sdk/examples/get_profiles.rs @@ -45,7 +45,7 @@ async fn login( } #[tokio::main] -async fn main() -> Result<(), matrix_sdk::Error> { +async fn main() -> anyhow::Result<()> { tracing_subscriber::fmt::init(); let (homeserver_url, username, password) = diff --git a/crates/matrix-sdk/examples/image_bot.rs b/crates/matrix-sdk/examples/image_bot.rs index 6f6724f1b..208ad7c5a 100644 --- a/crates/matrix-sdk/examples/image_bot.rs +++ b/crates/matrix-sdk/examples/image_bot.rs @@ -74,7 +74,7 @@ async fn login_and_sync( } #[tokio::main] -async fn main() -> Result<(), matrix_sdk::Error> { +async fn main() -> anyhow::Result<()> { tracing_subscriber::fmt::init(); let (homeserver_url, username, password, image_path) = match (env::args().nth(1), env::args().nth(2), env::args().nth(3), env::args().nth(4)) { diff --git a/crates/matrix-sdk/examples/login.rs b/crates/matrix-sdk/examples/login.rs index 1d68f5e64..259359773 100644 --- a/crates/matrix-sdk/examples/login.rs +++ b/crates/matrix-sdk/examples/login.rs @@ -47,7 +47,7 @@ async fn login( } #[tokio::main] -async fn main() -> Result<(), matrix_sdk::Error> { +async fn main() -> anyhow::Result<()> { tracing_subscriber::fmt::init(); let (homeserver_url, username, password) = @@ -62,5 +62,7 @@ async fn main() -> Result<(), matrix_sdk::Error> { } }; - login(homeserver_url, &username, &password).await + login(homeserver_url, &username, &password).await?; + + Ok(()) } diff --git a/crates/matrix-sdk/examples/timeline.rs b/crates/matrix-sdk/examples/timeline.rs index d8d32802b..339a7ee93 100644 --- a/crates/matrix-sdk/examples/timeline.rs +++ b/crates/matrix-sdk/examples/timeline.rs @@ -56,7 +56,7 @@ async fn print_timeline(room: Room) { } #[tokio::main] -async fn main() -> Result<(), matrix_sdk::Error> { +async fn main() -> anyhow::Result<()> { tracing_subscriber::fmt::init(); let (homeserver_url, username, password, room_id) =