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

Improve error handling #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
32 changes: 22 additions & 10 deletions native/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,14 +405,7 @@ fn handle_client_outer(stream: UnixStream) {
if index.is_some() {
let index_guard = OpenedIndexCleanupGuard { index: index.unwrap() };
// now start servicing instance requests
let result = panic::catch_unwind(|| {
handle_client(index_guard,
reader,
connection_id);
});
if result.is_err() {
println!("panic happend!")
}
handle_client(index_guard, reader, connection_id);
}
{
// clean up message slot
Expand Down Expand Up @@ -496,8 +489,27 @@ fn handle_client(mut index: OpenedIndexCleanupGuard,
drop(index); // make sure index instance is closed first
return; // now we end the loop. The client will notice the socket close.
}
// process the message
let response = process_message(&mut index, msg);
// NOTE vmx 2017-12-05: I'm not really sure if passing on the `&mut index`
// is really safe. But it seems to work.
let result = panic::catch_unwind(panic::AssertUnwindSafe(|| {
// process the message
process_message(&mut index, msg)
}));

let response = match result {
Ok(resp) => resp,
Err(panic) => {
let msg = match panic.downcast::<String>() {
Ok(panic_msg) => {
format!("panic happened: {}", panic_msg)
},
Err(_) => {
"panic happened: unknown cause.".to_string()
},
};
Message::ResponseError(msg)
},
};

// put the response in the queue
{
Expand Down