Skip to content

Commit

Permalink
chore(vulnerable-code): Log details about the error cause of an issue
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Schuberth <[email protected]>
  • Loading branch information
sschuberth committed Feb 2, 2024
1 parent 5b63a3f commit 4f8cb5e
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import java.net.URI
import java.time.Instant
import java.util.concurrent.TimeUnit

import org.apache.logging.log4j.kotlin.logger

import org.ossreviewtoolkit.advisor.AdviceProvider
import org.ossreviewtoolkit.advisor.AdviceProviderFactory
import org.ossreviewtoolkit.clients.vulnerablecode.VulnerableCodeService
Expand Down Expand Up @@ -96,11 +98,12 @@ class VulnerableCode(name: String, config: VulnerableCodeConfiguration) : Advice
val startTime = Instant.now()

val purls = packages.mapNotNull { pkg -> pkg.purl.takeUnless { it.isEmpty() } }
val chunks = purls.chunked(BULK_REQUEST_SIZE)

val allVulnerabilities = mutableMapOf<String, List<VulnerableCodeService.Vulnerability>>()
val issues = mutableListOf<Issue>()

purls.chunked(BULK_REQUEST_SIZE).forEach { chunk ->
chunks.forEachIndexed { index, chunk ->
runCatching {
val chunkVulnerabilities = service.getPackageVulnerabilities(PackagesWrapper(chunk)).filter {
it.affectedByVulnerabilities.isNotEmpty()
Expand All @@ -113,6 +116,12 @@ class VulnerableCode(name: String, config: VulnerableCodeConfiguration) : Advice
allVulnerabilities += chunk.associateWith { emptyList() }

issues += Issue(source = providerName, message = it.collectMessages())

logger.error {
"The request of chunk ${index + 1} of ${chunks.size} failed for the following ${chunk.size} " +
"PURL(s):"
}
chunk.forEach(logger::error)
}
}

Expand Down

0 comments on commit 4f8cb5e

Please sign in to comment.