Skip to content

Commit a63b245

Browse files
jasonginmhdawson
authored andcommitted
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. PR-URL: #13087 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
1 parent 3702ae7 commit a63b245

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
@@ -755,7 +755,7 @@ napi_status napi_get_last_error_info(napi_env env,
755755
error_messages[env->last_error.error_code];
756756

757757
*result = &(env->last_error);
758-
return napi_clear_last_error(env);
758+
return napi_ok;
759759
}
760760

761761
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)