matklad / xshell

Apache License 2.0
696 stars 30 forks source link

impl kind() for Error #70

Open csmoe opened 1 year ago

csmoe commented 1 year ago

add a method to get xshell error kind, the ErrorKind is marked as private intentionally, but sometimes we might wanna recover from certain exit_status.

matklad commented 1 year ago

Urgh, sorry, missed notification!

In principle, I think we should expose more information about the errors here, but I think we should do this in a more formward-compatible and scalable way.

In particular, exposing kinds which also carry data is a compatability hasard. The trick with the Error/ErrorKind pattern is that the kind is field-less enum, and can be evolved independently.

So I think we shuold do roughly the following:

pub enum ErrorKind {
   ExitCode,
   NonUtf8,
   NoSuchDir,
   ...
}
static_assert(size_of::<ErrorKind> == 1);

impl Error {
    pub fn io_error(&self) -> Option<&io::Error>
}
matklad commented 1 year ago

this should handle https://github.com/matklad/xshell/issues/46