pub struct Error { /* private fields */ }
Expand description
A structure to represent errors coming out of libgit2.
Implementations
sourceimpl Error
impl Error
sourcepub fn new<S: AsRef<str>>(
code: ErrorCode,
class: ErrorClass,
message: S
) -> Self
pub fn new<S: AsRef<str>>(
code: ErrorCode,
class: ErrorClass,
message: S
) -> Self
Creates a new error.
This is mainly intended for implementors of custom transports or
database backends, where it is desirable to propagate an Error
through libgit2
.
sourcepub fn last_error(code: c_int) -> Option<Error>
pub fn last_error(code: c_int) -> Option<Error>
Returns the last error that happened with the code specified by code
.
The code
argument typically comes from the return value of a function
call. This code will later be returned from the code
function.
Historically this function returned Some
or None
based on the return
value of git_error_last
but nowadays it always returns Some
so it’s
safe to unwrap the return value. This API will change in the next major
version.
sourcepub fn from_str(s: &str) -> Error
pub fn from_str(s: &str) -> Error
Creates a new error from the given string as the error.
The error returned will have the code GIT_ERROR
and the class
GIT_ERROR_NONE
.
sourcepub fn code(&self) -> ErrorCode
pub fn code(&self) -> ErrorCode
Return the error code associated with this error.
An error code is intended to be programmatically actionable most of the
time. For example the code GIT_EAGAIN
indicates that an error could be
fixed by trying again, while the code GIT_ERROR
is more bland and
doesn’t convey anything in particular.
sourcepub fn set_code(&mut self, code: ErrorCode)
pub fn set_code(&mut self, code: ErrorCode)
Modify the error code associated with this error.
This is mainly intended to be used by implementors of custom transports or database backends, and should be used with care.
sourcepub fn class(&self) -> ErrorClass
pub fn class(&self) -> ErrorClass
Return the error class associated with this error.
Error classes are in general mostly just informative. For example the class will show up in the error message but otherwise an error class is typically not directly actionable.
sourcepub fn set_class(&mut self, class: ErrorClass)
pub fn set_class(&mut self, class: ErrorClass)
Modify the error class associated with this error.
This is mainly intended to be used by implementors of custom transports or database backends, and should be used with care.
sourcepub fn raw_code(&self) -> git_error_code
pub fn raw_code(&self) -> git_error_code
Return the raw error code associated with this error.
sourcepub fn raw_class(&self) -> git_error_t
pub fn raw_class(&self) -> git_error_t
Return the raw error class associated with this error.
Trait Implementations
sourceimpl Error for Error
impl Error for Error
1.30.0 · sourcefn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
The lower-level source of this error, if any. Read more
sourcefn backtrace(&self) -> Option<&Backtrace>
fn backtrace(&self) -> Option<&Backtrace>
backtrace
)Returns a stack backtrace, if available, of where this error occurred. Read more
1.0.0 · sourcefn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
sourceimpl From<JoinPathsError> for Error
impl From<JoinPathsError> for Error
sourcefn from(e: JoinPathsError) -> Error
fn from(e: JoinPathsError) -> Error
Converts to this type from the input type.
impl StructuralPartialEq for Error
Auto Trait Implementations
impl RefUnwindSafe for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl UnwindSafe for Error
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more