glob icon indicating copy to clipboard operation
glob copied to clipboard

add `From<GlobError> for io::Error` impl

Open vitiral opened this issue 7 years ago • 3 comments

The conversion I would suggest is:

impl From<GlobError> for io::Error {
    fn from(err: GobError) -> io::Error {
        io::Error::new(err.error.kind(), err)
    }
}

This will keep the "pretty context" so that glob errors keep printing as:

"attempting to read `{}` resulted in an error: {}",
self.path.display(),
self.error

Which is already very ergonomic.

I can do this if you OK it :smile:

Benefits / Justification

The glob error is already essentially an io::Error with a bit of additional context. This will allow functions that return io::Error can use glob with ? directly which incurs (basically) no performance issues.

vitiral avatar Jan 29 '18 01:01 vitiral

Secondary point: I prefer the format "{err} while reading {path}". This is the format that path_abs uses. If you were okay with it I would like to change it, but it really isn't important.

Also, any opinion about that format would be appreciated... I could still improve it!

vitiral avatar Jan 29 '18 01:01 vitiral

I would like to have this feature too. Can I implement it myself and open a pull request? This issue seems to have become stale

mendess avatar Jun 27 '20 20:06 mendess

Orphan rules won't allow us to add impl From<glob::Error> for io::Error in this crate. We could add the Into impl, but that wouldn't work with ? as far as I know.

@mendess have you seen #66 which adds into_error? Is that sufficient for you?

LukasKalbertodt avatar Jun 28 '20 18:06 LukasKalbertodt