diff --git a/nixide/src/errors/context.rs b/nixide/src/errors/context.rs index f04a10e..060ddd9 100644 --- a/nixide/src/errors/context.rs +++ b/nixide/src/errors/context.rs @@ -118,6 +118,8 @@ impl Into> for &ErrorContext { .unwrap_or_else(|| panic_issue_call_failed!()), }, + // XXX: WARNING: Recoverable only exists in later version of Nix + sys::NixErr::Recoverable => NixError::Recoverable, sys::NixErr::Unknown => NixError::Unknown, }; diff --git a/nixide/src/errors/nix_error.rs b/nixide/src/errors/nix_error.rs index a2c7789..23dfcf3 100644 --- a/nixide/src/errors/nix_error.rs +++ b/nixide/src/errors/nix_error.rs @@ -6,6 +6,22 @@ use crate::sys; /// produced by the libnix C API. #[derive(Debug, Clone)] pub enum NixError { + /// A recoverable error occurred. + /// + /// # Reason + /// + /// This is used primarily by C API *consumers* to communicate that a failed + /// primop call should be retried on the next evaluation attempt. + /// + /// # Nix C++ API Internals + /// + /// ```cpp + /// // `NIX_ERR_NIX_ERROR` variant of the `nix_err` enum type + /// NIX_ERR_RECOVERABLE = -4 + /// ``` + /// + Recoverable, + /// A generic Nix error occurred. /// /// # Reason @@ -19,6 +35,7 @@ pub enum NixError { /// // `NIX_ERR_NIX_ERROR` variant of the `nix_err` enum type /// NIX_ERR_NIX_ERROR = -4 /// ``` + /// ExprEval { name: String, info_msg: String }, /// A key/index access error occurred in C API functions. @@ -47,6 +64,7 @@ pub enum NixError { /// // `NIX_ERR_KEY` variant of the `nix_err` enum type /// NIX_ERR_KEY = -3 /// ``` + /// KeyNotFound(Option), /// An overflow error occurred. @@ -62,6 +80,7 @@ pub enum NixError { /// // `NIX_ERR_OVERFLOW` variant of the `nix_err` enum type /// NIX_ERR_OVERFLOW = -2 /// ``` + /// Overflow, /// An unknown error occurred. @@ -77,6 +96,7 @@ pub enum NixError { /// // `NIX_ERR_OVERFLOW` variant of the `nix_err` enum type /// NIX_ERR_UNKNOWN = -1 /// ``` + /// Unknown, /// @@ -95,12 +115,14 @@ pub enum NixError { /// This is solely a language difference between C++ and Rust, since /// [sys::NixErr] is defined over the *"continuous" (not realy)* /// type [::core::ffi::c_int]. + /// Undocumented(sys::NixErr), } impl Display for NixError { fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult { match self { + NixError::Recoverable => write!(f, "[libnix] Recoverable error occurred"), NixError::ExprEval { name, info_msg } => write!( f, "[libnix] NixExpr evaluation failed [name=\"{name}\", info_msg=\"{info_msg}\"]" @@ -120,12 +142,13 @@ impl Display for NixError { impl NixError { pub fn err_code(&self) -> sys::NixErr { match self { - NixError::Overflow => sys::NixErr::Overflow, - NixError::KeyNotFound(_) => sys::NixErr::Key, + NixError::Recoverable => sys::NixErr::Recoverable, NixError::ExprEval { name: _, info_msg: _, } => sys::NixErr::NixError, + NixError::KeyNotFound(_) => sys::NixErr::Key, + NixError::Overflow => sys::NixErr::Overflow, NixError::Unknown => sys::NixErr::NixError, NixError::Undocumented(err) => err.clone(), }