push the error types conversion all the way through
This commit is contained in:
@@ -21,6 +21,9 @@ pub enum ErrorKind {
|
||||
/// Errno::Inval: Invalid argument
|
||||
#[error("Inval: Invalid argument")]
|
||||
Inval,
|
||||
/// Errno::Io: I/O error
|
||||
#[error("Io: I/O error")]
|
||||
Io,
|
||||
/// Errno::Nametoolong: Filename too long
|
||||
#[error("Nametoolong: Filename too long")]
|
||||
Nametoolong,
|
||||
@@ -50,6 +53,7 @@ pub trait ErrorExt {
|
||||
fn exist() -> Self;
|
||||
fn illegal_byte_sequence() -> Self;
|
||||
fn invalid_argument() -> Self;
|
||||
fn io() -> Self;
|
||||
fn name_too_long() -> Self;
|
||||
fn not_dir() -> Self;
|
||||
fn not_supported() -> Self;
|
||||
@@ -75,6 +79,9 @@ impl ErrorExt for Error {
|
||||
fn invalid_argument() -> Self {
|
||||
ErrorKind::Inval.into()
|
||||
}
|
||||
fn io() -> Self {
|
||||
ErrorKind::Io.into()
|
||||
}
|
||||
fn name_too_long() -> Self {
|
||||
ErrorKind::Nametoolong.into()
|
||||
}
|
||||
|
||||
@@ -79,6 +79,7 @@ impl From<ErrorKind> for types::Errno {
|
||||
ErrorKind::Exist => Errno::Exist,
|
||||
ErrorKind::Ilseq => Errno::Ilseq,
|
||||
ErrorKind::Inval => Errno::Inval,
|
||||
ErrorKind::Io => Errno::Io,
|
||||
ErrorKind::Nametoolong => Errno::Nametoolong,
|
||||
ErrorKind::Notdir => Errno::Notdir,
|
||||
ErrorKind::Notsup => Errno::Notsup,
|
||||
@@ -141,9 +142,15 @@ impl TryFrom<std::io::Error> for types::Errno {
|
||||
libc::EOVERFLOW => Ok(types::Errno::Overflow),
|
||||
libc::EILSEQ => Ok(types::Errno::Ilseq),
|
||||
libc::ENOTSUP => Ok(types::Errno::Notsup),
|
||||
_ => Err(anyhow!(err).context("Unknown raw OS error")),
|
||||
code => Err(anyhow!(err).context(format!("Unknown raw OS error: {}", code))),
|
||||
},
|
||||
None => match err.kind() {
|
||||
std::io::ErrorKind::NotFound => Ok(types::Errno::Noent),
|
||||
std::io::ErrorKind::PermissionDenied => Ok(types::Errno::Perm),
|
||||
std::io::ErrorKind::AlreadyExists => Ok(types::Errno::Exist),
|
||||
std::io::ErrorKind::InvalidInput => Ok(types::Errno::Ilseq),
|
||||
k => Err(anyhow!(err).context(format!("No raw OS error. Unhandled kind: {:?}", k))),
|
||||
},
|
||||
None => Err(anyhow!(err).context("No raw OS error")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user