From 0d489c8e04b83d58e638b1251e4a6636b8743146 Mon Sep 17 00:00:00 2001 From: Jason Ginchereau Date: Wed, 17 May 2017 16:56:37 -0700 Subject: [PATCH] n-api: Retain last code when getting error info Unlike most N-API functions, `napi_get_last_error_info()` should not clear the last error code when successful, because a pointer to (not a copy of) the error info structure is returned via an out parameter. --- src/node_api.cc | 2 +- test/addons-napi/test_napi_status/test_napi_status.cc | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/node_api.cc b/src/node_api.cc index 3a65862991c254..d0e535dca06c81 100644 --- a/src/node_api.cc +++ b/src/node_api.cc @@ -755,7 +755,7 @@ napi_status napi_get_last_error_info(napi_env env, error_messages[env->last_error.error_code]; *result = &(env->last_error); - return napi_clear_last_error(env); + return napi_ok; } napi_status napi_create_function(napi_env env, diff --git a/test/addons-napi/test_napi_status/test_napi_status.cc b/test/addons-napi/test_napi_status/test_napi_status.cc index 9046feffd4a15d..9e340aa46e106c 100644 --- a/test/addons-napi/test_napi_status/test_napi_status.cc +++ b/test/addons-napi/test_napi_status/test_napi_status.cc @@ -10,6 +10,14 @@ napi_value createNapiError(napi_env env, napi_callback_info info) { NAPI_ASSERT(env, status != napi_ok, "Failed to produce error condition"); + const napi_extended_error_info *error_info = 0; + NAPI_CALL(env, napi_get_last_error_info(env, &error_info)); + + NAPI_ASSERT(env, error_info->error_code == status, + "Last error info code should match last status"); + NAPI_ASSERT(env, error_info->error_message, + "Last error info message should not be null"); + return nullptr; }