diff --git a/crates/core/src/host/v8/error.rs b/crates/core/src/host/v8/error.rs index 1021f9c5f11..8365823ef3f 100644 --- a/crates/core/src/host/v8/error.rs +++ b/crates/core/src/host/v8/error.rs @@ -126,7 +126,9 @@ pub(super) struct JsError { impl fmt::Display for JsError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { writeln!(f, "js error {}", self.msg)?; - writeln!(f, "{}", self.trace)?; + if !f.alternate() { + writeln!(f, "{}", self.trace)?; + } Ok(()) } } @@ -249,6 +251,16 @@ impl JsError { } } +pub(super) fn log_traceback(func_type: &str, func: &str, e: &anyhow::Error) { + log::info!("{func_type} \"{func}\" runtime error: {e:#}"); + if let Some(js_err) = e.downcast_ref::() { + log::info!("js error {}", js_err.msg); + for (index, frame) in js_err.trace.frames.iter().enumerate() { + log::info!(" Frame #{index}: {frame}"); + } + } +} + /// Run `body` within a try-catch context and capture any JS exception thrown as a [`JsError`]. pub(super) fn catch_exception<'scope, T>( scope: &mut HandleScope<'scope>, diff --git a/crates/core/src/host/v8/mod.rs b/crates/core/src/host/v8/mod.rs index 92e1fb0c896..9e3c0cf429e 100644 --- a/crates/core/src/host/v8/mod.rs +++ b/crates/core/src/host/v8/mod.rs @@ -12,7 +12,7 @@ use crate::{host::Scheduler, module_host_context::ModuleCreationContext, replica use anyhow::anyhow; use core::time::Duration; use de::deserialize_js; -use error::{catch_exception, exception_already_thrown, ExcResult, Throwable}; +use error::{catch_exception, exception_already_thrown, log_traceback, ExcResult, Throwable}; use from_value::cast; use key_cache::get_or_create_key_cache; use ser::serialize_to_js; @@ -157,8 +157,7 @@ impl ModuleInstance for JsInstance { &self.replica_ctx.clone(), tx, params, - // TODO(centril): logging. - |_ty, _fun, _err| {}, + log_traceback, |tx, op, _budget| { let call_result = call_call_reducer_from_op(scope, op); // TODO(centril): energy metrering.