Skip to content

Error handling improvement: turn errors into terminal #87

@sagikazarmark

Description

@sagikazarmark

I've been experimenting with some error handling improvements.

One of them:

pub trait TerminalExt<T, E> {
    fn terminal(self) -> Result<T, HandlerError>;
    fn terminal_with_code(self, code: u16) -> Result<T, HandlerError>;
}

impl<T, E> TerminalExt<T, E> for Result<T, E>
where
    E: std::fmt::Display + std::fmt::Debug + Send + Sync + 'static,
{
    fn terminal(self) -> Result<T, HandlerError> {
        self.map_err(|err| TerminalError::new(err.to_string()).into())
    }

    fn terminal_with_code(self, code: u16) -> Result<T, HandlerError> {
        self.map_err(|err| TerminalError::new_with_code(code, err.to_string()).into())
    }
}

I can open a PR if this sound good to you to be included in the SDK.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions