66 restoreStdout,
77} = require ( '../common/hijackstdio' ) ;
88
9- const { internalBinding } = require ( 'internal/test/binding' ) ;
109const assert = require ( 'assert' ) ;
1110const errors = require ( 'internal/errors' ) ;
1211
@@ -101,125 +100,11 @@ common.expectsError(() => {
101100 message : / \+ m e s s a g e : ' E r r o r f o r t e s t i n g p u r p o s e s : a ' , \n - m e s s a g e : \/ \^ E r r o r /
102101} ) ;
103102
104- // Test ERR_INVALID_FD_TYPE
105- assert . strictEqual ( errors . getMessage ( 'ERR_INVALID_FD_TYPE' , [ 'a' ] ) ,
106- 'Unsupported fd type: a' ) ;
107-
108- // Test ERR_INVALID_URL_SCHEME
109- assert . strictEqual ( errors . getMessage ( 'ERR_INVALID_URL_SCHEME' , [ 'file' ] ) ,
110- 'The URL must be of scheme file' ) ;
111- assert . strictEqual ( errors . getMessage ( 'ERR_INVALID_URL_SCHEME' , [ [ 'file' ] ] ) ,
112- 'The URL must be of scheme file' ) ;
113- assert . strictEqual ( errors . getMessage ( 'ERR_INVALID_URL_SCHEME' ,
114- [ [ 'http' , 'ftp' ] ] ) ,
115- 'The URL must be one of scheme http or ftp' ) ;
116- assert . strictEqual ( errors . getMessage ( 'ERR_INVALID_URL_SCHEME' ,
117- [ [ 'a' , 'b' , 'c' ] ] ) ,
118- 'The URL must be one of scheme a, b, or c' ) ;
119- common . expectsError (
120- ( ) => errors . getMessage ( 'ERR_INVALID_URL_SCHEME' , [ [ ] ] ) ,
121- {
122- code : 'ERR_ASSERTION' ,
123- type : assert . AssertionError ,
124- message : / ^ A t l e a s t o n e e x p e c t e d v a l u e n e e d s t o b e s p e c i f i e d $ /
125- } ) ;
126-
127- // Test ERR_MISSING_ARGS
128- assert . strictEqual ( errors . getMessage ( 'ERR_MISSING_ARGS' , [ 'name' ] ) ,
129- 'The "name" argument must be specified' ) ;
130- assert . strictEqual ( errors . getMessage ( 'ERR_MISSING_ARGS' , [ 'name' , 'value' ] ) ,
131- 'The "name" and "value" arguments must be specified' ) ;
132- assert . strictEqual ( errors . getMessage ( 'ERR_MISSING_ARGS' , [ 'a' , 'b' , 'c' ] ) ,
133- 'The "a", "b", and "c" arguments must be specified' ) ;
134-
135- // Test ERR_SOCKET_BAD_PORT
136- assert . strictEqual (
137- errors . getMessage ( 'ERR_SOCKET_BAD_PORT' , [ 0 ] ) ,
138- 'Port should be >= 0 and < 65536. Received 0.' ) ;
139-
140- // Test ERR_TLS_CERT_ALTNAME_INVALID
141- assert . strictEqual (
142- errors . getMessage ( 'ERR_TLS_CERT_ALTNAME_INVALID' , [ 'altname' ] ) ,
143- 'Hostname/IP does not match certificate\'s altnames: altname' ) ;
144-
145- assert . strictEqual (
146- errors . getMessage ( 'ERR_INVALID_PROTOCOL' , [ 'bad protocol' , 'http' ] ) ,
147- 'Protocol "bad protocol" not supported. Expected "http"'
148- ) ;
149-
150- assert . strictEqual (
151- errors . getMessage ( 'ERR_HTTP_HEADERS_SENT' , [ 'render' ] ) ,
152- 'Cannot render headers after they are sent to the client'
153- ) ;
154-
155- assert . strictEqual (
156- errors . getMessage ( 'ERR_INVALID_HTTP_TOKEN' , [ 'Method' , 'foo' ] ) ,
157- 'Method must be a valid HTTP token ["foo"]'
158- ) ;
159-
160- assert . strictEqual (
161- errors . getMessage ( 'ERR_OUT_OF_RANGE' , [ 'A' , 'some values' , 'B' ] ) ,
162- 'The value of "A" is out of range. It must be some values. Received B'
163- ) ;
164-
165- assert . strictEqual (
166- errors . getMessage ( 'ERR_UNESCAPED_CHARACTERS' , [ 'Request path' ] ) ,
167- 'Request path contains unescaped characters'
168- ) ;
169-
170- // Test ERR_DNS_SET_SERVERS_FAILED
171- assert . strictEqual (
172- errors . getMessage ( 'ERR_DNS_SET_SERVERS_FAILED' , [ 'err' , 'servers' ] ) ,
173- 'c-ares failed to set servers: "err" [servers]' ) ;
174-
175- // Test ERR_ENCODING_NOT_SUPPORTED
176- assert . strictEqual (
177- errors . getMessage ( 'ERR_ENCODING_NOT_SUPPORTED' , [ 'enc' ] ) ,
178- 'The "enc" encoding is not supported' ) ;
179-
180- // Test error messages for async_hooks
181- assert . strictEqual (
182- errors . getMessage ( 'ERR_ASYNC_CALLBACK' , [ 'init' ] ) ,
183- 'init must be a function' ) ;
184- assert . strictEqual (
185- errors . getMessage ( 'ERR_ASYNC_TYPE' , [ { } ] ) ,
186- 'Invalid name for async "type": [object Object]' ) ;
187- assert . strictEqual (
188- errors . getMessage ( 'ERR_INVALID_ASYNC_ID' , [ 'asyncId' , undefined ] ) ,
189- 'Invalid asyncId value: undefined' ) ;
190-
191- {
192- const { kMaxLength } = internalBinding ( 'buffer' ) ;
193- const error = new errors . codes . ERR_BUFFER_TOO_LARGE ( ) ;
194- assert . strictEqual (
195- error . message ,
196- `Cannot create a Buffer larger than 0x${ kMaxLength . toString ( 16 ) } bytes`
197- ) ;
198- }
199-
200- {
201- const error = new errors . codes . ERR_INVALID_ARG_VALUE ( 'foo' , '\u0000bar' ) ;
202- assert . strictEqual (
203- error . message ,
204- 'The argument \'foo\' is invalid. Received \'\\u0000bar\''
205- ) ;
206- }
207-
208- {
209- const error = new errors . codes . ERR_INVALID_ARG_VALUE (
210- 'foo' , { a : 1 } , 'must have property \'b\''
211- ) ;
212- assert . strictEqual (
213- error . message ,
214- 'The argument \'foo\' must have property \'b\'. Received { a: 1 }'
215- ) ;
216- }
217-
218103// Test that `code` property is mutable and that changing it does not change the
219104// name.
220105{
221- const myError = new errors . codes . ERR_TLS_HANDSHAKE_TIMEOUT ( ) ;
222- assert . strictEqual ( myError . code , 'ERR_TLS_HANDSHAKE_TIMEOUT ' ) ;
106+ const myError = new errors . codes . TEST_ERROR_1 ( 'foo' ) ;
107+ assert . strictEqual ( myError . code , 'TEST_ERROR_1 ' ) ;
223108 assert . strictEqual ( myError . hasOwnProperty ( 'code' ) , false ) ;
224109 assert . strictEqual ( myError . hasOwnProperty ( 'name' ) , false ) ;
225110 assert . deepStrictEqual ( Object . keys ( myError ) , [ ] ) ;
@@ -228,15 +113,15 @@ assert.strictEqual(
228113 assert . strictEqual ( myError . code , 'FHQWHGADS' ) ;
229114 assert . strictEqual ( myError . name , initialName ) ;
230115 assert . deepStrictEqual ( Object . keys ( myError ) , [ 'code' ] ) ;
231- assert . ok ( myError . name . includes ( 'ERR_TLS_HANDSHAKE_TIMEOUT ' ) ) ;
116+ assert . ok ( myError . name . includes ( 'TEST_ERROR_1 ' ) ) ;
232117 assert . ok ( ! myError . name . includes ( 'FHQWHGADS' ) ) ;
233118}
234119
235120// Test that `name` is mutable and that changing it alters `toString()` but not
236121// `console.log()` results, which is the behavior of `Error` objects in the
237122// browser. Note that `name` becomes enumerable after being assigned.
238123{
239- const myError = new errors . codes . ERR_TLS_HANDSHAKE_TIMEOUT ( ) ;
124+ const myError = new errors . codes . TEST_ERROR_1 ( 'foo' ) ;
240125 assert . deepStrictEqual ( Object . keys ( myError ) , [ ] ) ;
241126 const initialToString = myError . toString ( ) ;
242127
@@ -251,7 +136,7 @@ assert.strictEqual(
251136{
252137 let initialConsoleLog = '' ;
253138 hijackStdout ( ( data ) => { initialConsoleLog += data ; } ) ;
254- const myError = new errors . codes . ERR_TLS_HANDSHAKE_TIMEOUT ( ) ;
139+ const myError = new errors . codes . TEST_ERROR_1 ( 'foo' ) ;
255140 assert . deepStrictEqual ( Object . keys ( myError ) , [ ] ) ;
256141 const initialToString = myError . toString ( ) ;
257142 console . log ( myError ) ;
@@ -269,13 +154,3 @@ assert.strictEqual(
269154
270155 restoreStdout ( ) ;
271156}
272-
273- {
274- const error = new errors . codes . ERR_WORKER_INVALID_EXEC_ARGV (
275- [ '--foo, --bar' ]
276- ) ;
277- assert . strictEqual (
278- error . message ,
279- 'Initiated Worker with invalid execArgv flags: --foo, --bar'
280- ) ;
281- }
0 commit comments