close
Skip to content

Error handling IO Errors vs Higher level errors. #202

@vikigenius

Description

@vikigenius

I am creating an event source to handle IPC Events by reading a socket:

pub struct IPCSource {
    socket_source: calloop::generic::Generic<UnixListener>,
}

impl calloop::EventSource for IPCSource {
    type Event = Message; // Change this
    type Metadata = ();
    type Ret = Result<(), IPCError>;
    type Error = IPCError;
}

My problem is that the socket_souce.process_events callback expects to return Result<PostAction, std::io::Error> but the IPCSource callback needs to return IPCError

        self.socket_source
            .process_events(readiness, token, |socket_readiness, socket| {
                if socket_readiness.readable {
                    for stream in socket.incoming() {
                       // Would like to call the callback here
                       // But all errors should be io:Error
                    }
                }
                Ok(calloop::PostAction::Continue)
            });

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions