From 97cadda681e258a1644d84dd9a1c8655f5dbc755 Mon Sep 17 00:00:00 2001 From: Vladimir Borisov Date: Fri, 30 Sep 2022 15:51:59 +0300 Subject: [PATCH] Slightly better error handling for the server --- src/stremio_app/stremio_server/server.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/stremio_app/stremio_server/server.rs b/src/stremio_app/stremio_server/server.rs index 010a822..3d35bf2 100644 --- a/src/stremio_app/stremio_server/server.rs +++ b/src/stremio_app/stremio_server/server.rs @@ -1,4 +1,6 @@ +use native_windows_gui as nwg; use std::os::windows::process::CommandExt; +use std::env; use std::process::Command; use std::thread; use std::time::Duration; @@ -17,12 +19,24 @@ impl StremioServer { job.set_extended_limit_info(&mut info).ok(); job.assign_current_process().ok(); loop { - let mut child = Command::new("stremio-runtime") + let child = Command::new("./stremio-runtime") .arg("server.js") .creation_flags(CREATE_NO_WINDOW) - .spawn() - .expect("Cannot run the server"); - child.wait().expect("Cannot wait for the server"); + .spawn(); + match child { + Ok(mut child) => { + // TODO: store somehow last few lines of the child's stdout/stderr instead of just waiting + child.wait().expect("Cannot wait for the server"); + } + Err(err) => { + nwg::error_message( + "Stremio server", + format!("Cannot execute stremio-runtime: {}", &err).as_str(), + ); + break; + } + }; + // TODO: show error message with the child's stdout/stderr thread::sleep(Duration::from_millis(500)); dbg!("Trying to restart the server..."); }