D
Deno

help

rusty_v8 extracting stack trace when a promise rejects

AAV67/26/2023
Hi, i am trying to get the stack trace and print it out when a promise rejects.
if promise.state() == v8::PromiseState::Rejected {
let exception = promise.result(scope);
retval = exception.to_rust_string_lossy(scope);

if exception.is_native_error() {
//how to get the exception stack trace to print here?
// i have retval from above, but it is just the oneliner eg:TypeError: Assignment to constant variable.

}

if promise.state() == v8::PromiseState::Rejected {
let exception = promise.result(scope);
retval = exception.to_rust_string_lossy(scope);

if exception.is_native_error() {
//how to get the exception stack trace to print here?
// i have retval from above, but it is just the oneliner eg:TypeError: Assignment to constant variable.

}

in the above example, i have the retval as the exception string which contains something like TypeError: Assignment to constant variable.. But how do i extract exception stack trace and get the line number and other details as well from this?
Mmmastrac7/26/2023
I'm not totally sure, but can you just use the object getter for the stack property? I read the rusty_v8 docs a bit more, and it looks like you can use v8::Exception::stack_trace(scope, exception)
AAV67/27/2023
that doesnt seem to work. Tried it, it just gives out None

Looking for more? Join the community!