You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: utilities/src/errors.rs
+92-5Lines changed: 92 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,16 @@
14
14
// limitations under the License.
15
15
16
16
use colored::Colorize;
17
-
use std::borrow::Borrow;
17
+
18
+
use std::{any::Any, backtrace::Backtrace, borrow::Borrow, cell::Cell, panic};
19
+
20
+
thread_local!{
21
+
/// The message backtrace of the last panic on this thread (if any).
22
+
///
23
+
/// We store this information here instead of directly processing it in a panic hook, because panic hooks are global whereas this can be processed on a per-thread basis.
24
+
/// For example, one thread may execute a program where panics should *not* cause the entire process to terminate, while in another thread there is a panic due to a bug.
/// Creates a panic with the `anyhow::Error` nicely formatted.
84
103
#[track_caller]
85
104
#[inline]
86
105
fnpretty_panic(error:&anyhow::Error) -> ! {
@@ -97,6 +116,7 @@ impl<T> PrettyUnwrap for anyhow::Result<T> {
97
116
typeInner = T;
98
117
99
118
#[track_caller]
119
+
#[inline]
100
120
fnpretty_unwrap(self) -> Self::Inner{
101
121
matchself{
102
122
Ok(result) => result,
@@ -117,9 +137,59 @@ impl<T> PrettyUnwrap for anyhow::Result<T> {
117
137
}
118
138
}
119
139
140
+
/// `try_vm_runtime` executes the given closure in an environment which will safely halt
141
+
/// without producing logs that look like unexpected behavior.
142
+
/// In debug mode, it prints to stderr using the format: "VM safely halted at {location}: {halt message}".
143
+
///
144
+
/// Note: For this to work as expected, panics must be set to `unwind` during compilation (default), and the closure cannot invoke any async code that may potentially execute in a different OS thread.
0 commit comments