@@ -172,47 +172,42 @@ export async function scanFile(
172172 filePath ,
173173 ] ) ;
174174
175- // Ignore errors concerning usage
176- // This occurs when the path of the file is invalid (i.e.VSCode sending an event for files not on the file system)
177- // or when the file is ignored in the .gitguardian.yaml
178- if (
179- proc . stderr . includes (
180- "Error: An ignored file or directory cannot be scanned"
181- )
182- ) {
183- updateStatusBarItem ( StatusBarStatus . ignoredFile ) ;
184- return ;
185- }
186- if ( proc . stderr . includes ( "Usage: ggshield secret scan path" ) ) {
187- return undefined ;
188- }
189- let errorMessage = "" ;
190- proc . stderr . split ( "\n" ) . forEach ( ( stderrLine ) => {
175+ if ( proc . status === 128 || proc . status === 3 ) {
176+ let errorMessage = "" ;
177+ proc . stderr . split ( "\n" ) . forEach ( ( stderrLine ) => {
178+ if (
179+ stderrLine . length > 0 &&
180+ ! stderrLine . includes ( "Scanning Path..." ) // ggshield outputs this info message on stderr, ignore it
181+ ) {
182+ errorMessage += stderrLine + "\n" ;
183+ }
184+ } ) ;
185+ if ( errorMessage . length > 0 ) {
186+ window . showErrorMessage ( `ggshield: ${ errorMessage } ` ) ;
187+ return undefined ;
188+ }
189+ } else if ( proc . status === 2 ) {
190+ // Ignore errors concerning usage
191+ // This occurs when the path of the file is invalid (i.e.VSCode sending an event for files not on the file system)
192+ // or when the file is ignored in the .gitguardian.yaml
191193 if (
192- stderrLine . length > 0 &&
193- ! stderrLine . includes ( "Scanning Path..." ) // ggshield outputs this info message on stderr, ignore it
194+ proc . stderr . includes (
195+ "Error: An ignored file or directory cannot be scanned"
196+ )
194197 ) {
195- errorMessage += stderrLine + "\n" ;
198+ updateStatusBarItem ( StatusBarStatus . ignoredFile ) ;
199+ return ;
196200 }
197- } ) ;
198- if ( errorMessage . length > 0 ) {
199- window . showErrorMessage ( `ggshield: ${ errorMessage } ` ) ;
200201 return undefined ;
201- }
202-
203- const results = JSON . parse ( proc . stdout ) ;
204- if ( ! results ) {
205- updateStatusBarItem ( StatusBarStatus . ready ) ;
202+ } else if ( proc . status === 0 ) {
203+ updateStatusBarItem ( StatusBarStatus . noSecretFound ) ;
206204 return ;
207- }
208- let incidentsDiagnostics : Diagnostic [ ] = parseGGShieldResults ( results ) ;
209- if ( incidentsDiagnostics . length !== 0 ) {
210- updateStatusBarItem ( StatusBarStatus . secretFound ) ;
211205 } else {
212- updateStatusBarItem ( StatusBarStatus . noSecretFound ) ;
206+ const results = JSON . parse ( proc . stdout ) ;
207+ let incidentsDiagnostics : Diagnostic [ ] = parseGGShieldResults ( results ) ;
208+ updateStatusBarItem ( StatusBarStatus . secretFound ) ;
209+ diagnosticCollection . set ( fileUri , incidentsDiagnostics ) ;
213210 }
214-
215- diagnosticCollection . set ( fileUri , incidentsDiagnostics ) ;
216211}
217212
218213export async function loginGGShield (
0 commit comments