Skip to content

uucore: strip_errno strips everything after the os error #13723

Description

@Devel08

in #13720 we have an error that has some text after the os error, thus when we use strip_errno() on it, we lose the text after it
mktemp: Permission denied (os error 13) at path "/tmp.haKXBI6xNU" becomes mktemp: Permission denied.

we can do something like

pub fn strip_errno(err: &std::io::Error) -> String {
    let msg = err.to_string();

    if let Some((before, rest)) = msg.split_once(" (os error ") {
        if let Some((_, after)) = rest.split_once(')') {
            return format!("{}{}", before, after);
        }
    }
    msg
}

which passes all the rust tests

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