-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherrors.html
More file actions
1941 lines (1918 loc) · 169 KB
/
errors.html
File metadata and controls
1941 lines (1918 loc) · 169 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Errors | Node.js v12.0.0 Documentation</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:400,700,400italic">
<link rel="stylesheet" href="assets/style.css">
<link rel="stylesheet" href="assets/hljs.css">
<link rel="canonical" href="https://nodejs.org/api/errors.html">
</head>
<body class="alt apidoc" id="api-section-errors">
<div id="content" class="clearfix">
<div id="column2" class="interior">
<div id="intro" class="interior">
<a href="/" title="Go back to the home page">
Node.js
</a>
</div>
<ul>
<li><a href="documentation.html" class="nav-documentation">About these Docs</a></li>
<li><a href="synopsis.html" class="nav-synopsis">Usage & Example</a></li>
</ul>
<div class="line"></div>
<ul>
<li><a href="assert.html" class="nav-assert">Assertion Testing</a></li>
<li><a href="async_hooks.html" class="nav-async_hooks">Async Hooks</a></li>
<li><a href="buffer.html" class="nav-buffer">Buffer</a></li>
<li><a href="addons.html" class="nav-addons">C++ Addons</a></li>
<li><a href="n-api.html" class="nav-n-api">C/C++ Addons - N-API</a></li>
<li><a href="child_process.html" class="nav-child_process">Child Processes</a></li>
<li><a href="cluster.html" class="nav-cluster">Cluster</a></li>
<li><a href="cli.html" class="nav-cli">Command Line Options</a></li>
<li><a href="console.html" class="nav-console">Console</a></li>
<li><a href="crypto.html" class="nav-crypto">Crypto</a></li>
<li><a href="debugger.html" class="nav-debugger">Debugger</a></li>
<li><a href="deprecations.html" class="nav-deprecations">Deprecated APIs</a></li>
<li><a href="dns.html" class="nav-dns">DNS</a></li>
<li><a href="domain.html" class="nav-domain">Domain</a></li>
<li><a href="esm.html" class="nav-esm">ECMAScript Modules</a></li>
<li><a href="errors.html" class="nav-errors active">Errors</a></li>
<li><a href="events.html" class="nav-events">Events</a></li>
<li><a href="fs.html" class="nav-fs">File System</a></li>
<li><a href="globals.html" class="nav-globals">Globals</a></li>
<li><a href="http.html" class="nav-http">HTTP</a></li>
<li><a href="http2.html" class="nav-http2">HTTP/2</a></li>
<li><a href="https.html" class="nav-https">HTTPS</a></li>
<li><a href="inspector.html" class="nav-inspector">Inspector</a></li>
<li><a href="intl.html" class="nav-intl">Internationalization</a></li>
<li><a href="modules.html" class="nav-modules">Modules</a></li>
<li><a href="net.html" class="nav-net">Net</a></li>
<li><a href="os.html" class="nav-os">OS</a></li>
<li><a href="path.html" class="nav-path">Path</a></li>
<li><a href="perf_hooks.html" class="nav-perf_hooks">Performance Hooks</a></li>
<li><a href="process.html" class="nav-process">Process</a></li>
<li><a href="punycode.html" class="nav-punycode">Punycode</a></li>
<li><a href="querystring.html" class="nav-querystring">Query Strings</a></li>
<li><a href="readline.html" class="nav-readline">Readline</a></li>
<li><a href="repl.html" class="nav-repl">REPL</a></li>
<li><a href="stream.html" class="nav-stream">Stream</a></li>
<li><a href="string_decoder.html" class="nav-string_decoder">String Decoder</a></li>
<li><a href="timers.html" class="nav-timers">Timers</a></li>
<li><a href="tls.html" class="nav-tls">TLS/SSL</a></li>
<li><a href="tracing.html" class="nav-tracing">Trace Events</a></li>
<li><a href="tty.html" class="nav-tty">TTY</a></li>
<li><a href="dgram.html" class="nav-dgram">UDP/Datagram</a></li>
<li><a href="url.html" class="nav-url">URL</a></li>
<li><a href="util.html" class="nav-util">Utilities</a></li>
<li><a href="v8.html" class="nav-v8">V8</a></li>
<li><a href="vm.html" class="nav-vm">VM</a></li>
<li><a href="worker_threads.html" class="nav-worker_threads">Worker Threads</a></li>
<li><a href="zlib.html" class="nav-zlib">ZLIB</a></li>
</ul>
<div class="line"></div>
<ul>
<li><a href="https://github.com/nodejs/node" class="nav-https-github-com-nodejs-node">GitHub Repo & Issue Tracker</a></li>
</ul>
</div>
<div id="column1" data-id="errors" class="interior">
<header>
<h1>Node.js v12.0.0 Documentation</h1>
<div id="gtoc">
<ul>
<li>
<a href="index.html" name="toc">Index</a>
</li>
<li>
<a href="all.html">View on single page</a>
</li>
<li>
<a href="errors.json">View as JSON</a>
</li>
<li class="version-picker">
<a href="#">View another version <span>▼</span></a>
<ol class="version-picker"><li><a href="https://nodejs.org/docs/latest-v11.x/api/errors.html">11.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v10.x/api/errors.html">10.x <b>LTS</b></a></li>
<li><a href="https://nodejs.org/docs/latest-v9.x/api/errors.html">9.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v8.x/api/errors.html">8.x <b>LTS</b></a></li>
<li><a href="https://nodejs.org/docs/latest-v7.x/api/errors.html">7.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v6.x/api/errors.html">6.x <b>LTS</b></a></li>
<li><a href="https://nodejs.org/docs/latest-v5.x/api/errors.html">5.x</a></li></ol>
</li>
<li class="edit_on_github"><a href="https://github.com/nodejs/node/edit/master/doc/api/errors.md"><span class="github_icon"><svg height="16" width="16" viewBox="0 0 16.1 16.1" fill="currentColor"><path d="M8 0a8 8 0 0 0-2.5 15.6c.4 0 .5-.2.5-.4v-1.5c-2 .4-2.5-.5-2.7-1 0-.1-.5-.9-.8-1-.3-.2-.7-.6 0-.6.6 0 1 .6 1.2.8.7 1.2 1.9 1 2.4.7 0-.5.2-.9.5-1-1.8-.3-3.7-1-3.7-4 0-.9.3-1.6.8-2.2 0-.2-.3-1 .1-2 0 0 .7-.3 2.2.7a7.4 7.4 0 0 1 4 0c1.5-1 2.2-.8 2.2-.8.5 1.1.2 2 .1 2.1.5.6.8 1.3.8 2.2 0 3-1.9 3.7-3.6 4 .3.2.5.7.5 1.4v2.2c0 .2.1.5.5.4A8 8 0 0 0 16 8a8 8 0 0 0-8-8z"/></svg></span>Edit on GitHub</a></li>
</ul>
</div>
<hr>
</header>
<div id="toc">
<h2>Table of Contents</h2>
<ul>
<li>
<p><a href="#errors_errors">Errors</a></p>
<ul>
<li>
<p><a href="#errors_error_propagation_and_interception">Error Propagation and Interception</a></p>
<ul>
<li><a href="#errors_error_first_callbacks">Error-first callbacks</a></li>
</ul>
</li>
<li>
<p><a href="#errors_class_error">Class: Error</a></p>
<ul>
<li><a href="#errors_new_error_message">new Error(message)</a></li>
<li><a href="#errors_error_capturestacktrace_targetobject_constructoropt">Error.captureStackTrace(targetObject[, constructorOpt])</a></li>
<li><a href="#errors_error_stacktracelimit">Error.stackTraceLimit</a></li>
<li><a href="#errors_error_code">error.code</a></li>
<li><a href="#errors_error_message">error.message</a></li>
<li><a href="#errors_error_stack">error.stack</a></li>
</ul>
</li>
<li><a href="#errors_class_assertionerror">Class: AssertionError</a></li>
<li><a href="#errors_class_rangeerror">Class: RangeError</a></li>
<li><a href="#errors_class_referenceerror">Class: ReferenceError</a></li>
<li><a href="#errors_class_syntaxerror">Class: SyntaxError</a></li>
<li><a href="#errors_class_typeerror">Class: TypeError</a></li>
<li><a href="#errors_exceptions_vs_errors">Exceptions vs. Errors</a></li>
<li>
<p><a href="#errors_system_errors">System Errors</a></p>
<ul>
<li>
<p><a href="#errors_class_systemerror">Class: SystemError</a></p>
<ul>
<li><a href="#errors_error_address">error.address</a></li>
<li><a href="#errors_error_code_1">error.code</a></li>
<li><a href="#errors_error_dest">error.dest</a></li>
<li><a href="#errors_error_errno">error.errno</a></li>
<li><a href="#errors_error_info">error.info</a></li>
<li><a href="#errors_error_message_1">error.message</a></li>
<li><a href="#errors_error_path">error.path</a></li>
<li><a href="#errors_error_port">error.port</a></li>
<li><a href="#errors_error_syscall">error.syscall</a></li>
</ul>
</li>
<li><a href="#errors_common_system_errors">Common System Errors</a></li>
</ul>
</li>
<li>
<p><a href="#errors_node_js_error_codes">Node.js Error Codes</a></p>
<ul>
<li><a href="#errors_err_ambiguous_argument">ERR_AMBIGUOUS_ARGUMENT</a></li>
<li><a href="#errors_err_arg_not_iterable">ERR_ARG_NOT_ITERABLE</a></li>
<li><a href="#errors_err_assertion">ERR_ASSERTION</a></li>
<li><a href="#errors_err_async_callback">ERR_ASYNC_CALLBACK</a></li>
<li><a href="#errors_err_async_type">ERR_ASYNC_TYPE</a></li>
<li><a href="#errors_err_buffer_context_not_available">ERR_BUFFER_CONTEXT_NOT_AVAILABLE</a></li>
<li><a href="#errors_err_buffer_out_of_bounds">ERR_BUFFER_OUT_OF_BOUNDS</a></li>
<li><a href="#errors_err_buffer_too_large">ERR_BUFFER_TOO_LARGE</a></li>
<li><a href="#errors_err_cannot_transfer_object">ERR_CANNOT_TRANSFER_OBJECT</a></li>
<li><a href="#errors_err_cannot_watch_sigint">ERR_CANNOT_WATCH_SIGINT</a></li>
<li><a href="#errors_err_child_closed_before_reply">ERR_CHILD_CLOSED_BEFORE_REPLY</a></li>
<li><a href="#errors_err_child_process_ipc_required">ERR_CHILD_PROCESS_IPC_REQUIRED</a></li>
<li><a href="#errors_err_child_process_stdio_maxbuffer">ERR_CHILD_PROCESS_STDIO_MAXBUFFER</a></li>
<li><a href="#errors_err_closed_message_port">ERR_CLOSED_MESSAGE_PORT</a></li>
<li><a href="#errors_err_console_writable_stream">ERR_CONSOLE_WRITABLE_STREAM</a></li>
<li><a href="#errors_err_construct_call_required">ERR_CONSTRUCT_CALL_REQUIRED</a></li>
<li><a href="#errors_err_cpu_usage">ERR_CPU_USAGE</a></li>
<li><a href="#errors_err_crypto_custom_engine_not_supported">ERR_CRYPTO_CUSTOM_ENGINE_NOT_SUPPORTED</a></li>
<li><a href="#errors_err_crypto_ecdh_invalid_format">ERR_CRYPTO_ECDH_INVALID_FORMAT</a></li>
<li><a href="#errors_err_crypto_ecdh_invalid_public_key">ERR_CRYPTO_ECDH_INVALID_PUBLIC_KEY</a></li>
<li><a href="#errors_err_crypto_engine_unknown">ERR_CRYPTO_ENGINE_UNKNOWN</a></li>
<li><a href="#errors_err_crypto_fips_forced">ERR_CRYPTO_FIPS_FORCED</a></li>
<li><a href="#errors_err_crypto_fips_unavailable">ERR_CRYPTO_FIPS_UNAVAILABLE</a></li>
<li><a href="#errors_err_crypto_hash_digest_no_utf16">ERR_CRYPTO_HASH_DIGEST_NO_UTF16</a></li>
<li><a href="#errors_err_crypto_hash_finalized">ERR_CRYPTO_HASH_FINALIZED</a></li>
<li><a href="#errors_err_crypto_hash_update_failed">ERR_CRYPTO_HASH_UPDATE_FAILED</a></li>
<li><a href="#errors_err_crypto_incompatible_key_options">ERR_CRYPTO_INCOMPATIBLE_KEY_OPTIONS</a></li>
<li><a href="#errors_err_crypto_invalid_digest">ERR_CRYPTO_INVALID_DIGEST</a></li>
<li><a href="#errors_err_crypto_invalid_state">ERR_CRYPTO_INVALID_STATE</a></li>
<li><a href="#errors_err_crypto_pbkdf2_error">ERR_CRYPTO_PBKDF2_ERROR</a></li>
<li><a href="#errors_err_crypto_scrypt_invalid_parameter">ERR_CRYPTO_SCRYPT_INVALID_PARAMETER</a></li>
<li><a href="#errors_err_crypto_scrypt_not_supported">ERR_CRYPTO_SCRYPT_NOT_SUPPORTED</a></li>
<li><a href="#errors_err_crypto_sign_key_required">ERR_CRYPTO_SIGN_KEY_REQUIRED</a></li>
<li><a href="#errors_err_crypto_timing_safe_equal_length">ERR_CRYPTO_TIMING_SAFE_EQUAL_LENGTH</a></li>
<li><a href="#errors_err_dns_set_servers_failed">ERR_DNS_SET_SERVERS_FAILED</a></li>
<li><a href="#errors_err_domain_callback_not_available">ERR_DOMAIN_CALLBACK_NOT_AVAILABLE</a></li>
<li><a href="#errors_err_domain_cannot_set_uncaught_exception_capture">ERR_DOMAIN_CANNOT_SET_UNCAUGHT_EXCEPTION_CAPTURE</a></li>
<li><a href="#errors_err_encoding_invalid_encoded_data">ERR_ENCODING_INVALID_ENCODED_DATA</a></li>
<li><a href="#errors_err_encoding_not_supported">ERR_ENCODING_NOT_SUPPORTED</a></li>
<li><a href="#errors_err_falsy_value_rejection">ERR_FALSY_VALUE_REJECTION</a></li>
<li><a href="#errors_err_fs_file_too_large">ERR_FS_FILE_TOO_LARGE</a></li>
<li><a href="#errors_err_fs_invalid_symlink_type">ERR_FS_INVALID_SYMLINK_TYPE</a></li>
<li><a href="#errors_err_http_headers_sent">ERR_HTTP_HEADERS_SENT</a></li>
<li><a href="#errors_err_http_invalid_header_value">ERR_HTTP_INVALID_HEADER_VALUE</a></li>
<li><a href="#errors_err_http_invalid_status_code">ERR_HTTP_INVALID_STATUS_CODE</a></li>
<li><a href="#errors_err_http_trailer_invalid">ERR_HTTP_TRAILER_INVALID</a></li>
<li><a href="#errors_err_http2_altsvc_invalid_origin">ERR_HTTP2_ALTSVC_INVALID_ORIGIN</a></li>
<li><a href="#errors_err_http2_altsvc_length">ERR_HTTP2_ALTSVC_LENGTH</a></li>
<li><a href="#errors_err_http2_connect_authority">ERR_HTTP2_CONNECT_AUTHORITY</a></li>
<li><a href="#errors_err_http2_connect_path">ERR_HTTP2_CONNECT_PATH</a></li>
<li><a href="#errors_err_http2_connect_scheme">ERR_HTTP2_CONNECT_SCHEME</a></li>
<li><a href="#errors_err_http2_error">ERR_HTTP2_ERROR</a></li>
<li><a href="#errors_err_http2_goaway_session">ERR_HTTP2_GOAWAY_SESSION</a></li>
<li><a href="#errors_err_http2_headers_after_respond">ERR_HTTP2_HEADERS_AFTER_RESPOND</a></li>
<li><a href="#errors_err_http2_headers_sent">ERR_HTTP2_HEADERS_SENT</a></li>
<li><a href="#errors_err_http2_header_single_value">ERR_HTTP2_HEADER_SINGLE_VALUE</a></li>
<li><a href="#errors_err_http2_info_status_not_allowed">ERR_HTTP2_INFO_STATUS_NOT_ALLOWED</a></li>
<li><a href="#errors_err_http2_invalid_connection_headers">ERR_HTTP2_INVALID_CONNECTION_HEADERS</a></li>
<li><a href="#errors_err_http2_invalid_header_value">ERR_HTTP2_INVALID_HEADER_VALUE</a></li>
<li><a href="#errors_err_http2_invalid_info_status">ERR_HTTP2_INVALID_INFO_STATUS</a></li>
<li><a href="#errors_err_http2_invalid_origin">ERR_HTTP2_INVALID_ORIGIN</a></li>
<li><a href="#errors_err_http2_invalid_packed_settings_length">ERR_HTTP2_INVALID_PACKED_SETTINGS_LENGTH</a></li>
<li><a href="#errors_err_http2_invalid_pseudoheader">ERR_HTTP2_INVALID_PSEUDOHEADER</a></li>
<li><a href="#errors_err_http2_invalid_session">ERR_HTTP2_INVALID_SESSION</a></li>
<li><a href="#errors_err_http2_invalid_setting_value">ERR_HTTP2_INVALID_SETTING_VALUE</a></li>
<li><a href="#errors_err_http2_invalid_stream">ERR_HTTP2_INVALID_STREAM</a></li>
<li><a href="#errors_err_http2_max_pending_settings_ack">ERR_HTTP2_MAX_PENDING_SETTINGS_ACK</a></li>
<li><a href="#errors_err_http2_nested_push">ERR_HTTP2_NESTED_PUSH</a></li>
<li><a href="#errors_err_http2_no_socket_manipulation">ERR_HTTP2_NO_SOCKET_MANIPULATION</a></li>
<li><a href="#errors_err_http2_origin_length">ERR_HTTP2_ORIGIN_LENGTH</a></li>
<li><a href="#errors_err_http2_out_of_streams">ERR_HTTP2_OUT_OF_STREAMS</a></li>
<li><a href="#errors_err_http2_payload_forbidden">ERR_HTTP2_PAYLOAD_FORBIDDEN</a></li>
<li><a href="#errors_err_http2_ping_cancel">ERR_HTTP2_PING_CANCEL</a></li>
<li><a href="#errors_err_http2_ping_length">ERR_HTTP2_PING_LENGTH</a></li>
<li><a href="#errors_err_http2_pseudoheader_not_allowed">ERR_HTTP2_PSEUDOHEADER_NOT_ALLOWED</a></li>
<li><a href="#errors_err_http2_push_disabled">ERR_HTTP2_PUSH_DISABLED</a></li>
<li><a href="#errors_err_http2_send_file">ERR_HTTP2_SEND_FILE</a></li>
<li><a href="#errors_err_http2_send_file_noseek">ERR_HTTP2_SEND_FILE_NOSEEK</a></li>
<li><a href="#errors_err_http2_session_error">ERR_HTTP2_SESSION_ERROR</a></li>
<li><a href="#errors_err_http2_settings_cancel">ERR_HTTP2_SETTINGS_CANCEL</a></li>
<li><a href="#errors_err_http2_socket_bound">ERR_HTTP2_SOCKET_BOUND</a></li>
<li><a href="#errors_err_http2_socket_unbound">ERR_HTTP2_SOCKET_UNBOUND</a></li>
<li><a href="#errors_err_http2_status_101">ERR_HTTP2_STATUS_101</a></li>
<li><a href="#errors_err_http2_status_invalid">ERR_HTTP2_STATUS_INVALID</a></li>
<li><a href="#errors_err_http2_stream_cancel">ERR_HTTP2_STREAM_CANCEL</a></li>
<li><a href="#errors_err_http2_stream_error">ERR_HTTP2_STREAM_ERROR</a></li>
<li><a href="#errors_err_http2_stream_self_dependency">ERR_HTTP2_STREAM_SELF_DEPENDENCY</a></li>
<li><a href="#errors_err_http2_trailers_already_sent">ERR_HTTP2_TRAILERS_ALREADY_SENT</a></li>
<li><a href="#errors_err_http2_trailers_not_ready">ERR_HTTP2_TRAILERS_NOT_READY</a></li>
<li><a href="#errors_err_http2_unsupported_protocol">ERR_HTTP2_UNSUPPORTED_PROTOCOL</a></li>
<li><a href="#errors_err_inspector_already_connected">ERR_INSPECTOR_ALREADY_CONNECTED</a></li>
<li><a href="#errors_err_inspector_closed">ERR_INSPECTOR_CLOSED</a></li>
<li><a href="#errors_err_inspector_not_available">ERR_INSPECTOR_NOT_AVAILABLE</a></li>
<li><a href="#errors_err_inspector_not_connected">ERR_INSPECTOR_NOT_CONNECTED</a></li>
<li><a href="#errors_err_invalid_address_family">ERR_INVALID_ADDRESS_FAMILY</a></li>
<li><a href="#errors_err_invalid_arg_type">ERR_INVALID_ARG_TYPE</a></li>
<li><a href="#errors_err_invalid_arg_value">ERR_INVALID_ARG_VALUE</a></li>
<li><a href="#errors_err_invalid_async_id">ERR_INVALID_ASYNC_ID</a></li>
<li><a href="#errors_err_invalid_buffer_size">ERR_INVALID_BUFFER_SIZE</a></li>
<li><a href="#errors_err_invalid_callback">ERR_INVALID_CALLBACK</a></li>
<li><a href="#errors_err_invalid_char">ERR_INVALID_CHAR</a></li>
<li><a href="#errors_err_invalid_cursor_pos">ERR_INVALID_CURSOR_POS</a></li>
<li><a href="#errors_err_invalid_fd">ERR_INVALID_FD</a></li>
<li><a href="#errors_err_invalid_fd_type">ERR_INVALID_FD_TYPE</a></li>
<li><a href="#errors_err_invalid_file_url_host">ERR_INVALID_FILE_URL_HOST</a></li>
<li><a href="#errors_err_invalid_file_url_path">ERR_INVALID_FILE_URL_PATH</a></li>
<li><a href="#errors_err_invalid_handle_type">ERR_INVALID_HANDLE_TYPE</a></li>
<li><a href="#errors_err_invalid_http_token">ERR_INVALID_HTTP_TOKEN</a></li>
<li><a href="#errors_err_invalid_ip_address">ERR_INVALID_IP_ADDRESS</a></li>
<li><a href="#errors_err_invalid_opt_value">ERR_INVALID_OPT_VALUE</a></li>
<li><a href="#errors_err_invalid_opt_value_encoding">ERR_INVALID_OPT_VALUE_ENCODING</a></li>
<li><a href="#errors_err_invalid_performance_mark">ERR_INVALID_PERFORMANCE_MARK</a></li>
<li><a href="#errors_err_invalid_protocol">ERR_INVALID_PROTOCOL</a></li>
<li><a href="#errors_err_invalid_repl_eval_config">ERR_INVALID_REPL_EVAL_CONFIG</a></li>
<li><a href="#errors_err_invalid_return_property">ERR_INVALID_RETURN_PROPERTY</a></li>
<li><a href="#errors_err_invalid_return_property_value">ERR_INVALID_RETURN_PROPERTY_VALUE</a></li>
<li><a href="#errors_err_invalid_return_value">ERR_INVALID_RETURN_VALUE</a></li>
<li><a href="#errors_err_invalid_sync_fork_input">ERR_INVALID_SYNC_FORK_INPUT</a></li>
<li><a href="#errors_err_invalid_this">ERR_INVALID_THIS</a></li>
<li><a href="#errors_err_invalid_transfer_object">ERR_INVALID_TRANSFER_OBJECT</a></li>
<li><a href="#errors_err_invalid_tuple">ERR_INVALID_TUPLE</a></li>
<li><a href="#errors_err_invalid_uri">ERR_INVALID_URI</a></li>
<li><a href="#errors_err_invalid_url">ERR_INVALID_URL</a></li>
<li><a href="#errors_err_invalid_url_scheme">ERR_INVALID_URL_SCHEME</a></li>
<li><a href="#errors_err_ipc_channel_closed">ERR_IPC_CHANNEL_CLOSED</a></li>
<li><a href="#errors_err_ipc_disconnected">ERR_IPC_DISCONNECTED</a></li>
<li><a href="#errors_err_ipc_one_pipe">ERR_IPC_ONE_PIPE</a></li>
<li><a href="#errors_err_ipc_sync_fork">ERR_IPC_SYNC_FORK</a></li>
<li><a href="#errors_err_memory_allocation_failed">ERR_MEMORY_ALLOCATION_FAILED</a></li>
<li><a href="#errors_err_method_not_implemented">ERR_METHOD_NOT_IMPLEMENTED</a></li>
<li><a href="#errors_err_missing_args">ERR_MISSING_ARGS</a></li>
<li><a href="#errors_err_missing_dynamic_instantiate_hook">ERR_MISSING_DYNAMIC_INSTANTIATE_HOOK</a></li>
<li><a href="#errors_err_missing_message_port_in_transfer_list">ERR_MISSING_MESSAGE_PORT_IN_TRANSFER_LIST</a></li>
<li><a href="#errors_err_missing_module">ERR_MISSING_MODULE</a></li>
<li><a href="#errors_err_missing_platform_for_worker">ERR_MISSING_PLATFORM_FOR_WORKER</a></li>
<li><a href="#errors_err_module_resolution_legacy">ERR_MODULE_RESOLUTION_LEGACY</a></li>
<li><a href="#errors_err_multiple_callback">ERR_MULTIPLE_CALLBACK</a></li>
<li><a href="#errors_err_napi_cons_function">ERR_NAPI_CONS_FUNCTION</a></li>
<li><a href="#errors_err_napi_invalid_dataview_args">ERR_NAPI_INVALID_DATAVIEW_ARGS</a></li>
<li><a href="#errors_err_napi_invalid_typedarray_alignment">ERR_NAPI_INVALID_TYPEDARRAY_ALIGNMENT</a></li>
<li><a href="#errors_err_napi_invalid_typedarray_length">ERR_NAPI_INVALID_TYPEDARRAY_LENGTH</a></li>
<li><a href="#errors_err_napi_tsfn_call_js">ERR_NAPI_TSFN_CALL_JS</a></li>
<li><a href="#errors_err_napi_tsfn_get_undefined">ERR_NAPI_TSFN_GET_UNDEFINED</a></li>
<li><a href="#errors_err_napi_tsfn_start_idle_loop">ERR_NAPI_TSFN_START_IDLE_LOOP</a></li>
<li><a href="#errors_err_napi_tsfn_stop_idle_loop">ERR_NAPI_TSFN_STOP_IDLE_LOOP</a></li>
<li><a href="#errors_err_no_crypto">ERR_NO_CRYPTO</a></li>
<li><a href="#errors_err_no_icu">ERR_NO_ICU</a></li>
<li><a href="#errors_err_no_longer_supported">ERR_NO_LONGER_SUPPORTED</a></li>
<li><a href="#errors_err_out_of_range">ERR_OUT_OF_RANGE</a></li>
<li><a href="#errors_err_require_esm">ERR_REQUIRE_ESM</a></li>
<li><a href="#errors_err_script_execution_interrupted">ERR_SCRIPT_EXECUTION_INTERRUPTED</a></li>
<li><a href="#errors_err_script_execution_timeout">ERR_SCRIPT_EXECUTION_TIMEOUT</a></li>
<li><a href="#errors_err_server_already_listen">ERR_SERVER_ALREADY_LISTEN</a></li>
<li><a href="#errors_err_server_not_running">ERR_SERVER_NOT_RUNNING</a></li>
<li><a href="#errors_err_socket_already_bound">ERR_SOCKET_ALREADY_BOUND</a></li>
<li><a href="#errors_err_socket_bad_buffer_size">ERR_SOCKET_BAD_BUFFER_SIZE</a></li>
<li><a href="#errors_err_socket_bad_port">ERR_SOCKET_BAD_PORT</a></li>
<li><a href="#errors_err_socket_bad_type">ERR_SOCKET_BAD_TYPE</a></li>
<li><a href="#errors_err_socket_buffer_size">ERR_SOCKET_BUFFER_SIZE</a></li>
<li><a href="#errors_err_socket_cannot_send">ERR_SOCKET_CANNOT_SEND</a></li>
<li><a href="#errors_err_socket_closed">ERR_SOCKET_CLOSED</a></li>
<li><a href="#errors_err_socket_dgram_not_running">ERR_SOCKET_DGRAM_NOT_RUNNING</a></li>
<li><a href="#errors_err_stream_cannot_pipe">ERR_STREAM_CANNOT_PIPE</a></li>
<li><a href="#errors_err_stream_destroyed">ERR_STREAM_DESTROYED</a></li>
<li><a href="#errors_err_stream_null_values">ERR_STREAM_NULL_VALUES</a></li>
<li><a href="#errors_err_stream_premature_close">ERR_STREAM_PREMATURE_CLOSE</a></li>
<li><a href="#errors_err_stream_push_after_eof">ERR_STREAM_PUSH_AFTER_EOF</a></li>
<li><a href="#errors_err_stream_unshift_after_end_event">ERR_STREAM_UNSHIFT_AFTER_END_EVENT</a></li>
<li><a href="#errors_err_stream_wrap">ERR_STREAM_WRAP</a></li>
<li><a href="#errors_err_stream_write_after_end">ERR_STREAM_WRITE_AFTER_END</a></li>
<li><a href="#errors_err_string_too_long">ERR_STRING_TOO_LONG</a></li>
<li><a href="#errors_err_system_error">ERR_SYSTEM_ERROR</a></li>
<li><a href="#errors_err_tls_cert_altname_invalid">ERR_TLS_CERT_ALTNAME_INVALID</a></li>
<li><a href="#errors_err_tls_dh_param_size">ERR_TLS_DH_PARAM_SIZE</a></li>
<li><a href="#errors_err_tls_handshake_timeout">ERR_TLS_HANDSHAKE_TIMEOUT</a></li>
<li><a href="#errors_err_tls_renegotiate">ERR_TLS_RENEGOTIATE</a></li>
<li><a href="#errors_err_tls_renegotiation_disabled">ERR_TLS_RENEGOTIATION_DISABLED</a></li>
<li><a href="#errors_err_tls_required_server_name">ERR_TLS_REQUIRED_SERVER_NAME</a></li>
<li><a href="#errors_err_tls_session_attack">ERR_TLS_SESSION_ATTACK</a></li>
<li><a href="#errors_err_tls_sni_from_server">ERR_TLS_SNI_FROM_SERVER</a></li>
<li><a href="#errors_err_trace_events_category_required">ERR_TRACE_EVENTS_CATEGORY_REQUIRED</a></li>
<li><a href="#errors_err_trace_events_unavailable">ERR_TRACE_EVENTS_UNAVAILABLE</a></li>
<li><a href="#errors_err_transferring_externalized_sharedarraybuffer">ERR_TRANSFERRING_EXTERNALIZED_SHAREDARRAYBUFFER</a></li>
<li><a href="#errors_err_transform_already_transforming">ERR_TRANSFORM_ALREADY_TRANSFORMING</a></li>
<li><a href="#errors_err_transform_with_length_0">ERR_TRANSFORM_WITH_LENGTH_0</a></li>
<li><a href="#errors_err_tty_init_failed">ERR_TTY_INIT_FAILED</a></li>
<li><a href="#errors_err_uncaught_exception_capture_already_set">ERR_UNCAUGHT_EXCEPTION_CAPTURE_ALREADY_SET</a></li>
<li><a href="#errors_err_unescaped_characters">ERR_UNESCAPED_CHARACTERS</a></li>
<li><a href="#errors_err_unhandled_error">ERR_UNHANDLED_ERROR</a></li>
<li><a href="#errors_err_unknown_builtin_module">ERR_UNKNOWN_BUILTIN_MODULE</a></li>
<li><a href="#errors_err_unknown_credential">ERR_UNKNOWN_CREDENTIAL</a></li>
<li><a href="#errors_err_unknown_encoding">ERR_UNKNOWN_ENCODING</a></li>
<li><a href="#errors_err_unknown_file_extension">ERR_UNKNOWN_FILE_EXTENSION</a></li>
<li><a href="#errors_err_unknown_module_format">ERR_UNKNOWN_MODULE_FORMAT</a></li>
<li><a href="#errors_err_unknown_signal">ERR_UNKNOWN_SIGNAL</a></li>
<li><a href="#errors_err_unknown_stdin_type">ERR_UNKNOWN_STDIN_TYPE</a></li>
<li><a href="#errors_err_unknown_stream_type">ERR_UNKNOWN_STREAM_TYPE</a></li>
<li><a href="#errors_err_v8breakiterator">ERR_V8BREAKITERATOR</a></li>
<li><a href="#errors_err_valid_performance_entry_type">ERR_VALID_PERFORMANCE_ENTRY_TYPE</a></li>
<li><a href="#errors_err_vm_dynamic_import_callback_missing">ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING</a></li>
<li><a href="#errors_err_vm_module_already_linked">ERR_VM_MODULE_ALREADY_LINKED</a></li>
<li><a href="#errors_err_vm_module_different_context">ERR_VM_MODULE_DIFFERENT_CONTEXT</a></li>
<li><a href="#errors_err_vm_module_linking_errored">ERR_VM_MODULE_LINKING_ERRORED</a></li>
<li><a href="#errors_err_vm_module_not_linked">ERR_VM_MODULE_NOT_LINKED</a></li>
<li><a href="#errors_err_vm_module_not_module">ERR_VM_MODULE_NOT_MODULE</a></li>
<li><a href="#errors_err_vm_module_status">ERR_VM_MODULE_STATUS</a></li>
<li><a href="#errors_err_worker_path">ERR_WORKER_PATH</a></li>
<li><a href="#errors_err_worker_unserializable_error">ERR_WORKER_UNSERIALIZABLE_ERROR</a></li>
<li><a href="#errors_err_worker_unsupported_extension">ERR_WORKER_UNSUPPORTED_EXTENSION</a></li>
<li><a href="#errors_err_zlib_initialization_failed">ERR_ZLIB_INITIALIZATION_FAILED</a></li>
<li><a href="#errors_hpe_header_overflow">HPE_HEADER_OVERFLOW</a></li>
<li><a href="#errors_module_not_found">MODULE_NOT_FOUND</a></li>
</ul>
</li>
<li>
<p><a href="#errors_legacy_node_js_error_codes">Legacy Node.js Error Codes</a></p>
<ul>
<li><a href="#errors_err_http2_frame_error">ERR_HTTP2_FRAME_ERROR</a></li>
<li><a href="#errors_err_http2_headers_object">ERR_HTTP2_HEADERS_OBJECT</a></li>
<li><a href="#errors_err_http2_header_required">ERR_HTTP2_HEADER_REQUIRED</a></li>
<li><a href="#errors_err_http2_info_headers_after_respond">ERR_HTTP2_INFO_HEADERS_AFTER_RESPOND</a></li>
<li><a href="#errors_err_http2_stream_closed">ERR_HTTP2_STREAM_CLOSED</a></li>
<li><a href="#errors_err_http_invalid_char">ERR_HTTP_INVALID_CHAR</a></li>
<li><a href="#errors_err_index_out_of_range">ERR_INDEX_OUT_OF_RANGE</a></li>
<li><a href="#errors_err_napi_cons_prototype_object">ERR_NAPI_CONS_PROTOTYPE_OBJECT</a></li>
<li><a href="#errors_err_outofmemory">ERR_OUTOFMEMORY</a></li>
<li><a href="#errors_err_parse_history_data">ERR_PARSE_HISTORY_DATA</a></li>
<li><a href="#errors_err_stderr_close">ERR_STDERR_CLOSE</a></li>
<li><a href="#errors_err_stdout_close">ERR_STDOUT_CLOSE</a></li>
<li><a href="#errors_err_stream_read_not_implemented">ERR_STREAM_READ_NOT_IMPLEMENTED</a></li>
<li><a href="#errors_err_tls_renegotiation_failed">ERR_TLS_RENEGOTIATION_FAILED</a></li>
<li><a href="#errors_err_unknown_builtin_module_1">ERR_UNKNOWN_BUILTIN_MODULE</a></li>
<li><a href="#errors_err_value_out_of_range">ERR_VALUE_OUT_OF_RANGE</a></li>
<li><a href="#errors_err_zlib_binding_closed">ERR_ZLIB_BINDING_CLOSED</a></li>
<li>
<p><a href="#errors_other_error_codes">Other error codes</a></p>
<ul>
<li><a href="#errors_err_fs_watcher_already_started">ERR_FS_WATCHER_ALREADY_STARTED</a></li>
<li><a href="#errors_err_fs_watcher_not_started">ERR_FS_WATCHER_NOT_STARTED</a></li>
<li><a href="#errors_err_http2_already_shutdown">ERR_HTTP2_ALREADY_SHUTDOWN</a></li>
<li><a href="#errors_err_http2_error_1">ERR_HTTP2_ERROR</a></li>
<li><a href="#errors_err_invalid_repl_history">ERR_INVALID_REPL_HISTORY</a></li>
<li><a href="#errors_err_missing_dynamic_instantiate_hook_1">ERR_MISSING_DYNAMIC_INSTANTIATE_HOOK</a></li>
<li><a href="#errors_err_stream_has_stringdecoder">ERR_STREAM_HAS_STRINGDECODER</a></li>
<li><a href="#errors_err_string_too_large">ERR_STRING_TOO_LARGE</a></li>
<li><a href="#errors_err_tty_writable_not_readable">ERR_TTY_WRITABLE_NOT_READABLE</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<div id="apicontent">
<h1>Errors<span><a class="mark" href="#errors_errors" id="errors_errors">#</a></span></h1>
<p>Applications running in Node.js will generally experience four categories of
errors:</p>
<ul>
<li>Standard JavaScript errors such as <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError" class="type"><EvalError></a>, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError" class="type"><SyntaxError></a>, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError" class="type"><RangeError></a>,
<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError" class="type"><ReferenceError></a>, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError" class="type"><TypeError></a>, and <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError" class="type"><URIError></a>.</li>
<li>System errors triggered by underlying operating system constraints such
as attempting to open a file that does not exist or attempting to send data
over a closed socket.</li>
<li>User-specified errors triggered by application code.</li>
<li><code>AssertionError</code>s are a special class of error that can be triggered when
Node.js detects an exceptional logic violation that should never occur. These
are raised typically by the <code>assert</code> module.</li>
</ul>
<p>All JavaScript and System errors raised by Node.js inherit from, or are
instances of, the standard JavaScript <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type"><Error></a> class and are guaranteed
to provide <em>at least</em> the properties available on that class.</p>
<h2>Error Propagation and Interception<span><a class="mark" href="#errors_error_propagation_and_interception" id="errors_error_propagation_and_interception">#</a></span></h2>
<p>Node.js supports several mechanisms for propagating and handling errors that
occur while an application is running. How these errors are reported and
handled depends entirely on the type of <code>Error</code> and the style of the API that is
called.</p>
<p>All JavaScript errors are handled as exceptions that <em>immediately</em> generate
and throw an error using the standard JavaScript <code>throw</code> mechanism. These
are handled using the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch"><code>try…catch</code> construct</a> provided by the
JavaScript language.</p>
<pre><code class="language-js"><span class="hljs-comment">// Throws with a ReferenceError because z is undefined</span>
<span class="hljs-keyword">try</span> {
<span class="hljs-keyword">const</span> m = <span class="hljs-number">1</span>;
<span class="hljs-keyword">const</span> n = m + z;
} <span class="hljs-keyword">catch</span> (err) {
<span class="hljs-comment">// Handle the error here.</span>
}</code></pre>
<p>Any use of the JavaScript <code>throw</code> mechanism will raise an exception that
<em>must</em> be handled using <code>try…catch</code> or the Node.js process will exit
immediately.</p>
<p>With few exceptions, <em>Synchronous</em> APIs (any blocking method that does not
accept a <code>callback</code> function, such as <a href="fs.html#fs_fs_readfilesync_path_options"><code>fs.readFileSync</code></a>), will use <code>throw</code>
to report errors.</p>
<p>Errors that occur within <em>Asynchronous APIs</em> may be reported in multiple ways:</p>
<ul>
<li>Most asynchronous methods that accept a <code>callback</code> function will accept an
<code>Error</code> object passed as the first argument to that function. If that first
argument is not <code>null</code> and is an instance of <code>Error</code>, then an error occurred
that should be handled.</li>
</ul>
<!-- eslint-disable no-useless-return -->
<pre><code class="language-js"><span class="hljs-keyword">const</span> fs = <span class="hljs-built_in">require</span>(<span class="hljs-string">'fs'</span>);
fs.readFile(<span class="hljs-string">'a file that does not exist'</span>, (err, data) => {
<span class="hljs-keyword">if</span> (err) {
<span class="hljs-built_in">console</span>.error(<span class="hljs-string">'There was an error reading the file!'</span>, err);
<span class="hljs-keyword">return</span>;
}
<span class="hljs-comment">// Otherwise handle the data</span>
});</code></pre>
<ul>
<li>
<p>When an asynchronous method is called on an object that is an
<a href="events.html#events_class_eventemitter"><code>EventEmitter</code></a>, errors can be routed to that object's <code>'error'</code> event.</p>
<pre><code class="language-js"><span class="hljs-keyword">const</span> net = <span class="hljs-built_in">require</span>(<span class="hljs-string">'net'</span>);
<span class="hljs-keyword">const</span> connection = net.connect(<span class="hljs-string">'localhost'</span>);
<span class="hljs-comment">// Adding an 'error' event handler to a stream:</span>
connection.on(<span class="hljs-string">'error'</span>, (err) => {
<span class="hljs-comment">// If the connection is reset by the server, or if it can't</span>
<span class="hljs-comment">// connect at all, or on any sort of error encountered by</span>
<span class="hljs-comment">// the connection, the error will be sent here.</span>
<span class="hljs-built_in">console</span>.error(err);
});
connection.pipe(process.stdout);</code></pre>
</li>
<li>
<p>A handful of typically asynchronous methods in the Node.js API may still
use the <code>throw</code> mechanism to raise exceptions that must be handled using
<code>try…catch</code>. There is no comprehensive list of such methods; please
refer to the documentation of each method to determine the appropriate
error handling mechanism required.</p>
</li>
</ul>
<p>The use of the <code>'error'</code> event mechanism is most common for <a href="stream.html">stream-based</a>
and <a href="events.html#events_class_eventemitter">event emitter-based</a> APIs, which themselves represent a series of
asynchronous operations over time (as opposed to a single operation that may
pass or fail).</p>
<p>For <em>all</em> <a href="events.html#events_class_eventemitter"><code>EventEmitter</code></a> objects, if an <code>'error'</code> event handler is not
provided, the error will be thrown, causing the Node.js process to report an
uncaught exception and crash unless either: The <a href="domain.html"><code>domain</code></a> module is
used appropriately or a handler has been registered for the
<a href="process.html#process_event_uncaughtexception"><code>'uncaughtException'</code></a> event.</p>
<pre><code class="language-js"><span class="hljs-keyword">const</span> EventEmitter = <span class="hljs-built_in">require</span>(<span class="hljs-string">'events'</span>);
<span class="hljs-keyword">const</span> ee = <span class="hljs-keyword">new</span> EventEmitter();
setImmediate(<span class="hljs-function"><span class="hljs-params">()</span> =></span> {
<span class="hljs-comment">// This will crash the process because no 'error' event</span>
<span class="hljs-comment">// handler has been added.</span>
ee.emit(<span class="hljs-string">'error'</span>, <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span>(<span class="hljs-string">'This will crash'</span>));
});</code></pre>
<p>Errors generated in this way <em>cannot</em> be intercepted using <code>try…catch</code> as
they are thrown <em>after</em> the calling code has already exited.</p>
<p>Developers must refer to the documentation for each method to determine
exactly how errors raised by those methods are propagated.</p>
<h3>Error-first callbacks<span><a class="mark" href="#errors_error_first_callbacks" id="errors_error_first_callbacks">#</a></span></h3>
<p>Most asynchronous methods exposed by the Node.js core API follow an idiomatic
pattern referred to as an <em>error-first callback</em>. With this pattern, a callback
function is passed to the method as an argument. When the operation either
completes or an error is raised, the callback function is called with the
<code>Error</code> object (if any) passed as the first argument. If no error was raised,
the first argument will be passed as <code>null</code>.</p>
<pre><code class="language-js"><span class="hljs-keyword">const</span> fs = <span class="hljs-built_in">require</span>(<span class="hljs-string">'fs'</span>);
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">errorFirstCallback</span>(<span class="hljs-params">err, data</span>) </span>{
<span class="hljs-keyword">if</span> (err) {
<span class="hljs-built_in">console</span>.error(<span class="hljs-string">'There was an error'</span>, err);
<span class="hljs-keyword">return</span>;
}
<span class="hljs-built_in">console</span>.log(data);
}
fs.readFile(<span class="hljs-string">'/some/file/that/does-not-exist'</span>, errorFirstCallback);
fs.readFile(<span class="hljs-string">'/some/file/that/does-exist'</span>, errorFirstCallback);</code></pre>
<p>The JavaScript <code>try…catch</code> mechanism <strong>cannot</strong> be used to intercept errors
generated by asynchronous APIs. A common mistake for beginners is to try to
use <code>throw</code> inside an error-first callback:</p>
<pre><code class="language-js"><span class="hljs-comment">// THIS WILL NOT WORK:</span>
<span class="hljs-keyword">const</span> fs = <span class="hljs-built_in">require</span>(<span class="hljs-string">'fs'</span>);
<span class="hljs-keyword">try</span> {
fs.readFile(<span class="hljs-string">'/some/file/that/does-not-exist'</span>, (err, data) => {
<span class="hljs-comment">// mistaken assumption: throwing here...</span>
<span class="hljs-keyword">if</span> (err) {
<span class="hljs-keyword">throw</span> err;
}
});
} <span class="hljs-keyword">catch</span> (err) {
<span class="hljs-comment">// This will not catch the throw!</span>
<span class="hljs-built_in">console</span>.error(err);
}</code></pre>
<p>This will not work because the callback function passed to <code>fs.readFile()</code> is
called asynchronously. By the time the callback has been called, the
surrounding code (including the <code>try { } catch (err) { }</code> block will have
already exited. Throwing an error inside the callback <strong>can crash the Node.js
process</strong> in most cases. If <a href="domain.html">domains</a> are enabled, or a handler has been
registered with <code>process.on('uncaughtException')</code>, such errors can be
intercepted.</p>
<h2>Class: Error<span><a class="mark" href="#errors_class_error" id="errors_class_error">#</a></span></h2>
<p>A generic JavaScript <code>Error</code> object that does not denote any specific
circumstance of why the error occurred. <code>Error</code> objects capture a "stack trace"
detailing the point in the code at which the <code>Error</code> was instantiated, and may
provide a text description of the error.</p>
<p>For crypto only, <code>Error</code> objects will include the OpenSSL error stack in a
separate property called <code>opensslErrorStack</code> if it is available when the error
is thrown.</p>
<p>All errors generated by Node.js, including all System and JavaScript errors,
will either be instances of, or inherit from, the <code>Error</code> class.</p>
<h3>new Error(message)<span><a class="mark" href="#errors_new_error_message" id="errors_new_error_message">#</a></span></h3>
<ul>
<li><code>message</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li>
</ul>
<p>Creates a new <code>Error</code> object and sets the <code>error.message</code> property to the
provided text message. If an object is passed as <code>message</code>, the text message
is generated by calling <code>message.toString()</code>. The <code>error.stack</code> property will
represent the point in the code at which <code>new Error()</code> was called. Stack traces
are dependent on <a href="https://github.com/v8/v8/wiki/Stack-Trace-API">V8's stack trace API</a>. Stack traces extend only to either
(a) the beginning of <em>synchronous code execution</em>, or (b) the number of frames
given by the property <code>Error.stackTraceLimit</code>, whichever is smaller.</p>
<h3>Error.captureStackTrace(targetObject[, constructorOpt])<span><a class="mark" href="#errors_error_capturestacktrace_targetobject_constructoropt" id="errors_error_capturestacktrace_targetobject_constructoropt">#</a></span></h3>
<ul>
<li><code>targetObject</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a></li>
<li><code>constructorOpt</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a></li>
</ul>
<p>Creates a <code>.stack</code> property on <code>targetObject</code>, which when accessed returns
a string representing the location in the code at which
<code>Error.captureStackTrace()</code> was called.</p>
<pre><code class="language-js"><span class="hljs-keyword">const</span> myObject = {};
<span class="hljs-built_in">Error</span>.captureStackTrace(myObject);
myObject.stack; <span class="hljs-comment">// similar to `new Error().stack`</span></code></pre>
<p>The first line of the trace will be prefixed with
<code>${myObject.name}: ${myObject.message}</code>.</p>
<p>The optional <code>constructorOpt</code> argument accepts a function. If given, all frames
above <code>constructorOpt</code>, including <code>constructorOpt</code>, will be omitted from the
generated stack trace.</p>
<p>The <code>constructorOpt</code> argument is useful for hiding implementation
details of error generation from an end user. For instance:</p>
<pre><code class="language-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">MyError</span>(<span class="hljs-params"></span>) </span>{
<span class="hljs-built_in">Error</span>.captureStackTrace(<span class="hljs-keyword">this</span>, MyError);
}
<span class="hljs-comment">// Without passing MyError to captureStackTrace, the MyError</span>
<span class="hljs-comment">// frame would show up in the .stack property. By passing</span>
<span class="hljs-comment">// the constructor, we omit that frame, and retain all frames below it.</span>
<span class="hljs-keyword">new</span> MyError().stack;</code></pre>
<h3>Error.stackTraceLimit<span><a class="mark" href="#errors_error_stacktracelimit" id="errors_error_stacktracelimit">#</a></span></h3>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li>
</ul>
<p>The <code>Error.stackTraceLimit</code> property specifies the number of stack frames
collected by a stack trace (whether generated by <code>new Error().stack</code> or
<code>Error.captureStackTrace(obj)</code>).</p>
<p>The default value is <code>10</code> but may be set to any valid JavaScript number. Changes
will affect any stack trace captured <em>after</em> the value has been changed.</p>
<p>If set to a non-number value, or set to a negative number, stack traces will
not capture any frames.</p>
<h3>error.code<span><a class="mark" href="#errors_error_code" id="errors_error_code">#</a></span></h3>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li>
</ul>
<p>The <code>error.code</code> property is a string label that identifies the kind of error.
<code>error.code</code> is the most stable way to identify an error. It will only change
between major versions of Node.js. In contrast, <code>error.message</code> strings may
change between any versions of Node.js. See <a href="#nodejs-error-codes">Node.js Error Codes</a> for details
about specific codes.</p>
<h3>error.message<span><a class="mark" href="#errors_error_message" id="errors_error_message">#</a></span></h3>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li>
</ul>
<p>The <code>error.message</code> property is the string description of the error as set by
calling <code>new Error(message)</code>. The <code>message</code> passed to the constructor will also
appear in the first line of the stack trace of the <code>Error</code>, however changing
this property after the <code>Error</code> object is created <em>may not</em> change the first
line of the stack trace (for example, when <code>error.stack</code> is read before this
property is changed).</p>
<pre><code class="language-js"><span class="hljs-keyword">const</span> err = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span>(<span class="hljs-string">'The message'</span>);
<span class="hljs-built_in">console</span>.error(err.message);
<span class="hljs-comment">// Prints: The message</span></code></pre>
<h3>error.stack<span><a class="mark" href="#errors_error_stack" id="errors_error_stack">#</a></span></h3>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li>
</ul>
<p>The <code>error.stack</code> property is a string describing the point in the code at which
the <code>Error</code> was instantiated.</p>
<pre><code class="language-txt">Error: Things keep happening!
at /home/gbusey/file.js:525:2
at Frobnicator.refrobulate (/home/gbusey/business-logic.js:424:21)
at Actor.<anonymous> (/home/gbusey/actors.js:400:8)
at increaseSynergy (/home/gbusey/actors.js:701:6)</anonymous></code></pre>
<p>The first line is formatted as <code><error class name>: <error message></code>, and
is followed by a series of stack frames (each line beginning with "at ").
Each frame describes a call site within the code that lead to the error being
generated. V8 attempts to display a name for each function (by variable name,
function name, or object method name), but occasionally it will not be able to
find a suitable name. If V8 cannot determine a name for the function, only
location information will be displayed for that frame. Otherwise, the
determined function name will be displayed with location information appended
in parentheses.</p>
<p>Frames are only generated for JavaScript functions. If, for example, execution
synchronously passes through a C++ addon function called <code>cheetahify</code> which
itself calls a JavaScript function, the frame representing the <code>cheetahify</code> call
will not be present in the stack traces:</p>
<pre><code class="language-js"><span class="hljs-keyword">const</span> cheetahify = <span class="hljs-built_in">require</span>(<span class="hljs-string">'./native-binding.node'</span>);
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">makeFaster</span>(<span class="hljs-params"></span>) </span>{
<span class="hljs-comment">// cheetahify *synchronously* calls speedy.</span>
cheetahify(<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">speedy</span>(<span class="hljs-params"></span>) </span>{
<span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span>(<span class="hljs-string">'oh no!'</span>);
});
}
makeFaster();
<span class="hljs-comment">// will throw:</span>
<span class="hljs-comment">// /home/gbusey/file.js:6</span>
<span class="hljs-comment">// throw new Error('oh no!');</span>
<span class="hljs-comment">// ^</span>
<span class="hljs-comment">// Error: oh no!</span>
<span class="hljs-comment">// at speedy (/home/gbusey/file.js:6:11)</span>
<span class="hljs-comment">// at makeFaster (/home/gbusey/file.js:5:3)</span>
<span class="hljs-comment">// at Object.<anonymous> (/home/gbusey/file.js:10:1)</span>
<span class="hljs-comment">// at Module._compile (module.js:456:26)</span>
<span class="hljs-comment">// at Object.Module._extensions..js (module.js:474:10)</span>
<span class="hljs-comment">// at Module.load (module.js:356:32)</span>
<span class="hljs-comment">// at Function.Module._load (module.js:312:12)</span>
<span class="hljs-comment">// at Function.Module.runMain (module.js:497:10)</span>
<span class="hljs-comment">// at startup (node.js:119:16)</span>
<span class="hljs-comment">// at node.js:906:3</span></code></pre>
<p>The location information will be one of:</p>
<ul>
<li><code>native</code>, if the frame represents a call internal to V8 (as in <code>[].forEach</code>).</li>
<li><code>plain-filename.js:line:column</code>, if the frame represents a call internal
to Node.js.</li>
<li><code>/absolute/path/to/file.js:line:column</code>, if the frame represents a call in
a user program, or its dependencies.</li>
</ul>
<p>The string representing the stack trace is lazily generated when the
<code>error.stack</code> property is <strong>accessed</strong>.</p>
<p>The number of frames captured by the stack trace is bounded by the smaller of
<code>Error.stackTraceLimit</code> or the number of available frames on the current event
loop tick.</p>
<p>System-level errors are generated as augmented <code>Error</code> instances, which are
detailed <a href="#errors_system_errors">here</a>.</p>
<h2>Class: AssertionError<span><a class="mark" href="#errors_class_assertionerror" id="errors_class_assertionerror">#</a></span></h2>
<p>A subclass of <code>Error</code> that indicates the failure of an assertion. For details,
see <a href="assert.html#assert_class_assert_assertionerror"><code>Class: assert.AssertionError</code></a>.</p>
<h2>Class: RangeError<span><a class="mark" href="#errors_class_rangeerror" id="errors_class_rangeerror">#</a></span></h2>
<p>A subclass of <code>Error</code> that indicates that a provided argument was not within the
set or range of acceptable values for a function; whether that is a numeric
range, or outside the set of options for a given function parameter.</p>
<pre><code class="language-js"><span class="hljs-built_in">require</span>(<span class="hljs-string">'net'</span>).connect(<span class="hljs-number">-1</span>);
<span class="hljs-comment">// throws "RangeError: "port" option should be >= 0 and < 65536: -1"</span></code></pre>
<p>Node.js will generate and throw <code>RangeError</code> instances <em>immediately</em> as a form
of argument validation.</p>
<h2>Class: ReferenceError<span><a class="mark" href="#errors_class_referenceerror" id="errors_class_referenceerror">#</a></span></h2>
<p>A subclass of <code>Error</code> that indicates that an attempt is being made to access a
variable that is not defined. Such errors commonly indicate typos in code, or
an otherwise broken program.</p>
<p>While client code may generate and propagate these errors, in practice, only V8
will do so.</p>
<pre><code class="language-js">doesNotExist;
<span class="hljs-comment">// throws ReferenceError, doesNotExist is not a variable in this program.</span></code></pre>
<p>Unless an application is dynamically generating and running code,
<code>ReferenceError</code> instances should always be considered a bug in the code
or its dependencies.</p>
<h2>Class: SyntaxError<span><a class="mark" href="#errors_class_syntaxerror" id="errors_class_syntaxerror">#</a></span></h2>
<p>A subclass of <code>Error</code> that indicates that a program is not valid JavaScript.
These errors may only be generated and propagated as a result of code
evaluation. Code evaluation may happen as a result of <code>eval</code>, <code>Function</code>,
<code>require</code>, or <a href="vm.html">vm</a>. These errors are almost always indicative of a broken
program.</p>
<pre><code class="language-js"><span class="hljs-keyword">try</span> {
<span class="hljs-built_in">require</span>(<span class="hljs-string">'vm'</span>).runInThisContext(<span class="hljs-string">'binary ! isNotOk'</span>);
} <span class="hljs-keyword">catch</span> (err) {
<span class="hljs-comment">// err will be a SyntaxError</span>
}</code></pre>
<p><code>SyntaxError</code> instances are unrecoverable in the context that created them –
they may only be caught by other contexts.</p>
<h2>Class: TypeError<span><a class="mark" href="#errors_class_typeerror" id="errors_class_typeerror">#</a></span></h2>
<p>A subclass of <code>Error</code> that indicates that a provided argument is not an
allowable type. For example, passing a function to a parameter which expects a
string would be considered a <code>TypeError</code>.</p>
<pre><code class="language-js"><span class="hljs-built_in">require</span>(<span class="hljs-string">'url'</span>).parse(<span class="hljs-function"><span class="hljs-params">()</span> =></span> { });
<span class="hljs-comment">// throws TypeError, since it expected a string</span></code></pre>
<p>Node.js will generate and throw <code>TypeError</code> instances <em>immediately</em> as a form
of argument validation.</p>
<h2>Exceptions vs. Errors<span><a class="mark" href="#errors_exceptions_vs_errors" id="errors_exceptions_vs_errors">#</a></span></h2>
<p>A JavaScript exception is a value that is thrown as a result of an invalid
operation or as the target of a <code>throw</code> statement. While it is not required
that these values are instances of <code>Error</code> or classes which inherit from
<code>Error</code>, all exceptions thrown by Node.js or the JavaScript runtime <em>will</em> be
instances of <code>Error</code>.</p>
<p>Some exceptions are <em>unrecoverable</em> at the JavaScript layer. Such exceptions
will <em>always</em> cause the Node.js process to crash. Examples include <code>assert()</code>
checks or <code>abort()</code> calls in the C++ layer.</p>
<h2>System Errors<span><a class="mark" href="#errors_system_errors" id="errors_system_errors">#</a></span></h2>
<p>Node.js generates system errors when exceptions occur within its runtime
environment. These usually occur when an application violates an operating
system constraint. For example, a system error will occur if an application
attempts to read a file that does not exist.</p>
<p>System errors are usually generated at the syscall level. For a comprehensive
list, see the <a href="http://man7.org/linux/man-pages/man3/errno.3.html"><code>errno</code>(3) man page</a>.</p>
<p>In Node.js, system errors are <code>Error</code> objects with extra properties.</p>
<h3>Class: SystemError<span><a class="mark" href="#errors_class_systemerror" id="errors_class_systemerror">#</a></span></h3>
<ul>
<li><code>address</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> If present, the address to which a network connection
failed</li>
<li><code>code</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> The string error code</li>
<li><code>dest</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> If present, the file path destination when reporting a file
system error</li>
<li><code>errno</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> The system-provided error number</li>
<li><code>info</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> If present, extra details about the error condition</li>
<li><code>message</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> A system-provided human-readable description of the error</li>
<li><code>path</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> If present, the file path when reporting a file system error</li>
<li><code>port</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> If present, the network connection port that is not available</li>
<li><code>syscall</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> The name of the system call that triggered the error</li>
</ul>
<h4>error.address<span><a class="mark" href="#errors_error_address" id="errors_error_address">#</a></span></h4>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li>
</ul>
<p>If present, <code>error.address</code> is a string describing the address to which a
network connection failed.</p>
<h4>error.code<span><a class="mark" href="#errors_error_code_1" id="errors_error_code_1">#</a></span></h4>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li>
</ul>
<p>The <code>error.code</code> property is a string representing the error code.</p>
<h4>error.dest<span><a class="mark" href="#errors_error_dest" id="errors_error_dest">#</a></span></h4>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li>
</ul>
<p>If present, <code>error.dest</code> is the file path destination when reporting a file
system error.</p>
<h4>error.errno<span><a class="mark" href="#errors_error_errno" id="errors_error_errno">#</a></span></h4>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li>
</ul>
<p>The <code>error.errno</code> property is a number or a string. If it is a number, it is a
negative value which corresponds to the error code defined in
<a href="http://docs.libuv.org/en/v1.x/errors.html"><code>libuv Error handling</code></a>. See the libuv <code>errno.h</code> header file
(<code>deps/uv/include/uv/errno.h</code> in the Node.js source tree) for details. In case
of a string, it is the same as <code>error.code</code>.</p>
<h4>error.info<span><a class="mark" href="#errors_error_info" id="errors_error_info">#</a></span></h4>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a></li>
</ul>
<p>If present, <code>error.info</code> is an object with details about the error condition.</p>
<h4>error.message<span><a class="mark" href="#errors_error_message_1" id="errors_error_message_1">#</a></span></h4>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li>
</ul>
<p><code>error.message</code> is a system-provided human-readable description of the error.</p>
<h4>error.path<span><a class="mark" href="#errors_error_path" id="errors_error_path">#</a></span></h4>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li>
</ul>
<p>If present, <code>error.path</code> is a string containing a relevant invalid pathname.</p>
<h4>error.port<span><a class="mark" href="#errors_error_port" id="errors_error_port">#</a></span></h4>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li>
</ul>
<p>If present, <code>error.port</code> is the network connection port that is not available.</p>
<h4>error.syscall<span><a class="mark" href="#errors_error_syscall" id="errors_error_syscall">#</a></span></h4>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li>
</ul>
<p>The <code>error.syscall</code> property is a string describing the <a href="http://man7.org/linux/man-pages/man2/syscalls.2.html">syscall</a> that failed.</p>
<h3>Common System Errors<span><a class="mark" href="#errors_common_system_errors" id="errors_common_system_errors">#</a></span></h3>
<p>This is a list of system errors commonly-encountered when writing a Node.js
program. For a comprehensive list, see the <a href="http://man7.org/linux/man-pages/man3/errno.3.html"><code>errno</code>(3) man page</a>.</p>
<ul>
<li>
<p><code>EACCES</code> (Permission denied): An attempt was made to access a file in a way
forbidden by its file access permissions.</p>
</li>
<li>
<p><code>EADDRINUSE</code> (Address already in use): An attempt to bind a server
(<a href="net.html"><code>net</code></a>, <a href="http.html"><code>http</code></a>, or <a href="https.html"><code>https</code></a>) to a local address failed due to
another server on the local system already occupying that address.</p>
</li>
<li>
<p><code>ECONNREFUSED</code> (Connection refused): No connection could be made because the
target machine actively refused it. This usually results from trying to
connect to a service that is inactive on the foreign host.</p>
</li>
<li>
<p><code>ECONNRESET</code> (Connection reset by peer): A connection was forcibly closed by
a peer. This normally results from a loss of the connection on the remote
socket due to a timeout or reboot. Commonly encountered via the <a href="http.html"><code>http</code></a>
and <a href="net.html"><code>net</code></a> modules.</p>
</li>
<li>
<p><code>EEXIST</code> (File exists): An existing file was the target of an operation that
required that the target not exist.</p>
</li>
<li>
<p><code>EISDIR</code> (Is a directory): An operation expected a file, but the given
pathname was a directory.</p>
</li>
<li>
<p><code>EMFILE</code> (Too many open files in system): Maximum number of
<a href="https://en.wikipedia.org/wiki/File_descriptor">file descriptors</a> allowable on the system has been reached, and
requests for another descriptor cannot be fulfilled until at least one
has been closed. This is encountered when opening many files at once in
parallel, especially on systems (in particular, macOS) where there is a low
file descriptor limit for processes. To remedy a low limit, run
<code>ulimit -n 2048</code> in the same shell that will run the Node.js process.</p>
</li>
<li>
<p><code>ENOENT</code> (No such file or directory): Commonly raised by <a href="fs.html"><code>fs</code></a> operations
to indicate that a component of the specified pathname does not exist — no
entity (file or directory) could be found by the given path.</p>
</li>
<li>
<p><code>ENOTDIR</code> (Not a directory): A component of the given pathname existed, but
was not a directory as expected. Commonly raised by <a href="fs.html#fs_fs_readdir_path_options_callback"><code>fs.readdir</code></a>.</p>
</li>
<li>
<p><code>ENOTEMPTY</code> (Directory not empty): A directory with entries was the target
of an operation that requires an empty directory — usually <a href="fs.html#fs_fs_unlink_path_callback"><code>fs.unlink</code></a>.</p>
</li>
<li>
<p><code>EPERM</code> (Operation not permitted): An attempt was made to perform an
operation that requires elevated privileges.</p>
</li>
<li>
<p><code>EPIPE</code> (Broken pipe): A write on a pipe, socket, or FIFO for which there is
no process to read the data. Commonly encountered at the <a href="net.html"><code>net</code></a> and
<a href="http.html"><code>http</code></a> layers, indicative that the remote side of the stream being
written to has been closed.</p>
</li>
<li>
<p><code>ETIMEDOUT</code> (Operation timed out): A connect or send request failed because
the connected party did not properly respond after a period of time. Usually
encountered by <a href="http.html"><code>http</code></a> or <a href="net.html"><code>net</code></a> — often a sign that a <code>socket.end()</code>
was not properly called.</p>
</li>
</ul>
<p><a id="nodejs-error-codes"></a></p>
<h2>Node.js Error Codes<span><a class="mark" href="#errors_node_js_error_codes" id="errors_node_js_error_codes">#</a></span></h2>
<p><a id="ERR_AMBIGUOUS_ARGUMENT"></a></p>
<h3>ERR_AMBIGUOUS_ARGUMENT<span><a class="mark" href="#errors_err_ambiguous_argument" id="errors_err_ambiguous_argument">#</a></span><span><a class="mark" href="#ERR_AMBIGUOUS_ARGUMENT" id="ERR_AMBIGUOUS_ARGUMENT">#</a></span></h3>
<p>A function argument is being used in a way that suggests that the function
signature may be misunderstood. This is thrown by the <code>assert</code> module when the
<code>message</code> parameter in <code>assert.throws(block, message)</code> matches the error message
thrown by <code>block</code> because that usage suggests that the user believes <code>message</code>
is the expected message rather than the message the <code>AssertionError</code> will
display if <code>block</code> does not throw.</p>
<p><a id="ERR_ARG_NOT_ITERABLE"></a></p>
<h3>ERR_ARG_NOT_ITERABLE<span><a class="mark" href="#errors_err_arg_not_iterable" id="errors_err_arg_not_iterable">#</a></span><span><a class="mark" href="#ERR_ARG_NOT_ITERABLE" id="ERR_ARG_NOT_ITERABLE">#</a></span></h3>
<p>An iterable argument (i.e. a value that works with <code>for...of</code> loops) was
required, but not provided to a Node.js API.</p>
<p><a id="ERR_ASSERTION"></a></p>
<h3>ERR_ASSERTION<span><a class="mark" href="#errors_err_assertion" id="errors_err_assertion">#</a></span><span><a class="mark" href="#ERR_ASSERTION" id="ERR_ASSERTION">#</a></span></h3>
<p>A special type of error that can be triggered whenever Node.js detects an
exceptional logic violation that should never occur. These are raised typically
by the <code>assert</code> module.</p>
<p><a id="ERR_ASYNC_CALLBACK"></a></p>
<h3>ERR_ASYNC_CALLBACK<span><a class="mark" href="#errors_err_async_callback" id="errors_err_async_callback">#</a></span><span><a class="mark" href="#ERR_ASYNC_CALLBACK" id="ERR_ASYNC_CALLBACK">#</a></span></h3>
<p>An attempt was made to register something that is not a function as an
<code>AsyncHooks</code> callback.</p>
<p><a id="ERR_ASYNC_TYPE"></a></p>
<h3>ERR_ASYNC_TYPE<span><a class="mark" href="#errors_err_async_type" id="errors_err_async_type">#</a></span><span><a class="mark" href="#ERR_ASYNC_TYPE" id="ERR_ASYNC_TYPE">#</a></span></h3>
<p>The type of an asynchronous resource was invalid. Note that users are also able
to define their own types if using the public embedder API.</p>
<p><a id="ERR_BUFFER_CONTEXT_NOT_AVAILABLE"></a></p>
<h3>ERR_BUFFER_CONTEXT_NOT_AVAILABLE<span><a class="mark" href="#errors_err_buffer_context_not_available" id="errors_err_buffer_context_not_available">#</a></span><span><a class="mark" href="#ERR_BUFFER_CONTEXT_NOT_AVAILABLE" id="ERR_BUFFER_CONTEXT_NOT_AVAILABLE">#</a></span></h3>
<p>An attempt was made to create a Node.js <code>Buffer</code> instance from addon or embedder
code, while in a JS engine Context that is not associated with a Node.js
instance. The data passed to the <code>Buffer</code> method will have been released
by the time the method returns.</p>
<p>When encountering this error, a possible alternative to creating a <code>Buffer</code>
instance is to create a normal <code>Uint8Array</code>, which only differs in the
prototype of the resulting object. <code>Uint8Array</code>s are generally accepted in all
Node.js core APIs where <code>Buffer</code>s are; they are available in all Contexts.</p>
<p><a id="ERR_BUFFER_OUT_OF_BOUNDS"></a></p>
<h3>ERR_BUFFER_OUT_OF_BOUNDS<span><a class="mark" href="#errors_err_buffer_out_of_bounds" id="errors_err_buffer_out_of_bounds">#</a></span><span><a class="mark" href="#ERR_BUFFER_OUT_OF_BOUNDS" id="ERR_BUFFER_OUT_OF_BOUNDS">#</a></span></h3>
<p>An operation outside the bounds of a <code>Buffer</code> was attempted.</p>
<p><a id="ERR_BUFFER_TOO_LARGE"></a></p>
<h3>ERR_BUFFER_TOO_LARGE<span><a class="mark" href="#errors_err_buffer_too_large" id="errors_err_buffer_too_large">#</a></span><span><a class="mark" href="#ERR_BUFFER_TOO_LARGE" id="ERR_BUFFER_TOO_LARGE">#</a></span></h3>
<p>An attempt has been made to create a <code>Buffer</code> larger than the maximum allowed
size.</p>
<p><a id="ERR_CANNOT_TRANSFER_OBJECT"></a></p>
<h3>ERR_CANNOT_TRANSFER_OBJECT<span><a class="mark" href="#errors_err_cannot_transfer_object" id="errors_err_cannot_transfer_object">#</a></span><span><a class="mark" href="#ERR_CANNOT_TRANSFER_OBJECT" id="ERR_CANNOT_TRANSFER_OBJECT">#</a></span></h3>
<p>The value passed to <code>postMessage()</code> contained an object that is not supported
for transferring.</p>
<p><a id="ERR_CANNOT_WATCH_SIGINT"></a></p>
<h3>ERR_CANNOT_WATCH_SIGINT<span><a class="mark" href="#errors_err_cannot_watch_sigint" id="errors_err_cannot_watch_sigint">#</a></span><span><a class="mark" href="#ERR_CANNOT_WATCH_SIGINT" id="ERR_CANNOT_WATCH_SIGINT">#</a></span></h3>
<p>Node.js was unable to watch for the <code>SIGINT</code> signal.</p>
<p><a id="ERR_CHILD_CLOSED_BEFORE_REPLY"></a></p>
<h3>ERR_CHILD_CLOSED_BEFORE_REPLY<span><a class="mark" href="#errors_err_child_closed_before_reply" id="errors_err_child_closed_before_reply">#</a></span><span><a class="mark" href="#ERR_CHILD_CLOSED_BEFORE_REPLY" id="ERR_CHILD_CLOSED_BEFORE_REPLY">#</a></span></h3>
<p>A child process was closed before the parent received a reply.</p>
<p><a id="ERR_CHILD_PROCESS_IPC_REQUIRED"></a></p>
<h3>ERR_CHILD_PROCESS_IPC_REQUIRED<span><a class="mark" href="#errors_err_child_process_ipc_required" id="errors_err_child_process_ipc_required">#</a></span><span><a class="mark" href="#ERR_CHILD_PROCESS_IPC_REQUIRED" id="ERR_CHILD_PROCESS_IPC_REQUIRED">#</a></span></h3>
<p>Used when a child process is being forked without specifying an IPC channel.</p>
<p><a id="ERR_CHILD_PROCESS_STDIO_MAXBUFFER"></a></p>
<h3>ERR_CHILD_PROCESS_STDIO_MAXBUFFER<span><a class="mark" href="#errors_err_child_process_stdio_maxbuffer" id="errors_err_child_process_stdio_maxbuffer">#</a></span><span><a class="mark" href="#ERR_CHILD_PROCESS_STDIO_MAXBUFFER" id="ERR_CHILD_PROCESS_STDIO_MAXBUFFER">#</a></span></h3>
<p>Used when the main process is trying to read data from the child process's
STDERR/STDOUT, and the data's length is longer than the <code>maxBuffer</code> option.</p>
<p><a id="ERR_CLOSED_MESSAGE_PORT"></a></p>
<h3>ERR_CLOSED_MESSAGE_PORT<span><a class="mark" href="#errors_err_closed_message_port" id="errors_err_closed_message_port">#</a></span><span><a class="mark" href="#ERR_CLOSED_MESSAGE_PORT" id="ERR_CLOSED_MESSAGE_PORT">#</a></span></h3>
<p>There was an attempt to use a <code>MessagePort</code> instance in a closed
state, usually after <code>.close()</code> has been called.</p>
<p><a id="ERR_CONSOLE_WRITABLE_STREAM"></a></p>
<h3>ERR_CONSOLE_WRITABLE_STREAM<span><a class="mark" href="#errors_err_console_writable_stream" id="errors_err_console_writable_stream">#</a></span><span><a class="mark" href="#ERR_CONSOLE_WRITABLE_STREAM" id="ERR_CONSOLE_WRITABLE_STREAM">#</a></span></h3>
<p><code>Console</code> was instantiated without <code>stdout</code> stream, or <code>Console</code> has a
non-writable <code>stdout</code> or <code>stderr</code> stream.</p>
<p><a id="ERR_CONSTRUCT_CALL_REQUIRED"></a></p>
<h3>ERR_CONSTRUCT_CALL_REQUIRED<span><a class="mark" href="#errors_err_construct_call_required" id="errors_err_construct_call_required">#</a></span><span><a class="mark" href="#ERR_CONSTRUCT_CALL_REQUIRED" id="ERR_CONSTRUCT_CALL_REQUIRED">#</a></span></h3>
<p>A constructor for a class was called without <code>new</code>.</p>
<p><a id="ERR_CPU_USAGE"></a></p>
<h3>ERR_CPU_USAGE<span><a class="mark" href="#errors_err_cpu_usage" id="errors_err_cpu_usage">#</a></span><span><a class="mark" href="#ERR_CPU_USAGE" id="ERR_CPU_USAGE">#</a></span></h3>
<p>The native call from <code>process.cpuUsage</code> could not be processed.</p>
<p><a id="ERR_CRYPTO_CUSTOM_ENGINE_NOT_SUPPORTED"></a></p>
<h3>ERR_CRYPTO_CUSTOM_ENGINE_NOT_SUPPORTED<span><a class="mark" href="#errors_err_crypto_custom_engine_not_supported" id="errors_err_crypto_custom_engine_not_supported">#</a></span><span><a class="mark" href="#ERR_CRYPTO_CUSTOM_ENGINE_NOT_SUPPORTED" id="ERR_CRYPTO_CUSTOM_ENGINE_NOT_SUPPORTED">#</a></span></h3>
<p>A client certificate engine was requested that is not supported by the version
of OpenSSL being used.</p>
<p><a id="ERR_CRYPTO_ECDH_INVALID_FORMAT"></a></p>
<h3>ERR_CRYPTO_ECDH_INVALID_FORMAT<span><a class="mark" href="#errors_err_crypto_ecdh_invalid_format" id="errors_err_crypto_ecdh_invalid_format">#</a></span><span><a class="mark" href="#ERR_CRYPTO_ECDH_INVALID_FORMAT" id="ERR_CRYPTO_ECDH_INVALID_FORMAT">#</a></span></h3>
<p>An invalid value for the <code>format</code> argument was passed to the <code>crypto.ECDH()</code>
class <code>getPublicKey()</code> method.</p>
<p><a id="ERR_CRYPTO_ECDH_INVALID_PUBLIC_KEY"></a></p>
<h3>ERR_CRYPTO_ECDH_INVALID_PUBLIC_KEY<span><a class="mark" href="#errors_err_crypto_ecdh_invalid_public_key" id="errors_err_crypto_ecdh_invalid_public_key">#</a></span><span><a class="mark" href="#ERR_CRYPTO_ECDH_INVALID_PUBLIC_KEY" id="ERR_CRYPTO_ECDH_INVALID_PUBLIC_KEY">#</a></span></h3>
<p>An invalid value for the <code>key</code> argument has been passed to the
<code>crypto.ECDH()</code> class <code>computeSecret()</code> method. It means that the public
key lies outside of the elliptic curve.</p>
<p><a id="ERR_CRYPTO_ENGINE_UNKNOWN"></a></p>
<h3>ERR_CRYPTO_ENGINE_UNKNOWN<span><a class="mark" href="#errors_err_crypto_engine_unknown" id="errors_err_crypto_engine_unknown">#</a></span><span><a class="mark" href="#ERR_CRYPTO_ENGINE_UNKNOWN" id="ERR_CRYPTO_ENGINE_UNKNOWN">#</a></span></h3>
<p>An invalid crypto engine identifier was passed to