From 6846dad9e6e109961442cb6b6a4e0dcbc3f7c7fd Mon Sep 17 00:00:00 2001 From: Vladimir Borisov Date: Wed, 21 Jul 2021 17:59:16 +0300 Subject: [PATCH] Better IPC error handling --- src/stremio_app/stremio_app.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/stremio_app/stremio_app.rs b/src/stremio_app/stremio_app.rs index 0ea9fef..8e64279 100644 --- a/src/stremio_app/stremio_app.rs +++ b/src/stremio_app/stremio_app.rs @@ -148,14 +148,15 @@ impl MainWindow { }), ..Default::default() }; - let resp_json = serde_json::to_string(&resp).unwrap(); + let resp_json = + serde_json::to_string(&resp).expect("Cannot build response"); web_tx_web.send(resp_json).ok(); } else if let Some(args) = msg.args { - // TODO: this can panic if let Some(method) = args.first() { - let method = method.as_str().unwrap(); + let method = method.as_str().unwrap_or("invalid-method"); if method.starts_with("mpv-") { - let resp_json = serde_json::to_string(&args).unwrap(); + let resp_json = + serde_json::to_string(&args).expect("Cannot build response"); player_tx.send(resp_json).ok(); } else { match method { @@ -172,7 +173,10 @@ impl MainWindow { hide_splash_sender.notice(); if args.len() > 1 { // TODO: Make this modal dialog - eprintln!("Web App Error: {}", args[1].as_str().unwrap_or("Unknown error")); + eprintln!( + "Web App Error: {}", + args[1].as_str().unwrap_or("Unknown error") + ); } } _ => eprintln!("Unsupported command {:?}", args),