Skip to content

Commit

Permalink
Merge pull request #1234 from hannobraun/host
Browse files Browse the repository at this point in the history
Rename `Watcher::receive`; improve its error handling
  • Loading branch information
hannobraun authored Oct 19, 2022
2 parents b20a96e + 5e2fbec commit 8632b06
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
13 changes: 8 additions & 5 deletions crates/fj-host/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<fj::Shape> {
pub fn receive_shape(
&self,
status: &mut StatusReport,
) -> Result<Option<fj::Shape>, Error> {
match self.channel.try_recv() {
Ok(()) => {
let shape = match self.model.load_once(&self.parameters, status)
Expand All @@ -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
Expand Down
39 changes: 24 additions & 15 deletions crates/fj-window/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand Down

0 comments on commit 8632b06

Please sign in to comment.