AV6
AV613mo ago

rusty_v8 extracting stack trace when a promise rejects

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?
2 Replies
mmastrac
mmastrac13mo ago
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)
AV6
AV613mo ago
that doesnt seem to work. Tried it, it just gives out None