Exhaustive ErrorKind for linux errors

(Constraining the discussion to only linux)

We can get the errno from errno()

The decode_error_kind(errno: i32) -> ErrorKind function maps the libc::some_error_type to ErrorKind enum member.

Issue

The ErrorKind only defines I/O related errors. Non I/O Errors like ENOSPC or ECANCELED, etc are not part of ErrorKind.

Shouldn't the ErrorKind enum be expanded to include all errors so that we can also have to_string for each of them making error logging easier.

Error::to_string() should internally call strerror_r if it was derived from a libc error code. This will give the error code description irrespective of which ErrorKind it maps to.

Feels closely related to Tracking Issue for io_error_more · Issue #86442 · rust-lang/rust · GitHub, although I don't think that was going for exhaustive.

There are a bunch of errno codes that are defined only for backward source compat with obsolete oddities like RFS and STREAMS; current kernels will never generate them. I don't think we need those in ErrorKind. Unfortunately there's no easy way to know which ones they are.

1 Like