andrewhickman/fs-err

Use wrapper around std::io::Error instead of custom error type?

LPGhatguy opened this issue · 2 comments

Hello!

I created a similar wrapper to fs-err, but I took a slightly different approach. When using a custom error type, code that uses those I/O functions has return types that don't compose well with the io trait ecosystem like io::Write.

If we use io::Error's ability to hold other arbitrary error types though, we can still return io::Error but attach custom information with no loss of error handling ability.

Here's an implementation I did recently: https://github.com/rojo-rbx/foreman/blob/4cca3ba84025ef42eb458f2a8184f93a42915c15/src/fs.rs

I was going to make a crate for this last week, but then found fs-err! Do you think this strategy would work better, and if so, can I help move fs-err to that pattern?

Hi!

There is actually an implementation of From<fs_err::Error> for io::Error which does what you describe, so if you use ? in a function returning io::Error it should do the right thing.

That said the return types are a bit inconsistent - File::open returns an fs_err::Error whereas read returns an io::Error because its implemented in terms of io::Read. I wouldn't be opposed to just using io::Error everywhere, if you want to create a PR :)

Already on it! I'll see if I can get something compiling to send you over soon.