Skip to content
Merged
Changes from 2 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
28 changes: 24 additions & 4 deletions src/wavm/wavm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "WAVM/Runtime/Intrinsics.h"
#include "WAVM/Runtime/Linker.h"
#include "WAVM/Runtime/Runtime.h"
#include "WAVM/RuntimeABI/RuntimeABI.h"
#include "WAVM/WASM/WASM.h"
#include "WAVM/WASTParse/WASTParse.h"

Expand Down Expand Up @@ -90,16 +91,35 @@ namespace {
WAVM::Runtime::catchRuntimeExceptions( \
[&] { _x; }, \
[&](WAVM::Runtime::Exception *exception) { \
auto description = describeException(exception); \
_wavm->fail(FailState::RuntimeError, \
"Function: " + std::string(function_name) + " failed: " + description); \
destroyException(exception); \
_wavm->fail(FailState::RuntimeError, getFailMessage(function_name, exception)); \
throw std::exception(); \
}); \
} catch (...) { \
} \
} while (0)

std::string getFailMessage(std::string_view function_name, WAVM::Runtime::Exception *exception) {
std::string message = "Function " + std::string(function_name) +
" failed: " + WAVM::Runtime::describeExceptionType(exception->type) +
"\nProxy-Wasm plugin in-VM backtrace:\n";
std::vector<std::string> callstack_descriptions =
WAVM::Runtime::describeCallStack(exception->callStack);

// Since the first frame is on host and useless for developers, e.g.: `host!envoy+112901013`
Comment thread
mathetake marked this conversation as resolved.
// we start with index 1 here
for (size_t i = 1; i < callstack_descriptions.size(); i++) {
std::string description = callstack_descriptions[i];
if (description.find("wasm!") == std::string::npos) {
// end of WASM's call stack
break;
}
message += " " + std::to_string(i) + ": " + description + "\n";
Comment thread
mathetake marked this conversation as resolved.
Outdated
}

WAVM::Runtime::destroyException(exception);
return message;
}

struct WasmUntaggedValue : public WAVM::IR::UntaggedValue {
WasmUntaggedValue() = default;
WasmUntaggedValue(I32 inI32) { i32 = inI32; }
Expand Down