Skip to content

Commit 92d96ac

Browse files
authored
Merge pull request #1072 from vcfxb/remove-error-unwraps
(Breaking Changes) Remove error unwraps
2 parents 8977c0c + 788306c commit 92d96ac

File tree

6 files changed

+7
-18
lines changed

6 files changed

+7
-18
lines changed

src/call.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ pub fn c_try(ret: libc::c_int) -> Result<libc::c_int, Error> {
4444
}
4545

4646
pub fn last_error(code: libc::c_int) -> Error {
47-
// nowadays this unwrap is safe as `Error::last_error` always returns
48-
// `Some`.
49-
Error::last_error(code).unwrap()
47+
Error::last_error(code)
5048
}
5149

5250
mod impls {

src/error.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,7 @@ impl Error {
3232
///
3333
/// The `code` argument typically comes from the return value of a function
3434
/// call. This code will later be returned from the `code` function.
35-
///
36-
/// Historically this function returned `Some` or `None` based on the return
37-
/// value of `git_error_last` but nowadays it always returns `Some` so it's
38-
/// safe to unwrap the return value. This API will change in the next major
39-
/// version.
40-
pub fn last_error(code: c_int) -> Option<Error> {
35+
pub fn last_error(code: c_int) -> Error {
4136
crate::init();
4237
unsafe {
4338
// Note that whenever libgit2 returns an error any negative value
@@ -64,7 +59,7 @@ impl Error {
6459
Error::from_raw(code, ptr)
6560
};
6661
raw::git_error_clear();
67-
Some(err)
62+
err
6863
}
6964
}
7065

src/indexer.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,7 @@ impl io::Write for Indexer<'_> {
188188

189189
let res = raw::git_indexer_append(self.raw, ptr, len, &mut self.progress);
190190
if res < 0 {
191-
Err(io::Error::new(
192-
io::ErrorKind::Other,
193-
Error::last_error(res).unwrap(),
194-
))
191+
Err(io::Error::new(io::ErrorKind::Other, Error::last_error(res)))
195192
} else {
196193
Ok(buf.len())
197194
}

src/odb.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ impl<'repo> OdbPackwriter<'repo> {
458458
};
459459

460460
if res < 0 {
461-
Err(Error::last_error(res).unwrap())
461+
Err(Error::last_error(res))
462462
} else {
463463
Ok(res)
464464
}

src/repo.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ impl Repository {
860860
match value {
861861
0 => Ok(false),
862862
1 => Ok(true),
863-
_ => Err(Error::last_error(value).unwrap()),
863+
_ => Err(Error::last_error(value)),
864864
}
865865
}
866866
}

src/tracing.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ pub fn trace_set(level: TraceLevel, cb: TracingCb) -> Result<(), Error> {
7676
let return_code: c_int = unsafe { raw::git_trace_set(level.raw(), Some(tracing_cb_c)) };
7777

7878
if return_code != 0 {
79-
// Unwrap here is fine since `Error::last_error` always returns `Some`.
80-
Err(Error::last_error(return_code).unwrap())
79+
Err(Error::last_error(return_code))
8180
} else {
8281
Ok(())
8382
}

0 commit comments

Comments
 (0)