src: rename ERR_STRING_TOO_LARGE to ERR_STRING_TOO_LONG

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: https://github.com/nodejs/node/pull/19864
Refs: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Joyee Cheung 2018-04-07 20:36:33 +08:00 committed by Ruben Bridgewater
parent 5b8c62c60d
commit 362694401f
No known key found for this signature in database
GPG Key ID: F07496B3EB3C1762
10 changed files with 36 additions and 29 deletions

View File

@ -1474,11 +1474,11 @@ additional details.
A stream method was called that cannot complete because the stream was A stream method was called that cannot complete because the stream was
destroyed using `stream.destroy()`. destroyed using `stream.destroy()`.
<a id="ERR_STRING_TOO_LARGE"></a> <a id="ERR_STRING_TOO_LONG"></a>
### ERR_STRING_TOO_LARGE ### ERR_STRING_TOO_LONG
An attempt has been made to create a string larger than the maximum allowed An attempt has been made to create a string longer than the maximum allowed
size. length.
<a id="ERR_TLS_CERT_ALTNAME_INVALID"></a> <a id="ERR_TLS_CERT_ALTNAME_INVALID"></a>
### ERR_TLS_CERT_ALTNAME_INVALID ### ERR_TLS_CERT_ALTNAME_INVALID

View File

@ -18,7 +18,7 @@ namespace node {
#define ERRORS_WITH_CODE(V) \ #define ERRORS_WITH_CODE(V) \
V(ERR_MEMORY_ALLOCATION_FAILED, Error) \ V(ERR_MEMORY_ALLOCATION_FAILED, Error) \
V(ERR_STRING_TOO_LARGE, Error) \ V(ERR_STRING_TOO_LONG, Error) \
V(ERR_BUFFER_TOO_LARGE, Error) V(ERR_BUFFER_TOO_LARGE, Error)
#define V(code, type) \ #define V(code, type) \
@ -58,12 +58,12 @@ inline v8::Local<v8::Value> ERR_BUFFER_TOO_LARGE(v8::Isolate *isolate) {
return ERR_BUFFER_TOO_LARGE(isolate, message); 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]; char message[128];
snprintf(message, sizeof(message), 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); v8::String::kMaxLength);
return ERR_STRING_TOO_LARGE(isolate, message); return ERR_STRING_TOO_LONG(isolate, message);
} }
} // namespace node } // namespace node

View File

@ -113,7 +113,7 @@ class ExternString: public ResourceType {
if (str.IsEmpty()) { if (str.IsEmpty()) {
delete h_str; delete h_str;
*error = node::ERR_STRING_TOO_LARGE(isolate); *error = node::ERR_STRING_TOO_LONG(isolate);
return MaybeLocal<Value>(); return MaybeLocal<Value>();
} }
@ -170,7 +170,7 @@ MaybeLocal<Value> ExternOneByteString::NewSimpleFromCopy(Isolate* isolate,
v8::NewStringType::kNormal, v8::NewStringType::kNormal,
length); length);
if (str.IsEmpty()) { if (str.IsEmpty()) {
*error = node::ERR_STRING_TOO_LARGE(isolate); *error = node::ERR_STRING_TOO_LONG(isolate);
return MaybeLocal<Value>(); return MaybeLocal<Value>();
} }
return str.ToLocalChecked(); return str.ToLocalChecked();
@ -188,7 +188,7 @@ MaybeLocal<Value> ExternTwoByteString::NewSimpleFromCopy(Isolate* isolate,
v8::NewStringType::kNormal, v8::NewStringType::kNormal,
length); length);
if (str.IsEmpty()) { if (str.IsEmpty()) {
*error = node::ERR_STRING_TOO_LARGE(isolate); *error = node::ERR_STRING_TOO_LONG(isolate);
return MaybeLocal<Value>(); return MaybeLocal<Value>();
} }
return str.ToLocalChecked(); return str.ToLocalChecked();
@ -657,7 +657,7 @@ MaybeLocal<Value> StringBytes::Encode(Isolate* isolate,
v8::NewStringType::kNormal, v8::NewStringType::kNormal,
buflen); buflen);
if (val.IsEmpty()) { if (val.IsEmpty()) {
*error = node::ERR_STRING_TOO_LARGE(isolate); *error = node::ERR_STRING_TOO_LONG(isolate);
return MaybeLocal<Value>(); return MaybeLocal<Value>();
} }
return val.ToLocalChecked(); return val.ToLocalChecked();

