Skip to content

Commit

Permalink
More graceful failure when expected files are missing in Semgrep (#436)
Browse files Browse the repository at this point in the history
Although some use cases are very strict about SARIF-referenced files
being present, others aren't (like testing) -- we should handle this
more gracefully.
  • Loading branch information
nahsra authored Aug 1, 2024
1 parent 35ba4a8 commit 42f1f73
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
import com.contrastsecurity.sarif.SarifSchema210;
import io.codemodder.RuleSarif;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* {@inheritDoc}
Expand Down Expand Up @@ -77,8 +78,10 @@ public List<Result> getResultsByLocationPath(final Path path) {
.getUri();
try {
return Files.isSameFile(path, repositoryRoot.resolve(uri));
} catch (IOException e) { // this should never happen
throw new UncheckedIOException(e);
} catch (IOException e) {
// this can happen if the file referenced in SARIF doesn't exist (like in tests)
log.debug("Couldn't find file referenced in SARIF", e);
return false;
}
})
.toList();
Expand All @@ -91,5 +94,5 @@ public String getDriver() {
return sarif.getRuns().get(0).getTool().getDriver().getName();
}

static final String toolName = "semgrep";
private static final Logger log = LoggerFactory.getLogger(SingleSemgrepRuleSarif.class);
}

0 comments on commit 42f1f73

Please sign in to comment.