mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
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: https://github.com/nodejs/node/pull/13087 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
This commit is contained in:
1 parent
3702ae732e
commit
a63b245b0a
2 files changed
+9
-1
No files matched your search
+1
-1
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user