File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -203,9 +203,25 @@ async function runCppcheckOnFileXML(
203203
204204 const proc = cp . spawn ( commandPath , args ) ;
205205
206+ // if spawn fails (e.g. ENOENT or permission denied)
207+ proc . on ( "error" , ( err ) => {
208+ console . error ( "Failed to start cppcheck:" , err ) ;
209+ vscode . window . showErrorMessage ( `Cppcheck failed to start: ${ err . message } ` ) ;
210+ } ) ;
211+
206212 let xmlOutput = "" ;
213+ let out = "" ;
207214 proc . stderr . on ( "data" , d => xmlOutput += d . toString ( ) ) ;
208- proc . on ( "close" , ( ) => {
215+ proc . stdout . on ( "data" , d => out += d . toString ( ) ) ;
216+ proc . on ( "close" , code => {
217+ if ( code && code > 0 ) {
218+ // Non-zero code means an error has occured
219+ let errorMessage = `Cppcheck failed with code ${ code } (unknown error)` ;
220+ if ( out . trim ( ) . length > 0 ) {
221+ errorMessage = out . trim ( ) ;
222+ }
223+ vscode . window . showErrorMessage ( errorMessage ) ;
224+ }
209225 const parser = new xml2js . Parser ( { explicitArray : true } ) ;
210226 parser . parseString ( xmlOutput , ( err , result ) => {
211227 if ( err ) {
You can’t perform that action at this time.
0 commit comments