summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/error.rs5
-rw-r--r--src/util.rs2
2 files changed, 6 insertions, 1 deletions
diff --git a/src/error.rs b/src/error.rs
index 7019aa9..e402010 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -44,6 +44,11 @@ impl Error {
Error::new(raw::LIBSSH2_ERROR_CHANNEL_EOF_SENT, "end of file")
}
+ /// Generate an error for unknown failure
+ pub fn unknown() -> Error {
+ Error::new(libc::c_int::min_value(), "no other error listed")
+ }
+
/// Construct an error from an error code from libssh2
pub fn from_errno(code: libc::c_int) -> Error {
let msg = match code {
diff --git a/src/util.rs b/src/util.rs
index 1955431..31637dc 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -20,7 +20,7 @@ pub trait SessionBinding<'sess>: Sized {
unsafe fn from_raw_opt(sess: &'sess Session, raw: *mut Self::Raw)
-> Result<Self, Error> {
if raw.is_null() {
- Err(Error::last_error(sess).unwrap())
+ Err(Error::last_error(sess).unwrap_or_else(Error::unknown))
} else {
Ok(SessionBinding::from_raw(sess, raw))
}