diff options
author | Alexandre Bury <alexandre.bury@gmail.com> | 2017-04-13 10:08:45 -0700 |
---|---|---|
committer | Alexandre Bury <alexandre.bury@gmail.com> | 2017-04-13 10:08:45 -0700 |
commit | 165b413cf616533c6817dc9cf090d559e4e1dfe8 (patch) | |
tree | 790ba20a09292a4d25d169ad8e918acd457028b1 /src | |
parent | 064934737b0f214466e802b74195be1cd0c86735 (diff) | |
download | ssh2-rs-165b413cf616533c6817dc9cf090d559e4e1dfe8.zip |
Return unknown error when none is returned by last_error
Fixes #60
Diffstat (limited to 'src')
-rw-r--r-- | src/error.rs | 5 | ||||
-rw-r--r-- | src/util.rs | 2 |
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)) } |