Skip to content
Browse files

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 <>
Reviewed-By: Colin Ihrig <>
Reviewed-By: Michael Dawson <>
  • Loading branch information...
jasongin authored and mhdawson committed May 17, 2017
1 parent 3702ae7 commit a63b245b0a0d15e9a494b3a4602031bfc6a51ff8
Showing with 9 additions and 1 deletion.
  1. +1 −1 src/
  2. +8 −0 test/addons-napi/test_napi_status/
@@ -755,7 +755,7 @@ napi_status napi_get_last_error_info(napi_env env,

*result = &(env->last_error);
return napi_clear_last_error(env);
return napi_ok;

napi_status napi_create_function(napi_env env,
@@ -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;

0 comments on commit a63b245

Please sign in to comment.
You can’t perform that action at this time.