Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andrieshiemstra committed Mar 15, 2024
1 parent 38f9693 commit 08d8dde
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.13.2 (WiP)

* add realm id to log on unhandled promises

# 0.13.1

* update quickjs-ng to 4.0.1
Expand Down
29 changes: 20 additions & 9 deletions src/quickjs_utils/promises.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,6 @@ unsafe extern "C" fn promise_rejection_tracker(
_opaque: *mut ::std::os::raw::c_void,
) {
if is_handled == 0 {
log::error!("unhandled promise rejection detected");

let reason_ref = QuickJsValueAdapter::new(
ctx,
reason,
Expand All @@ -242,14 +240,27 @@ unsafe extern "C" fn promise_rejection_tracker(
"promises::promise_rejection_tracker reason",
);
let reason_str_res = functions::call_to_string(ctx, &reason_ref);
match reason_str_res {
Ok(reason_str) => {
log::error!("unhandled promise rejection - reason: {}", reason_str);
}
Err(e) => {
log::error!("could not get reason: {}", e);
QuickJsRuntimeAdapter::do_with(|rt| {
let realm = rt.get_quickjs_context(ctx);
let realm_id = realm.get_realm_id();

match reason_str_res {
Ok(reason_str) => {
log::error!(
"[{}] unhandled promise rejection, reason: {}",
realm_id,
reason_str
);
}
Err(e) => {
log::error!(
"[{}] unhandled promise rejection, could not get reason: {}",
realm_id,
e
);
}
}
}
});
}
}

Expand Down

0 comments on commit 08d8dde

Please sign in to comment.