Buffer: include encoding value in exception when invalid #4097

Closed
wants to merge 1 commit into from

2 participants

@rngadam

Encoding failures can be somewhat confusing, especially when they are due to control flow frameworks auto-filling parameters from the previous step output values to functions (such as toString and write) that developers don't expect to take an encoding parameter. By outputting the value as part of the message, should make it easier to track down these sort of bugs.

@bnoordhuis
Node.js Foundation member

Thanks, I'll land it but can you sign the CLA and reword the commit log so it follows our convention?

@langpavel langpavel commented on an outdated diff Oct 9, 2012
lib/buffer.js
@@ -459,7 +459,7 @@ Buffer.prototype.toString = function(encoding, start, end) {
return this.parent.ucs2Slice(start, end);
default:
- throw new Error('Unknown encoding');
+ throw new Error('Unknown encoding ' + encoding);

May be

throw new Error('Unknown encoding: ' + encoding);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@rngadam rngadam Buffer: include encoding value in exception when invalid.
Encoding failures can be somewhat confusing, especially when they are due to
control flow frameworks auto-filling parameters from the previous step output
values to functions (such as toString and write) that developers don't expect
to take an encoding parameter. By outputting the value as part of the message,
should make it easier to track down these sort of bugs.
756c33f
@rngadam

Signed the CLA (rngadam@lophilo.com), found a few more cases, added some tests, rewrote both the pull request and commit messages. Hopefully I didn't make too much of a mess.

@bnoordhuis
Node.js Foundation member

I reformatted the commit message a little but otherwise looks good. Landed in 8bd4590, thanks.

@bnoordhuis bnoordhuis closed this Oct 9, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment