File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -83,13 +83,16 @@ type StreamingHandler = (r: SgSearch[]) => void
8383let child : ChildProcessWithoutNullStreams | undefined
8484
8585async function uniqueCommand (
86- proc : ChildProcessWithoutNullStreams ,
86+ proc : ChildProcessWithoutNullStreams | undefined ,
8787 handler : StreamingHandler ,
8888) {
8989 // kill previous search
9090 if ( child ) {
9191 child . kill ( 'SIGTERM' )
9292 }
93+ if ( ! proc ) {
94+ return Promise . resolve ( )
95+ }
9396 try {
9497 // set current proc to child
9598 child = proc
@@ -140,13 +143,12 @@ function getPatternRes(query: SearchQuery, handlers: Handlers) {
140143 includeFiles : [ query . includeFile ] ,
141144 rewrite : query . rewrite ,
142145 } )
143- if ( ! proc ) {
144- return Promise . resolve ( )
146+ if ( proc ) {
147+ proc . on ( 'error' , error => {
148+ console . debug ( 'ast-grep CLI runs error' )
149+ handlers . onError ( error )
150+ } )
145151 }
146- proc . on ( 'error' , error => {
147- console . debug ( 'ast-grep CLI runs error' )
148- handlers . onError ( error )
149- } )
150152 return uniqueCommand ( proc , handlers . onData )
151153}
152154
You can’t perform that action at this time.
0 commit comments