Skip to content

Commit

Permalink
n-api: Retain last code when getting error info
Browse files Browse the repository at this point in the history
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 <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
  • Loading branch information
jasongin authored and mhdawson committed May 19, 2017
1 parent 3702ae7 commit a63b245
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/node_api.cc
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ napi_status napi_get_last_error_info(napi_env env,
error_messages[env->last_error.error_code]; error_messages[env->last_error.error_code];


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


napi_status napi_create_function(napi_env env, napi_status napi_create_function(napi_env env,
Expand Down
8 changes: 8 additions & 0 deletions test/addons-napi/test_napi_status/test_napi_status.cc
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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"); 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; return nullptr;
} }


Expand Down

0 comments on commit a63b245

Please sign in to comment.