Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Watcher::receive; improve its error handling #1234

Merged
merged 5 commits into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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