Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion crates/core/src/host/v8/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
}
Expand Down Expand Up @@ -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::<JsError>() {
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>,
Expand Down
5 changes: 2 additions & 3 deletions crates/core/src/host/v8/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
Loading