Skip to content

Commit f0f26ce

Browse files
committed
n-api: remove code from error name
This is a first step to align the n-api errors towards errors created in JS. The stack still has to be updated to add the error code. PR-URL: #26738 Fixes: #26669 Fixes: #20253 Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
1 parent e96e3f9 commit f0f26ce

File tree

2 files changed

+3
-30
lines changed

2 files changed

+3
-30
lines changed

src/js_native_api_v8.cc

-27
Original file line numberDiff line numberDiff line change
@@ -1532,33 +1532,6 @@ static inline napi_status set_error_code(napi_env env,
15321532
RETURN_STATUS_IF_FALSE(env,
15331533
set_maybe.FromMaybe(false),
15341534
napi_generic_failure);
1535-
1536-
// now update the name to be "name [code]" where name is the
1537-
// original name and code is the code associated with the Error
1538-
v8::Local<v8::String> name_string;
1539-
CHECK_NEW_FROM_UTF8(env, name_string, "");
1540-
v8::Local<v8::Name> name_key;
1541-
CHECK_NEW_FROM_UTF8(env, name_key, "name");
1542-
1543-
auto maybe_name = err_object->Get(context, name_key);
1544-
if (!maybe_name.IsEmpty()) {
1545-
v8::Local<v8::Value> name = maybe_name.ToLocalChecked();
1546-
if (name->IsString()) {
1547-
name_string =
1548-
v8::String::Concat(isolate, name_string, name.As<v8::String>());
1549-
}
1550-
}
1551-
name_string = v8::String::Concat(
1552-
isolate, name_string, NAPI_FIXED_ONE_BYTE_STRING(isolate, " ["));
1553-
name_string =
1554-
v8::String::Concat(isolate, name_string, code_value.As<v8::String>());
1555-
name_string = v8::String::Concat(
1556-
isolate, name_string, NAPI_FIXED_ONE_BYTE_STRING(isolate, "]"));
1557-
1558-
set_maybe = err_object->Set(context, name_key, name_string);
1559-
RETURN_STATUS_IF_FALSE(env,
1560-
set_maybe.FromMaybe(false),
1561-
napi_generic_failure);
15621535
}
15631536
return napi_ok;
15641537
}

test/js-native-api/test_error/test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -118,18 +118,18 @@ error = test_error.createErrorCode();
118118
assert.ok(error instanceof Error, 'expected error to be an instance of Error');
119119
assert.strictEqual(error.code, 'ERR_TEST_CODE');
120120
assert.strictEqual(error.message, 'Error [error]');
121-
assert.strictEqual(error.name, 'Error [ERR_TEST_CODE]');
121+
assert.strictEqual(error.name, 'Error');
122122

123123
error = test_error.createRangeErrorCode();
124124
assert.ok(error instanceof RangeError,
125125
'expected error to be an instance of RangeError');
126126
assert.strictEqual(error.message, 'RangeError [range error]');
127127
assert.strictEqual(error.code, 'ERR_TEST_CODE');
128-
assert.strictEqual(error.name, 'RangeError [ERR_TEST_CODE]');
128+
assert.strictEqual(error.name, 'RangeError');
129129

130130
error = test_error.createTypeErrorCode();
131131
assert.ok(error instanceof TypeError,
132132
'expected error to be an instance of TypeError');
133133
assert.strictEqual(error.message, 'TypeError [type error]');
134134
assert.strictEqual(error.code, 'ERR_TEST_CODE');
135-
assert.strictEqual(error.name, 'TypeError [ERR_TEST_CODE]');
135+
assert.strictEqual(error.name, 'TypeError');

0 commit comments

Comments
 (0)