Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: add error codes to errors thrown in node_i18n.cc #28221

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/node_i18n.cc
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ static void ToUnicode(const FunctionCallbackInfo<Value>& args) {
int32_t len = ToUnicode(&buf, *val, val.length());

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

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

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

args.GetReturnValue().Set(
Expand Down
12 changes: 8 additions & 4 deletions test/parallel/test-icu-punycode.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ const wptToASCIITests = require(
}

{
const errMessage = /^Error: Cannot convert name to ASCII$/;

for (const [i, test] of wptToASCIITests.entries()) {
if (typeof test === 'string')
continue; // skip comments
Expand All @@ -43,8 +41,14 @@ const wptToASCIITests = require(
if (comment)
caseComment += ` (${comment})`;
if (output === null) {
assert.throws(() => icu.toASCII(input),
errMessage, `ToASCII ${caseComment}`);
common.expectsError(
() => icu.toASCII(input),
{
code: 'ERR_INVALID_ARG_VALUE',
type: TypeError,
message: 'Cannot convert name to ASCII'
}
);
icu.toASCII(input, true); // Should not throw.
} else {
assert.strictEqual(icu.toASCII(input), output, `ToASCII ${caseComment}`);
Expand Down