Skip to content

Commit

Permalink
added rust backtrace as stacktrace to JSError
Browse files Browse the repository at this point in the history
  • Loading branch information
andrieshiemstra committed Jun 1, 2024
1 parent 226cab0 commit 268ab10
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 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.4

* added rust backtrace to errors generated in rust

# 0.13.3

* added some debug info to async promise await code
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "quickjs_runtime"
version = "0.13.3"
version = "0.13.4"
authors = ["Andries Hiemstra <[email protected]>"]
edition = "2021"
description = "Wrapper API and utils for the QuickJS JavaScript engine with support for Promise, Modules, Async/await"
Expand Down
4 changes: 3 additions & 1 deletion src/jsutils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//! The facade classes are for use outside the worker thread, they are Send
//!

use backtrace::Backtrace;
use std::fmt::{Debug, Display, Error, Formatter};

pub mod helper_tasks;
Expand Down Expand Up @@ -71,10 +72,11 @@ impl JsError {
Self::new_string(err.to_string())
}
pub fn new_string(err: String) -> Self {
let bt = Backtrace::new();
JsError {
name: "Error".to_string(),
message: err,
stack: "".to_string(),
stack: format!("{bt:?}"),
}
}
pub fn get_message(&self) -> &str {
Expand Down
8 changes: 5 additions & 3 deletions src/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ impl CachedJsPromiseRef {

pub fn get_promise_result_sync(&self) -> Result<Result<JsValueFacade, JsValueFacade>, JsError> {
let rx = self.get_promise_result_receiver();
rx.recv().map_err(|e| JsError::new_string(format!("{e}")))?
rx.recv()
.map_err(|e| JsError::new_string(format!("get_promise_result_sync/1: {e}")))?
}

pub fn get_promise_result_sync_timeout(
Expand All @@ -216,9 +217,10 @@ impl CachedJsPromiseRef {
let rx = self.get_promise_result_receiver();
let res = if let Some(timeout) = timeout {
rx.recv_timeout(timeout)
.map_err(|e| JsError::new_string(format!("{e}")))
.map_err(|e| JsError::new_string(format!("get_promise_result_sync_timeout/1: {e}")))
} else {
rx.recv().map_err(|e| JsError::new_string(format!("{e}")))
rx.recv()
.map_err(|e| JsError::new_string(format!("get_promise_result_sync_timeout/2: {e}")))
};
res?
}
Expand Down

0 comments on commit 268ab10

Please sign in to comment.