Skip to content

Commit e5f58ae

Browse files
committed
v8: add and use log_traceback
1 parent e0bfe00 commit e5f58ae

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

crates/core/src/host/v8/error.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@ pub(super) struct JsError {
126126
impl fmt::Display for JsError {
127127
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
128128
writeln!(f, "js error {}", self.msg)?;
129-
writeln!(f, "{}", self.trace)?;
129+
if !f.alternate() {
130+
writeln!(f, "{}", self.trace)?;
131+
}
130132
Ok(())
131133
}
132134
}
@@ -249,6 +251,16 @@ impl JsError {
249251
}
250252
}
251253

254+
pub(super) fn log_traceback(func_type: &str, func: &str, e: &anyhow::Error) {
255+
log::info!("{func_type} \"{func}\" runtime error: {e:#}");
256+
if let Some(js_err) = e.downcast_ref::<JsError>() {
257+
log::info!("js error {}", js_err.msg);
258+
for (index, frame) in js_err.trace.frames.iter().enumerate() {
259+
log::info!(" Frame #{index}: {frame}");
260+
}
261+
}
262+
}
263+
252264
/// Run `body` within a try-catch context and capture any JS exception thrown as a [`JsError`].
253265
pub(super) fn catch_exception<'scope, T>(
254266
scope: &mut HandleScope<'scope>,

crates/core/src/host/v8/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::{host::Scheduler, module_host_context::ModuleCreationContext, replica
1212
use anyhow::anyhow;
1313
use core::time::Duration;
1414
use de::deserialize_js;
15-
use error::{catch_exception, exception_already_thrown, ExcResult, Throwable};
15+
use error::{catch_exception, exception_already_thrown, log_traceback, ExcResult, Throwable};
1616
use from_value::cast;
1717
use key_cache::get_or_create_key_cache;
1818
use ser::serialize_to_js;
@@ -157,8 +157,7 @@ impl ModuleInstance for JsInstance {
157157
&self.replica_ctx.clone(),
158158
tx,
159159
params,
160-
// TODO(centril): logging.
161-
|_ty, _fun, _err| {},
160+
log_traceback,
162161
|tx, op, _budget| {
163162
let call_result = call_call_reducer_from_op(scope, op);
164163
// TODO(centril): energy metrering.

0 commit comments

Comments
 (0)