1
1
import assert from "node:assert/strict" ;
2
2
import { describe , it } from "node:test" ;
3
- import util from "node:util" ;
4
3
5
4
import {
6
5
HardhatError ,
@@ -32,10 +31,10 @@ describe("error-handler", () => {
32
31
describe ( "printErrorMessages" , ( ) => {
33
32
describe ( "with a Hardhat error" , ( ) => {
34
33
it ( "should print the error message" , ( ) => {
35
- const lines : string [ ] = [ ] ;
34
+ const lines : Array < string | Error > = [ ] ;
36
35
const error = new HardhatError ( mockCoreErrorDescriptor ) ;
37
36
38
- printErrorMessages ( error , false , ( msg : string ) => {
37
+ printErrorMessages ( error , false , ( msg : string | Error ) => {
39
38
lines . push ( msg ) ;
40
39
} ) ;
41
40
@@ -53,10 +52,10 @@ describe("error-handler", () => {
53
52
} ) ;
54
53
55
54
it ( "should print the stack trace" , ( ) => {
56
- const lines : string [ ] = [ ] ;
55
+ const lines : Array < string | Error > = [ ] ;
57
56
const error = new HardhatError ( mockCoreErrorDescriptor ) ;
58
57
59
- printErrorMessages ( error , true , ( msg : string ) => {
58
+ printErrorMessages ( error , true , ( msg : string | Error ) => {
60
59
lines . push ( msg ) ;
61
60
} ) ;
62
61
@@ -66,16 +65,16 @@ describe("error-handler", () => {
66
65
`${ chalk . red . bold ( `Error ${ error . errorCode } :` ) } ${ error . formattedMessage } ` ,
67
66
) ;
68
67
assert . equal ( lines [ 1 ] , "" ) ;
69
- assert . equal ( lines [ 2 ] , ` ${ error . stack } ` ) ;
68
+ assert . equal ( lines [ 2 ] , error ) ;
70
69
} ) ;
71
70
} ) ;
72
71
73
72
describe ( "with a Hardhat plugin error" , ( ) => {
74
73
it ( "should print the error message" , ( ) => {
75
- const lines : string [ ] = [ ] ;
74
+ const lines : Array < string | Error > = [ ] ;
76
75
const error = new HardhatError ( mockPluginErrorDescriptor ) ;
77
76
78
- printErrorMessages ( error , false , ( msg : string ) => {
77
+ printErrorMessages ( error , false , ( msg : string | Error ) => {
79
78
lines . push ( msg ) ;
80
79
} ) ;
81
80
@@ -93,10 +92,10 @@ describe("error-handler", () => {
93
92
} ) ;
94
93
95
94
it ( "should print the stack trace" , ( ) => {
96
- const lines : string [ ] = [ ] ;
95
+ const lines : Array < string | Error > = [ ] ;
97
96
const error = new HardhatError ( mockPluginErrorDescriptor ) ;
98
97
99
- printErrorMessages ( error , true , ( msg : string ) => {
98
+ printErrorMessages ( error , true , ( msg : string | Error ) => {
100
99
lines . push ( msg ) ;
101
100
} ) ;
102
101
@@ -106,19 +105,19 @@ describe("error-handler", () => {
106
105
`${ chalk . red . bold ( `Error ${ error . errorCode } in plugin ${ error . pluginId } :` ) } ${ error . formattedMessage } ` ,
107
106
) ;
108
107
assert . equal ( lines [ 1 ] , "" ) ;
109
- assert . equal ( lines [ 2 ] , ` ${ error . stack } ` ) ;
108
+ assert . equal ( lines [ 2 ] , error ) ;
110
109
} ) ;
111
110
} ) ;
112
111
113
112
describe ( "with a Hardhat community plugin error" , ( ) => {
114
113
it ( "should print the error message" , ( ) => {
115
- const lines : string [ ] = [ ] ;
114
+ const lines : Array < string | Error > = [ ] ;
116
115
const error = new HardhatPluginError (
117
116
"community-plugin" ,
118
117
"error message" ,
119
118
) ;
120
119
121
- printErrorMessages ( error , false , ( msg : string ) => {
120
+ printErrorMessages ( error , false , ( msg : string | Error ) => {
122
121
lines . push ( msg ) ;
123
122
} ) ;
124
123
@@ -135,13 +134,13 @@ describe("error-handler", () => {
135
134
} ) ;
136
135
137
136
it ( "should print the stack trace" , ( ) => {
138
- const lines : string [ ] = [ ] ;
137
+ const lines : Array < string | Error > = [ ] ;
139
138
const error = new HardhatPluginError (
140
139
"community-plugin" ,
141
140
"error message" ,
142
141
) ;
143
142
144
- printErrorMessages ( error , true , ( msg : string ) => {
143
+ printErrorMessages ( error , true , ( msg : string | Error ) => {
145
144
lines . push ( msg ) ;
146
145
} ) ;
147
146
@@ -151,42 +150,23 @@ describe("error-handler", () => {
151
150
`${ chalk . red . bold ( `Error in community plugin ${ error . pluginId } :` ) } ${ error . message } ` ,
152
151
) ;
153
152
assert . equal ( lines [ 1 ] , "" ) ;
154
- assert . equal ( lines [ 2 ] , ` ${ error . stack } ` ) ;
153
+ assert . equal ( lines [ 2 ] , error ) ;
155
154
} ) ;
156
155
} ) ;
157
156
158
157
describe ( "with an unknown error" , ( ) => {
159
158
it ( "should print the error message with the stack traces for an instance of Error" , ( ) => {
160
- const lines : string [ ] = [ ] ;
159
+ const lines : Array < string | Error > = [ ] ;
161
160
const error = new Error ( "error message" ) ;
162
161
163
- printErrorMessages ( error , false , ( msg : string ) => {
162
+ printErrorMessages ( error , false , ( msg : string | Error ) => {
164
163
lines . push ( msg ) ;
165
164
} ) ;
166
165
167
166
assert . equal ( lines . length , 5 ) ;
168
167
assert . equal ( lines [ 0 ] , chalk . red . bold ( `An unexpected error occurred:` ) ) ;
169
168
assert . equal ( lines [ 1 ] , "" ) ;
170
- assert . equal ( lines [ 2 ] , `${ error . stack } ` ) ;
171
- assert . equal ( lines [ 3 ] , "" ) ;
172
- assert . equal (
173
- lines [ 4 ] ,
174
- `If you think this is a bug in Hardhat, please report it here: ${ HARDHAT_WEBSITE_URL } report-bug` ,
175
- ) ;
176
- } ) ;
177
-
178
- it ( "should print the error message with the error for an unknown error" , ( ) => {
179
- const lines : string [ ] = [ ] ;
180
- const error = { message : "error message" } ;
181
-
182
- printErrorMessages ( error , false , ( msg : string ) => {
183
- lines . push ( msg ) ;
184
- } ) ;
185
-
186
- assert . equal ( lines . length , 5 ) ;
187
- assert . equal ( lines [ 0 ] , chalk . red . bold ( `An unexpected error occurred:` ) ) ;
188
- assert . equal ( lines [ 1 ] , "" ) ;
189
- assert . equal ( lines [ 2 ] , `${ util . inspect ( error ) } ` ) ;
169
+ assert . equal ( lines [ 2 ] , error ) ;
190
170
assert . equal ( lines [ 3 ] , "" ) ;
191
171
assert . equal (
192
172
lines [ 4 ] ,
0 commit comments