summaryrefslogtreecommitdiff
path: root/src/error.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/error.rs')
-rw-r--r--src/error.rs12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/error.rs b/src/error.rs
index 2499150..7ae0431 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -38,7 +38,7 @@ impl Error {
/// If the error code doesn't match then an approximation of the error
/// reason is used instead of the error message stored in the Session.
pub fn from_session_error(sess: &Session, rc: libc::c_int) -> Error {
- Self::from_session_error_raw(sess.raw(), rc)
+ Self::from_session_error_raw(&mut *sess.raw(), rc)
}
#[doc(hidden)]
@@ -59,7 +59,7 @@ impl Error {
///
/// Returns `None` if there was no last error.
pub fn last_error(sess: &Session) -> Option<Error> {
- Self::last_error_raw(sess.raw())
+ Self::last_error_raw(&mut *sess.raw())
}
/// Create a new error for the given code and message
@@ -80,6 +80,14 @@ impl Error {
Error::new(libc::c_int::min_value(), "no other error listed")
}
+ pub(crate) fn rc(rc: libc::c_int) -> Result<(), Error> {
+ if rc == 0 {
+ Ok(())
+ } else {
+ Err(Self::from_errno(rc))
+ }
+ }
+
/// Construct an error from an error code from libssh2
pub fn from_errno(code: libc::c_int) -> Error {
let msg = match code {