Skip to content

Commit 70281ba

Browse files
jasonginMylesBorins
authored andcommittedApr 16, 2018
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. Backport-PR-URL: #19447 PR-URL: #13087 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
1 parent 71aa251 commit 70281ba

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed
 

‎src/node_api.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ napi_status napi_get_last_error_info(napi_env env,
757757
error_messages[env->last_error.error_code];
758758

759759
*result = &(env->last_error);
760-
return napi_clear_last_error(env);
760+
return napi_ok;
761761
}
762762

763763
napi_status napi_create_function(napi_env env,

‎test/addons-napi/test_napi_status/test_napi_status.cc

+8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ napi_value createNapiError(napi_env env, napi_callback_info info) {
1010

1111
NAPI_ASSERT(env, status != napi_ok, "Failed to produce error condition");
1212

13+
const napi_extended_error_info *error_info = 0;
14+
NAPI_CALL(env, napi_get_last_error_info(env, &error_info));
15+
16+
NAPI_ASSERT(env, error_info->error_code == status,
17+
"Last error info code should match last status");
18+
NAPI_ASSERT(env, error_info->error_message,
19+
"Last error info message should not be null");
20+
1321
return nullptr;
1422
}
1523

0 commit comments

Comments
 (0)
Please sign in to comment.