add a noent / not_found errorkind

This commit is contained in:
Pat Hickey
2021-01-30 13:36:41 -08:00
parent c12cd82fc0
commit e940d31f95
3 changed files with 8 additions and 0 deletions

View File

@@ -6,6 +6,9 @@ pub use anyhow::Error;
#[derive(Debug, thiserror::Error)]
pub enum ErrorKind {
/// Errno::Noent: No such file or directory
#[error("Noent: No such file or directory")]
Noent,
/// Errno::TooBig: Argument list too long
#[error("TooBig: Argument list too long")]
TooBig,
@@ -49,6 +52,7 @@ pub enum ErrorKind {
pub trait ErrorExt {
fn trap(msg: impl Into<String>) -> Self;
fn not_found() -> Self;
fn too_big() -> Self;
fn badf() -> Self;
fn exist() -> Self;
@@ -68,6 +72,9 @@ impl ErrorExt for Error {
fn trap(msg: impl Into<String>) -> Self {
anyhow::anyhow!(msg.into())
}
fn not_found() -> Self {
ErrorKind::Noent.into()
}
fn too_big() -> Self {
ErrorKind::TooBig.into()
}

View File

@@ -73,6 +73,7 @@ impl From<ErrorKind> for types::Errno {
fn from(e: ErrorKind) -> types::Errno {
use types::Errno;
match e {
ErrorKind::Noent => Errno::Noent,
ErrorKind::TooBig => Errno::TooBig,
ErrorKind::Badf => Errno::Badf,
ErrorKind::Exist => Errno::Exist,