Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Dawson <mdawson@devrus.com>2021-10-14 17:28:38 +0300
committerMichael Dawson <mdawson@devrus.com>2021-10-20 23:01:50 +0300
commitf27f8d256e1370cb464764f3369b74200c798839 (patch)
treee43e2c87105aa084e2739455598030249a8dd890 /doc/api/n-api.md
parent516cdcd8aaf4c693711d3359bcd45e0dac568b0c (diff)
doc: clarify behavior of napi_extended_error_info
Fix up example and make it more explicit on how you need to use napi_extended_error_info in order to help people avoid what might be a common mistake that we made in node-addon-api. Refs: https://github.com/nodejs/node-addon-api/issues/1089 Signed-off-by: Michael Dawson <mdawson@devrus.com> PR-URL: https://github.com/nodejs/node/pull/40458 Reviewed-By: Gabriel Schulhof <gabrielschulhof@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com>
Diffstat (limited to 'doc/api/n-api.md')
-rw-r--r--doc/api/n-api.md12
1 files changed, 9 insertions, 3 deletions
diff --git a/doc/api/n-api.md b/doc/api/n-api.md
index 7bddf9a7df8..0c0b9110947 100644
--- a/doc/api/n-api.md
+++ b/doc/api/n-api.md
@@ -403,12 +403,13 @@ napi_value create_addon(napi_env env);
if (status != napi_ok) { \
const napi_extended_error_info* error_info = NULL; \
napi_get_last_error_info((env), &error_info); \
+ const char* err_message = error_info->error_message; \
bool is_pending; \
napi_is_exception_pending((env), &is_pending); \
if (!is_pending) { \
- const char* message = (error_info->error_message == NULL) \
+ const char* message = (err_message == NULL) \
? "empty error message" \
- : error_info->error_message; \
+ : err_message; \
napi_throw_error((env), NULL, message); \
return NULL; \
} \
@@ -1005,7 +1006,12 @@ This API retrieves a `napi_extended_error_info` structure with information
about the last error that occurred.
The content of the `napi_extended_error_info` returned is only valid up until
-a Node-API function is called on the same `env`.
+a Node-API function is called on the same `env`. This includes a call to
+`napi_is_exception_pending` so it may often be necessary to make a copy
+of the information so that it can be used later. The pointer returned
+in error_message points to a statically defined string so it is safe to use
+that pointer if you have copied it out of the error_message field (which will
+be overwritten) before another Node-API function was called.
Do not rely on the content or format of any of the extended information as it
is not subject to SemVer and may change at any time. It is intended only for