Skip to content

Commit 0044fd2

Browse files
yanivfriedensohntargos
authored andcommitted
src: add error codes to errors thrown in node_i18n.cc
PR-URL: #28221 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 57ac661 commit 0044fd2

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/node_i18n.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ static void ToUnicode(const FunctionCallbackInfo<Value>& args) {
655655
int32_t len = ToUnicode(&buf, *val, val.length());
656656

657657
if (len < 0) {
658-
return env->ThrowError("Cannot convert name to Unicode");
658+
return THROW_ERR_INVALID_ARG_VALUE(env, "Cannot convert name to Unicode");
659659
}
660660

661661
args.GetReturnValue().Set(
@@ -678,7 +678,7 @@ static void ToASCII(const FunctionCallbackInfo<Value>& args) {
678678
int32_t len = ToASCII(&buf, *val, val.length(), mode);
679679

680680
if (len < 0) {
681-
return env->ThrowError("Cannot convert name to ASCII");
681+
return THROW_ERR_INVALID_ARG_VALUE(env, "Cannot convert name to ASCII");
682682
}
683683

684684
args.GetReturnValue().Set(

test/parallel/test-icu-punycode.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ const wptToASCIITests = require(
3333
}
3434

3535
{
36-
const errMessage = /^Error: Cannot convert name to ASCII$/;
37-
3836
for (const [i, test] of wptToASCIITests.entries()) {
3937
if (typeof test === 'string')
4038
continue; // skip comments
@@ -43,8 +41,14 @@ const wptToASCIITests = require(
4341
if (comment)
4442
caseComment += ` (${comment})`;
4543
if (output === null) {
46-
assert.throws(() => icu.toASCII(input),
47-
errMessage, `ToASCII ${caseComment}`);
44+
common.expectsError(
45+
() => icu.toASCII(input),
46+
{
47+
code: 'ERR_INVALID_ARG_VALUE',
48+
type: TypeError,
49+
message: 'Cannot convert name to ASCII'
50+
}
51+
);
4852
icu.toASCII(input, true); // Should not throw.
4953
} else {
5054
assert.strictEqual(icu.toASCII(input), output, `ToASCII ${caseComment}`);

0 commit comments

Comments
 (0)