Skip to content

Commit

Permalink
[WASM] improve error logging
Browse files Browse the repository at this point in the history
Summary: Emscripten instead of errors returns to JS pointer to error. To get meaningful message we need to pass this pointer back to C++, read value from it and return `error.what()` as string.

Test Plan:
1. Add this code `auto x =  SQLiteQueryExecutor::getStorage().get<Draft>("123");` and check if error from `ORM` is visible:
{F985698}
2. Add this code `throw std::runtime_error("TEST ERROR");` and check if error is visible:
{F985697}
3. Use null pointer
4. User not existing pointer

Reviewers: tomek, michal, marcin

Reviewed By: tomek

Subscribers: ashoat

Differential Revision: https://phab.comm.dev/D10396
  • Loading branch information
xsanm committed Dec 19, 2023
1 parent 692ce23 commit c2b8eac
Show file tree
Hide file tree
Showing 6 changed files with 172 additions and 121 deletions.
14 changes: 14 additions & 0 deletions web/cpp/SQLiteQueryExecutorBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,21 @@ namespace comm {

using namespace emscripten;

std::string getExceptionMessage(int exceptionPtr) {
if (exceptionPtr == 0) {
return std::string("Exception pointer value was null");
}

std::exception *e = reinterpret_cast<std::exception *>(exceptionPtr);
if (e) {
return std::string(e->what());
}
return std::string("Pointer to exception was invalid");
}

EMSCRIPTEN_BINDINGS(SQLiteQueryExecutor) {
function("getExceptionMessage", &getExceptionMessage);

value_object<NullableString>("NullableString")
.field("value", &NullableString::value)
.field("isNull", &NullableString::isNull);
Expand Down
Loading

0 comments on commit c2b8eac

Please sign in to comment.