Follow-up for error messages in core (#2719)

* Fix tests

* Replace unwraps on RuntimeError with panics and add track_caller for better error output

* Convert more unwraps

* Fix git
This commit is contained in:
Matt Hunzinger authored and GitHub committed 2024-07-29 13:15:06 -07:00
1 parent a1dfc4b4f0
commit 6558fd95a2
9 files changed
+39 -17

No files matched your search

+9 -4
View File
@@ -7,6 +7,7 @@ use crate::ScopeId;
use futures_util::task::ArcWake;
use slotmap::DefaultKey;
use std::marker::PhantomData;
use std::panic;
use std::sync::Arc;
use std::task::Waker;
use std::{cell::Cell, future::Future};
@@ -76,21 +77,24 @@ impl Task {
}
/// Wake the task.
#[track_caller]
pub fn wake(&self) {
Runtime::with(|rt| {
_ = rt
.sender
.unbounded_send(SchedulerMsg::TaskNotified(self.id))
})
.unwrap();
.unwrap_or_else(|e| panic!("{}", e))
}
/// Poll the task immediately.
#[track_caller]
pub fn poll_now(&self) -> Poll<()> {
Runtime::with(|rt| rt.handle_task_wakeup(*self)).unwrap()
Runtime::with(|rt| rt.handle_task_wakeup(*self)).unwrap_or_else(|e| panic!("{}", e))
}
/// Set the task as active or paused.
#[track_caller]
pub fn set_active(&self, active: bool) {
Runtime::with(|rt| {
if let Some(task) = rt.tasks.borrow().get(self.id) {
@@ -102,7 +106,7 @@ impl Task {
}
}
})
.unwrap();
.unwrap_or_else(|e| panic!("{}", e))
}
}
@@ -247,11 +251,12 @@ impl Runtime {
self.tasks.borrow().get(task.id).map(|t| t.scope)
}
#[track_caller]
pub(crate) fn handle_task_wakeup(&self, id: Task) -> Poll<()> {
#[cfg(debug_assertions)]
{
// Ensure we are currently inside a `Runtime`.
Runtime::current().unwrap();
Runtime::current().unwrap_or_else(|e| panic!("{}", e));
}
let task = self.tasks.borrow().get(id.id).cloned();