Skip to content
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

add From<GlobError> for io::Error impl #64

Open
vitiral opened this issue Jan 29, 2018 · 3 comments
Open

add From<GlobError> for io::Error impl #64

vitiral opened this issue Jan 29, 2018 · 3 comments

Comments

@vitiral
Copy link
Contributor

vitiral commented Jan 29, 2018

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 😄

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
Copy link
Contributor Author

vitiral commented Jan 29, 2018

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!

@mendess
Copy link

mendess commented Jun 27, 2020

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

@LukasKalbertodt
Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants