Skip to content

Commit 0b68a1b

Browse files
committed
core/io: Improve error handling
1 parent 91a2c3c commit 0b68a1b

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

core/io/clock.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,17 @@ impl std::ops::Add<Duration> for Instant {
7272
type Output = Instant;
7373

7474
fn add(self, rhs: Duration) -> Self::Output {
75-
self.checked_add_duration(&rhs).unwrap()
75+
self.checked_add_duration(&rhs)
76+
.expect("duration addition overflow")
7677
}
7778
}
7879

7980
impl std::ops::Sub<Duration> for Instant {
8081
type Output = Instant;
8182

8283
fn sub(self, rhs: Duration) -> Self::Output {
83-
self.checked_sub_duration(&rhs).unwrap()
84+
self.checked_sub_duration(&rhs)
85+
.expect("duration subtraction underflow")
8486
}
8587
}
8688

core/io/completions.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,9 @@ impl Completion {
272272
}
273273

274274
pub(super) fn get_inner(&self) -> &Arc<CompletionInner> {
275-
self.inner.as_ref().unwrap()
275+
self.inner
276+
.as_ref()
277+
.expect("completion inner should be initialized")
276278
}
277279

278280
pub fn needs_link(&self) -> bool {

core/io/memory.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,12 @@ impl IO for MemoryIO {
5959
}),
6060
);
6161
}
62-
Ok(files.get(path).unwrap().clone())
62+
Ok(files
63+
.get(path)
64+
.ok_or(crate::LimboError::InternalError(
65+
"file should exist after insert".to_string(),
66+
))?
67+
.clone())
6368
}
6469
fn remove_file(&self, path: &str) -> Result<()> {
6570
let mut files = self.files.lock();

0 commit comments

Comments
 (0)