@@ -375,19 +375,14 @@ func populateScanTargets(cmdResults *results.SecurityCommandResults, params *Aud
375375 // No need to generate the SBOM if we are not going to use it.
376376 continue
377377 }
378- targetResultsToCompare , err := getTargetResultsToCompare (cmdResults , params .ResultsToCompare (), targetResult )
379- if err != nil {
380- cmdResults .AddGeneralError (fmt .Errorf ("failed to get target results to compare: %s" , err .Error ()), false )
381- continue
382- }
383378 bom .GenerateSbomForTarget (params .BomGenerator ().WithOptions (buildinfo .WithDescriptors (targetResult .GetDescriptors ())),
384379 bom.SbomGeneratorParams {
385380 Target : targetResult ,
386381 AllowPartialResults : params .AllowPartialResults (),
387382 ScanResultsOutputDir : params .scanResultsOutputDir ,
388383 // Diff mode - SCA
389384 DiffMode : params .DiffMode (),
390- TargetResultToCompare : targetResultsToCompare ,
385+ TargetResultToCompare : getTargetResultsToCompare ( cmdResults , params . ResultsToCompare (), targetResult ) ,
391386 },
392387 )
393388 }
@@ -399,16 +394,18 @@ func populateScanTargets(cmdResults *results.SecurityCommandResults, params *Aud
399394 log .Info (fmt .Sprintf ("Performing scans on %d targets:\n %s" , len (cmdResults .Targets ), scanInfo ))
400395}
401396
402- func getTargetResultsToCompare (cmdResults , resultsToCompare * results.SecurityCommandResults , targetResult * results.TargetResults ) (targetResultsToCompare * results.TargetResults , err error ) {
397+ func getTargetResultsToCompare (cmdResults , resultsToCompare * results.SecurityCommandResults , targetResult * results.TargetResults ) (targetResultsToCompare * results.TargetResults ) {
403398 if resultsToCompare == nil {
404399 return
405400 }
406401 targetResultsToCompare = results .SearchTargetResultsByRelativePath (
407402 utils .GetRelativePath (targetResult .Target , cmdResults .GetCommonParentPath ()),
408403 resultsToCompare ,
409404 )
405+ // Let's check if the target results to compare are valid.
406+ // If the current target result is a new module, it will not have any previous target results to compare with.
410407 if targetResultsToCompare == nil || targetResultsToCompare .ScaResults == nil || targetResultsToCompare .ScaResults .Sbom == nil {
411- err = fmt .Errorf ( "no target results found to compare" )
408+ log . Debug ( fmt .Sprintf ( "No previous target results found to compare with for %s" , targetResult . Target ) )
412409 }
413410 return
414411}
0 commit comments