-
Notifications
You must be signed in to change notification settings - Fork 36
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
Error handling IO Errors vs Higher level errors. #202
Comments
You can pass the error outside of the closure, like so: let mut err = None;
let action = self.socket_source.process_events(readiness, token, |_, _| {
match do_something() {
Ok(_) => Ok(PostAction::Continue),
Err(e) => {
err = Some(e);
Ok(PostAction::Continue)
}
}
})?;
err.map_or(Ok(action), Err) Does this work for you? |
Yup this does work. I did take a look at what the generic process_events is doing: // If the token is invalid or not ours, skip processing.
if self.token != Some(token) {
return Ok(PostAction::Continue);
}
callback(readiness, self.file.as_mut().unwrap()) This is not a lot. Can't I just directly get a reference to the underlying object |
You can yes, the main reason of this logic here is as a convenience for event sources that bundle multiple sub-sources (like monitoring multiple FDs for example), this checks makes sure that only the sub-sources that are actually ready are being processed. If this is a convenience you do not need, you can bypass it. |
I am creating an event source to handle IPC Events by reading a socket:
My problem is that the
socket_souce.process_events
callback expects to returnResult<PostAction, std::io::Error>
but the IPCSource callback needs to returnIPCError
I read the error handling chapter in the book: https://smithay.github.io/calloop/ch02-06-errors.html but it doesn't talk about the context of generic wrappers?
Should I be converting the IPCError to io:Error and then back to IPCError when returning from process_events?
Is there a more ergonomic way to do this?
How am I supposed to handle this?
The text was updated successfully, but these errors were encountered: