@@ -134,13 +134,29 @@ export function runProgram(
134
134
) {
135
135
const transform = new ReadlineTransform ( { skipEmpty : true } ) ;
136
136
const proc = spawn ( command , arguments_ , options ) ;
137
+ let recentMessage : string ;
138
+ let errorMessage : string ;
137
139
proc . stdout . setEncoding ( "utf8" ) ;
138
140
proc . stdout
139
- . pipe ( transform )
140
- // TODO: Review this JSONStream.parse()
141
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
142
- // @ts -ignore
143
- . pipe ( JSONStream . parse ( ) )
141
+ . pipe (
142
+ transform . on ( "error" , ( error ) => {
143
+ throw error ;
144
+ } )
145
+ )
146
+ . pipe (
147
+ eventStream . mapSync ( ( data : string ) => {
148
+ recentMessage = data ;
149
+ return data ;
150
+ } )
151
+ )
152
+ . pipe (
153
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
154
+ // @ts -ignore -- JSONStream.parse() accepts (pattern: any) when it should accept (pattern?: any)
155
+ JSONStream . parse ( ) . on ( "error" , ( ) => {
156
+ errorMessage = recentMessage ;
157
+ throw new Error ( errorMessage ) ;
158
+ } )
159
+ )
144
160
. pipe (
145
161
eventStream . mapSync ( ( data : unknown ) => {
146
162
if ( ! data ) return ;
@@ -167,8 +183,15 @@ export function runProgram(
167
183
} )
168
184
) ;
169
185
return new Promise < void > ( ( resolve , reject ) => {
170
- proc . on ( "close" , ( ) => resolve ( ) ) ;
171
- proc . on ( "error" , ( error ) => reject ( error ) ) ;
186
+ proc . on ( "close" , ( ) => {
187
+ if ( errorMessage ) {
188
+ return reject ( new Error ( errorMessage ) ) ;
189
+ }
190
+ return resolve ( ) ;
191
+ } ) ;
192
+ proc . on ( "error" , ( error ) =>
193
+ reject ( errorMessage ? new Error ( errorMessage ) : error )
194
+ ) ;
172
195
} ) ;
173
196
}
174
197
0 commit comments