Skip to content

Commit 3626944

Browse files
joyeecheungBridgeAR
authored andcommitted
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: #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>
1 parent 5b8c62c commit 3626944

10 files changed

+36
-29
lines changed

doc/api/errors.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,11 +1474,11 @@ additional details.
14741474
A stream method was called that cannot complete because the stream was
14751475
destroyed using `stream.destroy()`.
14761476

1477-
<a id="ERR_STRING_TOO_LARGE"></a>
1478-
### ERR_STRING_TOO_LARGE
1477+
<a id="ERR_STRING_TOO_LONG"></a>
1478+
### ERR_STRING_TOO_LONG
14791479

1480-
An attempt has been made to create a string larger than the maximum allowed
1481-
size.
1480+
An attempt has been made to create a string longer than the maximum allowed
1481+
length.
14821482

14831483
<a id="ERR_TLS_CERT_ALTNAME_INVALID"></a>
14841484
### ERR_TLS_CERT_ALTNAME_INVALID

src/node_errors.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace node {
1818

1919
#define ERRORS_WITH_CODE(V) \
2020
V(ERR_MEMORY_ALLOCATION_FAILED, Error) \
21-
V(ERR_STRING_TOO_LARGE, Error) \
21+
V(ERR_STRING_TOO_LONG, Error) \
2222
V(ERR_BUFFER_TOO_LARGE, Error)
2323

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

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

6969
} // namespace node

src/string_bytes.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class ExternString: public ResourceType {
113113

114114
if (str.IsEmpty()) {
115115
delete h_str;
116-
*error = node::ERR_STRING_TOO_LARGE(isolate);
116+
*error = node::ERR_STRING_TOO_LONG(isolate);
117117
return MaybeLocal<Value>();
118118
}
119119

@@ -170,7 +170,7 @@ MaybeLocal<Value> ExternOneByteString::NewSimpleFromCopy(Isolate* isolate,
170170
v8::NewStringType::kNormal,
171171
length);
172172
if (str.IsEmpty()) {
173-
*error = node::ERR_STRING_TOO_LARGE(isolate);
173+
*error = node::ERR_STRING_TOO_LONG(isolate);
174174
return MaybeLocal<Value>();
175175
}
176176
return str.ToLocalChecked();
@@ -188,7 +188,7 @@ MaybeLocal<Value> ExternTwoByteString::NewSimpleFromCopy(Isolate* isolate,
188188
v8::NewStringType::kNormal,
189189
length);
190190
if (str.IsEmpty()) {
191-
*error = node::ERR_STRING_TOO_LARGE(isolate);
191+
*error = node::ERR_STRING_TOO_LONG(isolate);
192192
return MaybeLocal<Value>();
193193
}
194194
return str.ToLocalChecked();
@@ -657,7 +657,7 @@ MaybeLocal<Value> StringBytes::Encode(Isolate* isolate,
657657
v8::NewStringType::kNormal,
658658
buflen);
659659
if (val.IsEmpty()) {
660-
*error = node::ERR_STRING_TOO_LARGE(isolate);
660+
*error = node::ERR_STRING_TOO_LONG(isolate);
661661
return MaybeLocal<Value>();
662662
}
663663
return val.ToLocalChecked();

test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-ascii.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ const stringLengthHex = kStringMaxLength.toString(16);
2828
common.expectsError(function() {
2929
buf.toString('ascii');
3030
}, {
31-
message: `Cannot create a string larger than 0x${stringLengthHex} bytes`,
32-
code: 'ERR_STRING_TOO_LARGE',
31+
message: `Cannot create a string longer than 0x${stringLengthHex} ` +
32+
'characters',
33+
code: 'ERR_STRING_TOO_LONG',
3334
type: Error
3435
});

test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-base64.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ const stringLengthHex = kStringMaxLength.toString(16);
2828
common.expectsError(function() {
2929
buf.toString('base64');
3030
}, {
31-
message: `Cannot create a string larger than 0x${stringLengthHex} bytes`,
32-
code: 'ERR_STRING_TOO_LARGE',
31+
message: `Cannot create a string longer than 0x${stringLengthHex} ` +
32+
'characters',
33+
code: 'ERR_STRING_TOO_LONG',
3334
type: Error
3435
});

test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-binary.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ const stringLengthHex = kStringMaxLength.toString(16);
2929
common.expectsError(function() {
3030
buf.toString('latin1');
3131
}, {
32-
message: `Cannot create a string larger than 0x${stringLengthHex} bytes`,
33-
code: 'ERR_STRING_TOO_LARGE',
32+
message: `Cannot create a string longer than 0x${stringLengthHex} ` +
33+
'characters',
34+
code: 'ERR_STRING_TOO_LONG',
3435
type: Error
3536
});
3637

test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-hex.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ const stringLengthHex = kStringMaxLength.toString(16);
2828
common.expectsError(function() {
2929
buf.toString('hex');
3030
}, {
31-
message: `Cannot create a string larger than 0x${stringLengthHex} bytes`,
32-
code: 'ERR_STRING_TOO_LARGE',
31+
message: `Cannot create a string longer than 0x${stringLengthHex} ` +
32+
'characters',
33+
code: 'ERR_STRING_TOO_LONG',
3334
type: Error
3435
});

test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-utf8.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ assert.throws(function() {
3232
}, function(e) {
3333
if (e.message !== 'Array buffer allocation failed') {
3434
common.expectsError({
35-
message: `Cannot create a string larger than 0x${stringLengthHex} bytes`,
36-
code: 'ERR_STRING_TOO_LARGE',
35+
message: `Cannot create a string longer than 0x${stringLengthHex} ` +
36+
'characters',
37+
code: 'ERR_STRING_TOO_LONG',
3738
type: Error
3839
})(e);
3940
return true;
@@ -45,7 +46,8 @@ assert.throws(function() {
4546
common.expectsError(function() {
4647
buf.toString('utf8');
4748
}, {
48-
message: `Cannot create a string larger than 0x${stringLengthHex} bytes`,
49-
code: 'ERR_STRING_TOO_LARGE',
49+
message: `Cannot create a string longer than 0x${stringLengthHex} ` +
50+
'characters',
51+
code: 'ERR_STRING_TOO_LONG',
5052
type: Error
5153
});

test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ const stringLengthHex = kStringMaxLength.toString(16);
2929
common.expectsError(function() {
3030
buf.toString('utf16le');
3131
}, {
32-
message: `Cannot create a string larger than 0x${stringLengthHex} bytes`,
33-
code: 'ERR_STRING_TOO_LARGE',
32+
message: `Cannot create a string longer than 0x${stringLengthHex} ` +
33+
'characters',
34+
code: 'ERR_STRING_TOO_LONG',
3435
type: Error
3536
});

test/sequential/test-fs-readfile-tostring-fail.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ stream.on('finish', common.mustCall(function() {
3535
if (err.message !== 'Array buffer allocation failed') {
3636
const stringLengthHex = kStringMaxLength.toString(16);
3737
common.expectsError({
38-
message: 'Cannot create a string larger than ' +
39-
`0x${stringLengthHex} bytes`,
40-
code: 'ERR_STRING_TOO_LARGE',
38+
message: 'Cannot create a string longer than ' +
39+
`0x${stringLengthHex} characters`,
40+
code: 'ERR_STRING_TOO_LONG',
4141
type: Error
4242
})(err);
4343
}

0 commit comments

Comments
 (0)