Skip to content

Commit

Permalink
src: add error codes to errors thrown in node_i18n.cc
Browse files Browse the repository at this point in the history
PR-URL: nodejs#28221
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
  • Loading branch information
yanivfriedensohn authored and Trott committed Jun 21, 2019
1 parent 7334aaf commit e6edd66
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
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

0 comments on commit e6edd66

Please sign in to comment.