Skip to content

Commit

Permalink
src: rename ERR_STRING_TOO_LARGE to ERR_STRING_TOO_LONG
Browse files Browse the repository at this point in the history
The old error name and message were trying to be consistent with
ERR_BUFFER_TOO_LARGE but they were not really accurate.
The kStringMaxLength was measured in number of characters,
not number of bytes. The name ERR_STRING_TOO_LARGE also
seems a bit awkward. This patch tries to correct them before
they get released to users.

PR-URL: #19864
Refs: #19739
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
  • Loading branch information
joyeecheung authored and BridgeAR committed Apr 9, 2018
1 parent 5b8c62c commit 3626944
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 29 deletions.
8 changes: 4 additions & 4 deletions doc/api/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -1474,11 +1474,11 @@ additional details.
A stream method was called that cannot complete because the stream was
destroyed using `stream.destroy()`.

<a id="ERR_STRING_TOO_LARGE"></a>
### ERR_STRING_TOO_LARGE
<a id="ERR_STRING_TOO_LONG"></a>
### ERR_STRING_TOO_LONG

An attempt has been made to create a string larger than the maximum allowed
size.
An attempt has been made to create a string longer than the maximum allowed
length.

<a id="ERR_TLS_CERT_ALTNAME_INVALID"></a>
### ERR_TLS_CERT_ALTNAME_INVALID
Expand Down
8 changes: 4 additions & 4 deletions src/node_errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace node {

#define ERRORS_WITH_CODE(V) \
V(ERR_MEMORY_ALLOCATION_FAILED, Error) \
V(ERR_STRING_TOO_LARGE, Error) \
V(ERR_STRING_TOO_LONG, Error) \
V(ERR_BUFFER_TOO_LARGE, Error)

#define V(code, type) \
Expand Down Expand Up @@ -58,12 +58,12 @@ inline v8::Local<v8::Value> ERR_BUFFER_TOO_LARGE(v8::Isolate *isolate) {
return ERR_BUFFER_TOO_LARGE(isolate, message);
}

inline v8::Local<v8::Value> ERR_STRING_TOO_LARGE(v8::Isolate *isolate) {
inline v8::Local<v8::Value> ERR_STRING_TOO_LONG(v8::Isolate *isolate) {
char message[128];
snprintf(message, sizeof(message),
"Cannot create a string larger than 0x%x bytes",
"Cannot create a string longer than 0x%x characters",
v8::String::kMaxLength);
return ERR_STRING_TOO_LARGE(isolate, message);
return ERR_STRING_TOO_LONG(isolate, message);
}

} // namespace node
Expand Down
8 changes: 4 additions & 4 deletions src/string_bytes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class ExternString: public ResourceType {

if (str.IsEmpty()) {
delete h_str;
*error = node::ERR_STRING_TOO_LARGE(isolate);
*error = node::ERR_STRING_TOO_LONG(isolate);
return MaybeLocal<Value>();
}

Expand Down Expand Up @@ -170,7 +170,7 @@ MaybeLocal<Value> ExternOneByteString::NewSimpleFromCopy(Isolate* isolate,
v8::NewStringType::kNormal,
length);
if (str.IsEmpty()) {
*error = node::ERR_STRING_TOO_LARGE(isolate);
*error = node::ERR_STRING_TOO_LONG(isolate);
return MaybeLocal<Value>();
}
return str.ToLocalChecked();
Expand All @@ -188,7 +188,7 @@ MaybeLocal<Value> ExternTwoByteString::NewSimpleFromCopy(Isolate* isolate,
v8::NewStringType::kNormal,
length);
if (str.IsEmpty()) {
*error = node::ERR_STRING_TOO_LARGE(isolate);
*error = node::ERR_STRING_TOO_LONG(isolate);
return MaybeLocal<Value>();
}
return str.ToLocalChecked();
Expand Down Expand Up @@ -657,7 +657,7 @@ MaybeLocal<Value> StringBytes::Encode(Isolate* isolate,
v8::NewStringType::kNormal,
buflen);
if (val.IsEmpty()) {
*error = node::ERR_STRING_TOO_LARGE(isolate);
*error = node::ERR_STRING_TOO_LONG(isolate);
return MaybeLocal<Value>();
}
return val.ToLocalChecked();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ const stringLengthHex = kStringMaxLength.toString(16);
common.expectsError(function() {
buf.toString('ascii');
}, {
message: `Cannot create a string larger than 0x${stringLengthHex} bytes`,
code: 'ERR_STRING_TOO_LARGE',
message: `Cannot create a string longer than 0x${stringLengthHex} ` +
'characters',
code: 'ERR_STRING_TOO_LONG',
type: Error
});
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ const stringLengthHex = kStringMaxLength.toString(16);
common.expectsError(function() {
buf.toString('base64');
}, {
message: `Cannot create a string larger than 0x${stringLengthHex} bytes`,
code: 'ERR_STRING_TOO_LARGE',
message: `Cannot create a string longer than 0x${stringLengthHex} ` +
'characters',
code: 'ERR_STRING_TOO_LONG',
type: Error
});
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ const stringLengthHex = kStringMaxLength.toString(16);
common.expectsError(function() {
buf.toString('latin1');
}, {
message: `Cannot create a string larger than 0x${stringLengthHex} bytes`,
code: 'ERR_STRING_TOO_LARGE',
message: `Cannot create a string longer than 0x${stringLengthHex} ` +
'characters',
code: 'ERR_STRING_TOO_LONG',
type: Error
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ const stringLengthHex = kStringMaxLength.toString(16);
common.expectsError(function() {
buf.toString('hex');
}, {
message: `Cannot create a string larger than 0x${stringLengthHex} bytes`,
code: 'ERR_STRING_TOO_LARGE',
message: `Cannot create a string longer than 0x${stringLengthHex} ` +
'characters',
code: 'ERR_STRING_TOO_LONG',
type: Error
});
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ assert.throws(function() {
}, function(e) {
if (e.message !== 'Array buffer allocation failed') {
common.expectsError({
message: `Cannot create a string larger than 0x${stringLengthHex} bytes`,
code: 'ERR_STRING_TOO_LARGE',
message: `Cannot create a string longer than 0x${stringLengthHex} ` +
'characters',
code: 'ERR_STRING_TOO_LONG',
type: Error
})(e);
return true;
Expand All @@ -45,7 +46,8 @@ assert.throws(function() {
common.expectsError(function() {
buf.toString('utf8');
}, {
message: `Cannot create a string larger than 0x${stringLengthHex} bytes`,
code: 'ERR_STRING_TOO_LARGE',
message: `Cannot create a string longer than 0x${stringLengthHex} ` +
'characters',
code: 'ERR_STRING_TOO_LONG',
type: Error
});
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ const stringLengthHex = kStringMaxLength.toString(16);
common.expectsError(function() {
buf.toString('utf16le');
}, {
message: `Cannot create a string larger than 0x${stringLengthHex} bytes`,
code: 'ERR_STRING_TOO_LARGE',
message: `Cannot create a string longer than 0x${stringLengthHex} ` +
'characters',
code: 'ERR_STRING_TOO_LONG',
type: Error
});
6 changes: 3 additions & 3 deletions test/sequential/test-fs-readfile-tostring-fail.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ stream.on('finish', common.mustCall(function() {
if (err.message !== 'Array buffer allocation failed') {
const stringLengthHex = kStringMaxLength.toString(16);
common.expectsError({
message: 'Cannot create a string larger than ' +
`0x${stringLengthHex} bytes`,
code: 'ERR_STRING_TOO_LARGE',
message: 'Cannot create a string longer than ' +
`0x${stringLengthHex} characters`,
code: 'ERR_STRING_TOO_LONG',
type: Error
})(err);
}
Expand Down

0 comments on commit 3626944

Please sign in to comment.