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:
parent
5b8c62c60d
commit
362694401f
@ -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
|
||||
|
@ -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) \
|
||||
@ -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
|
||||
|
@ -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>();
|
||||
}
|
||||
|
||||
@ -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();
|
||||
@ -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();
|
||||
@ -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();
|
||||
|
@ -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
|
||||
});
|
||||
|
@ -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
|
||||
});
|
||||
|
@ -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
|
||||
});
|
||||
|
||||
|
@ -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
|
||||
});
|
||||
|
@ -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;
|
||||
@ -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
|
||||
});
|
||||
|
@ -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
|
||||
});
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user