"stash" (...) ErrorContext::set_err
This commit is contained in:
parent
c9b566fc11
commit
5930db8233
1 changed files with 25 additions and 0 deletions
|
|
@ -180,11 +180,36 @@ impl ErrorContext {
|
||||||
/// `nix_clear_err` only modifies the `last_err_code`, it does not
|
/// `nix_clear_err` only modifies the `last_err_code`, it does not
|
||||||
/// clear all attributes of a `nix_c_context` struct. Hence all uses
|
/// clear all attributes of a `nix_c_context` struct. Hence all uses
|
||||||
/// of `nix_c_context` must be careful to check the `last_err_code` regularly.
|
/// of `nix_c_context` must be careful to check the `last_err_code` regularly.
|
||||||
|
///
|
||||||
pub fn clear(&mut self) {
|
pub fn clear(&mut self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
sys::nix_clear_err(self.as_ptr());
|
sys::nix_clear_err(self.as_ptr());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// This function never fails.
|
||||||
|
/// Nixide will always guarantee `context != nullptr`.
|
||||||
|
///
|
||||||
|
/// # Nix C++ API Internals
|
||||||
|
///
|
||||||
|
/// ```cpp
|
||||||
|
/// nix_err nix_set_err_msg(nix_c_context * context, nix_err err, const char * msg)
|
||||||
|
/// {
|
||||||
|
/// if (context == nullptr) {
|
||||||
|
/// // todo last_err_code
|
||||||
|
/// throw nix::Error("Nix C api error: %s", msg);
|
||||||
|
/// }
|
||||||
|
/// context->last_err_code = err;
|
||||||
|
/// context->last_err = msg;
|
||||||
|
/// return err;
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
pub fn set_err(&self, err: NixError, msg: &str) {
|
||||||
|
let ptr = unsafe { self.as_ptr() };
|
||||||
|
assert!(!ptr.is_null(), "");
|
||||||
|
|
||||||
|
sys::nix_set_err_msg(ptr, err.into())
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns [None] if [self.code] is [sys::nix_err_NIX_OK], and [Some] otherwise.
|
/// Returns [None] if [self.code] is [sys::nix_err_NIX_OK], and [Some] otherwise.
|
||||||
///
|
///
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue