diff --git a/src/error.rs b/src/error.rs index 2eb11c93..8973b3e3 100644 --- a/src/error.rs +++ b/src/error.rs @@ -108,8 +108,7 @@ pub(crate) enum ErrorKind { NotSupported, InvalidArgument, SafetyViolation, - BadSymlinkStack, - ParseError, + InternalError, // TODO: We might want to use Option? OsError(Option), } @@ -121,12 +120,16 @@ impl ErrorImpl { Self::NotSupported { .. } => ErrorKind::NotSupported, Self::InvalidArgument { .. } => ErrorKind::InvalidArgument, Self::SafetyViolation { .. } => ErrorKind::SafetyViolation, - Self::BadSymlinkStackError { .. } => ErrorKind::BadSymlinkStack, - Self::ParseIntError(_) => ErrorKind::ParseError, + // Any syscall-related errors get mapped to an OsError, since the + // distinction doesn't matter to users checking error values. Self::OsError { source, .. } => ErrorKind::OsError(source.raw_os_error()), Self::RawOsError { source, .. } => { ErrorKind::OsError(source.root_cause().raw_os_error()) } + // These errors are internal error types that we don't want to + // expose outside of the crate. All that matters to users is that + // there was some internal error. + Self::BadSymlinkStackError { .. } | Self::ParseIntError(_) => ErrorKind::InternalError, Self::Wrapped { source, .. } => source.kind(), } } diff --git a/src/tests/capi/utils.rs b/src/tests/capi/utils.rs index ed5ff075..9d41dcfd 100644 --- a/src/tests/capi/utils.rs +++ b/src/tests/capi/utils.rs @@ -72,7 +72,7 @@ impl ErrorImpl for CapiError { // TODO: We should probably have an actual "no-op" error here that // is unused except for these tests so we can properly detect // a bad ErrorKind. - ErrorKind::ParseError + ErrorKind::InternalError } } } diff --git a/src/utils/sysctl.rs b/src/utils/sysctl.rs index a8936b6d..1255708d 100644 --- a/src/utils/sysctl.rs +++ b/src/utils/sysctl.rs @@ -114,7 +114,7 @@ mod tests { super::sysctl_read_parse::(&GLOBAL_PROCFS_HANDLE, "kernel.printk") .as_ref() .map_err(Error::kind), - Err(ErrorKind::ParseError), + Err(ErrorKind::InternalError), "parsing line from multi-number sysctl", ); } @@ -126,7 +126,7 @@ mod tests { super::sysctl_read_parse::(&GLOBAL_PROCFS_HANDLE, "kernel.random.uuid") .as_ref() .map_err(Error::kind), - Err(ErrorKind::ParseError), + Err(ErrorKind::InternalError), "parsing line from non-number sysctl", ); }