Skip to content

Commit 42f1f73

Browse files
authored
More graceful failure when expected files are missing in Semgrep (#436)
Although some use cases are very strict about SARIF-referenced files being present, others aren't (like testing) -- we should handle this more gracefully.
1 parent 35ba4a8 commit 42f1f73

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

plugins/codemodder-plugin-semgrep/src/main/java/io/codemodder/providers/sarif/semgrep/SingleSemgrepRuleSarif.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
import com.contrastsecurity.sarif.SarifSchema210;
66
import io.codemodder.RuleSarif;
77
import java.io.IOException;
8-
import java.io.UncheckedIOException;
98
import java.nio.file.Files;
109
import java.nio.file.Path;
1110
import java.util.*;
11+
import org.slf4j.Logger;
12+
import org.slf4j.LoggerFactory;
1213

1314
/**
1415
* {@inheritDoc}
@@ -77,8 +78,10 @@ public List<Result> getResultsByLocationPath(final Path path) {
7778
.getUri();
7879
try {
7980
return Files.isSameFile(path, repositoryRoot.resolve(uri));
80-
} catch (IOException e) { // this should never happen
81-
throw new UncheckedIOException(e);
81+
} catch (IOException e) {
82+
// this can happen if the file referenced in SARIF doesn't exist (like in tests)
83+
log.debug("Couldn't find file referenced in SARIF", e);
84+
return false;
8285
}
8386
})
8487
.toList();
@@ -91,5 +94,5 @@ public String getDriver() {
9194
return sarif.getRuns().get(0).getTool().getDriver().getName();
9295
}
9396

94-
static final String toolName = "semgrep";
97+
private static final Logger log = LoggerFactory.getLogger(SingleSemgrepRuleSarif.class);
9598
}

0 commit comments

Comments
 (0)