From fd6d7d87b6a16097435b50650831ec421c95b1f3 Mon Sep 17 00:00:00 2001 From: JandereDev Date: Tue, 28 Sep 2021 15:55:08 +0200 Subject: [PATCH] Added error handling to `upload` subcommand --- desktop/src-tauri/src/cli.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/desktop/src-tauri/src/cli.rs b/desktop/src-tauri/src/cli.rs index 7f97ee8..f741cab 100644 --- a/desktop/src-tauri/src/cli.rs +++ b/desktop/src-tauri/src/cli.rs @@ -100,17 +100,25 @@ pub fn run() -> bool { .to_string_lossy() .to_string(); let bar = ProgressBar::new(buf.len() as u64); - bar.set_style(ProgressStyle::default_bar().template("{spinner:.green} {msg}[{elapsed_precise}] [{bar:40.cyan/blue}] {bytes}/{total_bytes} ({bytes_per_sec}, {eta})")); + bar.set_style(ProgressStyle::default_bar().template("{spinner:.green} {msg} [{elapsed_precise}] [{bar:40.cyan/blue}] {bytes}/{total_bytes} ({bytes_per_sec}, {eta})")); bar.set_message(&format!("Upload {}", name)); bar.enable_steady_tick(100); if dest.ends_with('/') { dest.remove(dest.len() - 1); } - handle + let res = handle .write_file(&format!("{}/{}", dest, name), &buf, &mut |remaining| { bar.set_position((buf.len() - remaining) as u64) - }) - .unwrap(); + }); + + match res { + Ok(_) => { + println!("Upload {}: Ok", dest); + } + Err(error) => { + bar.abandon_with_message(&format!("Failed: {}", error)); + } + } bar.finish(); } } else {