Skip to content

Commit c4e29bd

Browse files
committed
JSCBC-1524: Surface C++ exceptions at entry points as JS errors
Changes ------- * Define `NODE_ADDON_API_CPP_EXCEPTIONS` and `NODE_ADDON_API_CPP_EXCEPTIONS_ALL`, so the exception mode is explicit and every entry point turns any C++ exception that escapes it into a thrown JS error rather than aborting the process * Report a core exception thrown by a transaction operation that cannot start through the operation's callback, so it rejects with the usual typed error and the callback runs exactly once * Convert transaction operation arguments before creating the callback cookie, so a bad argument throws with no cookie to resolve * Add tests for a CAS string that is not a 64-bit number and for transaction operations made before any attempt Change-Id: I3518304a9edebd856c459ac67fa109593e154f7e Reviewed-on: https://review.couchbase.org/c/couchnode/+/256435 Tested-by: Jared Casey <jared.casey@couchbase.com> Reviewed-by: Mateusz <matt.wozakowski@couchbase.com>
1 parent ad15c97 commit c4e29bd

4 files changed

Lines changed: 302 additions & 133 deletions

File tree

‎CMakeLists.txt‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ file(GLOB SOURCE_FILES "src/*.cpp")
203203
add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES} ${CMAKE_JS_SRC})
204204
target_compile_definitions(${PROJECT_NAME} PRIVATE COUCHBASE_CXX_CLIENT_IGNORE_CORE_DEPRECATIONS)
205205
add_definitions(-DNAPI_VERSION=6)
206+
# Build node-addon-api with C++ exceptions, and have every entry point turn any
207+
# C++ exception that escapes it into a thrown JS error. Without the second, only
208+
# a Napi::Error is translated, and any other exception aborts the process.
209+
add_definitions(-DNODE_ADDON_API_CPP_EXCEPTIONS)
210+
add_definitions(-DNODE_ADDON_API_CPP_EXCEPTIONS_ALL)
206211
# A callback that reaches JS while a worker is terminating cannot throw. Without
207212
# this, node-addon-api aborts the process building the error instead.
208213
add_definitions(-DNODE_API_SWALLOW_UNTHROWABLE_EXCEPTIONS)

0 commit comments

Comments
 (0)