Skip to content
Merged
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
15 changes: 9 additions & 6 deletions crates/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,19 @@ unsafe impl Sync for Cx {}
static CONTEXT: std::sync::OnceLock<Cx> = std::sync::OnceLock::new();
static CALL_ARGS: std::sync::Mutex<Vec<Vec<ArgType>>> = std::sync::Mutex::new(vec![]);

fn check_exception(this: &Ctx, err: rquickjs::Error) -> anyhow::Error {
let s = match err {
fn err_into_string(this: &Ctx, err: rquickjs::Error) -> String {
match err {
rquickjs::Error::Exception => {
let err = this.catch().into_exception().unwrap();
let msg = err.message().unwrap_or_default();
format!("Exception: {}\n{}", msg, err.stack().unwrap_or_default())
}
err => err.to_string(),
};
}
}

fn check_exception(this: &Ctx, err: rquickjs::Error) -> anyhow::Error {
let s = err_into_string(this, err);

let mem = extism_pdk::Memory::from_bytes(&s).unwrap();
unsafe {
Expand All @@ -43,9 +47,8 @@ extern "C" fn init() {

context
.with(|this| -> Result<rquickjs::Undefined, anyhow::Error> {
match this.eval(code) {
Ok(()) => (),
Err(err) => return Err(check_exception(&this, err)),
if let Err(err) = this.eval::<(), _>(code) {
panic!("{}", err_into_string(&this, err).to_string());
}

Ok(Undefined)
Expand Down
Loading