View File

@ -28,7 +28,8 @@ const stringLengthHex = kStringMaxLength.toString(16);
common.expectsError(function() { common.expectsError(function() {
buf.toString('ascii'); buf.toString('ascii');
}, { }, {
message: `Cannot create a string larger than 0x${stringLengthHex} bytes`, message: `Cannot create a string longer than 0x${stringLengthHex} ` +
code: 'ERR_STRING_TOO_LARGE', 'characters',
code: 'ERR_STRING_TOO_LONG',
type: Error type: Error
}); });

View File

@ -28,7 +28,8 @@ const stringLengthHex = kStringMaxLength.toString(16);
common.expectsError(function() { common.expectsError(function() {
buf.toString('base64'); buf.toString('base64');
}, { }, {
message: `Cannot create a string larger than 0x${stringLengthHex} bytes`, message: `Cannot create a string longer than 0x${stringLengthHex} ` +
code: 'ERR_STRING_TOO_LARGE', 'characters',
code: 'ERR_STRING_TOO_LONG',
type: Error type: Error
}); });

View File

@ -29,8 +29,9 @@ const stringLengthHex = kStringMaxLength.toString(16);
common.expectsError(function() { common.expectsError(function() {
buf.toString('latin1'); buf.toString('latin1');
}, { }, {
message: `Cannot create a string larger than 0x${stringLengthHex} bytes`, message: `Cannot create a string longer than 0x${stringLengthHex} ` +
code: 'ERR_STRING_TOO_LARGE', 'characters',
code: 'ERR_STRING_TOO_LONG',
type: Error type: Error
}); });

View File

@ -28,7 +28,8 @@ const stringLengthHex = kStringMaxLength.toString(16);
common.expectsError(function() { common.expectsError(function() {
buf.toString('hex'); buf.toString('hex');
}, { }, {
message: `Cannot create a string larger than 0x${stringLengthHex} bytes`, message: `Cannot create a string longer than 0x${stringLengthHex} ` +
code: 'ERR_STRING_TOO_LARGE', 'characters',
code: 'ERR_STRING_TOO_LONG',
type: Error type: Error
}); });

View File

@ -32,8 +32,9 @@ assert.throws(function() {
}, function(e) { }, function(e) {
if (e.message !== 'Array buffer allocation failed') { if (e.message !== 'Array buffer allocation failed') {
common.expectsError({ common.expectsError({
message: `Cannot create a string larger than 0x${stringLengthHex} bytes`, message: `Cannot create a string longer than 0x${stringLengthHex} ` +
code: 'ERR_STRING_TOO_LARGE', 'characters',
code: 'ERR_STRING_TOO_LONG',
type: Error type: Error
})(e); })(e);
return true; return true;
@ -45,7 +46,8 @@ assert.throws(function() {
common.expectsError(function() { common.expectsError(function() {
buf.toString('utf8'); buf.toString('utf8');
}, { }, {
message: `Cannot create a string larger than 0x${stringLengthHex} bytes`, message: `Cannot create a string longer than 0x${stringLengthHex} ` +
code: 'ERR_STRING_TOO_LARGE', 'characters',
code: 'ERR_STRING_TOO_LONG',
type: Error type: Error
}); });

View File

@ -29,7 +29,8 @@ const stringLengthHex = kStringMaxLength.toString(16);
common.expectsError(function() { common.expectsError(function() {
buf.toString('utf16le'); buf.toString('utf16le');
}, { }, {
message: `Cannot create a string larger than 0x${stringLengthHex} bytes`, message: `Cannot create a string longer than 0x${stringLengthHex} ` +
code: 'ERR_STRING_TOO_LARGE', 'characters',
code: 'ERR_STRING_TOO_LONG',
type: Error type: Error
}); });

View File

@ -35,9 +35,9 @@ stream.on('finish', common.mustCall(function() {
if (err.message !== 'Array buffer allocation failed') { if (err.message !== 'Array buffer allocation failed') {
const stringLengthHex = kStringMaxLength.toString(16); const stringLengthHex = kStringMaxLength.toString(16);
common.expectsError({ common.expectsError({
message: 'Cannot create a string larger than ' + message: 'Cannot create a string longer than ' +
`0x${stringLengthHex} bytes`, `0x${stringLengthHex} characters`,
code: 'ERR_STRING_TOO_LARGE', code: 'ERR_STRING_TOO_LONG',
type: Error type: Error
})(err); })(err);
} }