Skip to content

Commit 8b68f6f

Browse files
authored
Improve panic message for tls::get failures (#11413)
Closes #11412
1 parent e90b1fb commit 8b68f6f

File tree

1 file changed

+17
-6
lines changed
  • crates/wasmtime/src/runtime/component/concurrent

1 file changed

+17
-6
lines changed

crates/wasmtime/src/runtime/component/concurrent/tls.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,27 @@ pub fn set<R>(store: &mut dyn VMStore, f: impl FnOnce() -> R) -> R {
7272
pub fn get<R>(f: impl FnOnce(&mut dyn VMStore) -> R) -> R {
7373
try_get(|val| match val {
7474
TryGet::Some(store) => f(store),
75-
TryGet::None | TryGet::Taken => get_failed(),
75+
TryGet::None => get_failed(false),
76+
TryGet::Taken => get_failed(true),
7677
})
7778
}
7879

7980
#[cold]
80-
fn get_failed() -> ! {
81-
panic!(
82-
"attempted to recursively call `tls::get` when the pointer was not \
83-
present or already taken by a previous call to `tls::get`"
84-
);
81+
fn get_failed(taken: bool) -> ! {
82+
if taken {
83+
panic!(
84+
"attempted to recursively call `Accessor::with` when the pointer \
85+
was already taken by a previous call to `Accessor::with`; try \
86+
using `RUST_BACKTRACE=1` to find two stack frames to \
87+
`Accessor::with` on the stack"
88+
);
89+
} else {
90+
panic!(
91+
"`Accessor::with` was called when the TLS pointer was not \
92+
previously set; this is likely a bug in Wasmtime and we would \
93+
appreciate an issue being filed to help fix this."
94+
);
95+
}
8596
}
8697

8798
/// Values yielded to the [`try_get`] closure as an argument.

0 commit comments

Comments
 (0)