Skip to content

errors: port internal/buffer errors to internal/errors #11341

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

Closed
wants to merge 4 commits into from
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: 3 additions & 1 deletion lib/internal/buffer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const errors = require('internal/errors');

if (!process.binding('config').hasIntl) {
return;
}
Expand All @@ -24,7 +26,7 @@ exports.transcode = function transcode(source, fromEncoding, toEncoding) {
return result;

const code = icu.icuErrName(result);
const err = new Error(`Unable to transcode Buffer [${code}]`);
const err = new errors.Error('ERR_UNABlE_TRANSCODE_BUFFER', code);
err.code = code;
err.errno = result;
throw err;
Expand Down
1 change: 1 addition & 0 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,4 @@ module.exports = exports = {
// Note: Please try to keep these in alphabetical order
E('ERR_ASSERTION', (msg) => msg);
// Add new errors from here...
E('ERR_UNABlE_TRNSC_BUFF', `Unable to transcode Buffer [%s]`);
4 changes: 2 additions & 2 deletions test/parallel/test-icu-transcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ assert.throws(

assert.throws(
() => buffer.transcode(Buffer.from('a'), 'b', 'utf8'),
/^Error: Unable to transcode Buffer \[U_ILLEGAL_ARGUMENT_ERROR\]/
common.expectsError('ERR_UNABlE_TRANSCODE_BUFFER', Error)
);

assert.throws(
() => buffer.transcode(Buffer.from('a'), 'uf8', 'b'),
/^Error: Unable to transcode Buffer \[U_ILLEGAL_ARGUMENT_ERROR\]$/
common.expectsError('ERR_UNABlE_TRANSCODE_BUFFER', Error)
);

assert.deepStrictEqual(
Expand Down