diff --git a/crates/fj-host/src/lib.rs b/crates/fj-host/src/lib.rs index 57c133714..3b09d70a8 100644 --- a/crates/fj-host/src/lib.rs +++ b/crates/fj-host/src/lib.rs @@ -307,7 +307,10 @@ impl Watcher { /// /// Returns `None`, if the model has not changed since the last time this /// method was called. - pub fn receive(&self, status: &mut StatusReport) -> Option { + pub fn receive_shape( + &self, + status: &mut StatusReport, + ) -> Result, Error> { match self.channel.try_recv() { Ok(()) => { let shape = match self.model.load_once(&self.parameters, status) @@ -317,18 +320,18 @@ impl Watcher { // An error is being displayed to the user via the // `StatusReport that is passed to `load_once` above, so // no need to do anything else here. - return None; + return Ok(None); } Err(err) => { - panic!("Error reloading model: {:?}", err); + return Err(err); } }; - Some(shape) + Ok(Some(shape)) } Err(mpsc::TryRecvError::Empty) => { // Nothing to receive from the channel. - None + Ok(None) } Err(mpsc::TryRecvError::Disconnected) => { // The other end has disconnected. This is probably the result diff --git a/crates/fj-window/src/run.rs b/crates/fj-window/src/run.rs index 350216313..8d101dc26 100644 --- a/crates/fj-window/src/run.rs +++ b/crates/fj-window/src/run.rs @@ -50,27 +50,36 @@ pub fn run( trace!("Handling event: {:?}", event); if let Some(watcher) = &watcher { - if let Some(new_shape) = watcher.receive(&mut status) { - match shape_processor.process(&new_shape) { - Ok(new_shape) => { - viewer.handle_shape_update(new_shape); - } - Err(err) => { - // Can be cleaned up, once `Report` is stable: - // https://doc.rust-lang.org/std/error/struct.Report.html + match watcher.receive_shape(&mut status) { + Ok(shape) => { + if let Some(shape) = shape { + match shape_processor.process(&shape) { + Ok(shape) => { + viewer.handle_shape_update(shape); + } + Err(err) => { + // Can be cleaned up, once `Report` is stable: + // https://doc.rust-lang.org/std/error/struct.Report.html - println!("Shape processing error: {}", err); + println!("Shape processing error: {}", err); - let mut current_err = &err as &dyn error::Error; - while let Some(err) = current_err.source() { - println!(); - println!("Caused by:"); - println!(" {}", err); + let mut current_err = &err as &dyn error::Error; + while let Some(err) = current_err.source() { + println!(); + println!("Caused by:"); + println!(" {}", err); - current_err = err; + current_err = err; + } + } } } } + Err(err) => { + println!("Error receiving updated shape: {}", err); + *control_flow = ControlFlow::Exit; + return; + } } }