@@ -204,7 +204,7 @@ private static Boolean collectFilesToUpload(ScanTaskState state) {
204204 try {
205205 state .filesToUpload .add (Archiver .archive (state .taskContext .getRootDirectory (), state .includePaths , state .excludePaths , "files_to_scan" ));
206206 } catch (IOException e ) {
207- logError (state , "An error occurred while trying to archive source files: %s" , e . toString () );
207+ logError (state , e , "An error occurred while trying to archive source files" );
208208 return false ;
209209 }
210210
@@ -249,7 +249,7 @@ private static Boolean uploadFiles(ScanTaskState state) {
249249 logApiException (state , e );
250250 return false ;
251251 } catch (IOException e ) {
252- logError (state , "An error occurred while trying to archive source files: %s" , e . toString () );
252+ logError (state , e , "An error occurred while trying to archive source files" );
253253 return false ;
254254 }
255255
@@ -265,7 +265,7 @@ private static Boolean waitForCodeDxToBeReadyForAnalysis(ScanTaskState state) {
265265 try {
266266 Thread .sleep (1000 ); // Consider adding maximum wait time
267267 } catch (InterruptedException e ) {
268- logError (state , "An unexpected threading issue occurred. This could occur if the build is manually cancelled. Exception: %s" , e . toString () );
268+ logError (state , e , "An unexpected threading issue occurred. This could occur if the build is manually cancelled." );
269269 return false ;
270270 }
271271
@@ -354,7 +354,7 @@ private static Boolean waitForAnalysisToFinish(ScanTaskState state) {
354354 try {
355355 Thread .sleep (5000 ); // Consider adding maximum wait time
356356 } catch (InterruptedException e ) {
357- logError (state , "An unexpected threading issue occurred. This could occur if the build is manually cancelled. Exception: %s" , e . toString () );
357+ logError (state , e , "An unexpected threading issue occurred. This could occur if the build is manually cancelled." );
358358 return false ;
359359 }
360360
@@ -468,13 +468,19 @@ private static void log(ScanTaskState state, String format, Object... args) {
468468 _logger .info (message );
469469 }
470470
471+ private static void logError (ScanTaskState state , Exception e , String format , Object ... args ) {
472+ String errorMessage = String .format (format , args );
473+ state .buildLogger .addErrorLogEntry (String .format ("%s || Exception - %s" , errorMessage , e .toString ()));
474+ _logger .error (errorMessage , e );
475+ }
476+
471477 private static void logError (ScanTaskState state , String format , Object ... args ) {
472- String error = String .format (format , args );
473- state .buildLogger .addErrorLogEntry (error );
474- _logger .error (error );
478+ String errorMessage = String .format (format , args );
479+ state .buildLogger .addErrorLogEntry (errorMessage );
480+ _logger .error (errorMessage );
475481 }
476482
477483 private static void logApiException (ScanTaskState state , Exception e ) {
478- logError (state , "An error occurred while trying to communicate with Code Dx's API: %s" , e . toString () );
484+ logError (state , e , "An error occurred while trying to communicate with Code Dx's API" );
479485 }
480486}
0 commit comments