Skip to content

Commit c6dc54d

Browse files
fourlscirras
authored andcommitted
Gracefully handle exceptions in check execution
1 parent 3aeb072 commit c6dc54d

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

delphi-frontend/src/main/java/au/com/integradev/delphi/executor/DelphiChecksExecutor.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import au.com.integradev.delphi.preprocessor.directive.CompilerDirectiveParserImpl;
2727
import java.util.Set;
2828
import java.util.function.Function;
29+
import org.slf4j.Logger;
30+
import org.slf4j.LoggerFactory;
2931
import org.sonar.api.SonarProduct;
3032
import org.sonar.api.SonarRuntime;
3133
import org.sonar.api.batch.fs.InputFile;
@@ -37,6 +39,8 @@
3739
import org.sonar.plugins.communitydelphi.api.directive.CompilerDirectiveParser;
3840

3941
public class DelphiChecksExecutor implements Executor {
42+
private static final Logger LOG = LoggerFactory.getLogger(DelphiChecksExecutor.class);
43+
4044
private final DelphiProjectHelper delphiProjectHelper;
4145
private final MasterCheckRegistrar checkRegistrar;
4246
private final SonarRuntime sonarRuntime;
@@ -79,9 +83,18 @@ private void runChecks(
7983
.forEach(
8084
check -> {
8185
DelphiCheckContext context = createCheckContext.apply(check);
82-
check.start(context);
83-
check.visit(context.getAst(), context);
84-
check.end(context);
86+
try {
87+
check.start(context);
88+
check.visit(context.getAst(), context);
89+
check.end(context);
90+
} catch (Exception e) {
91+
LOG.error(
92+
"Error occurred while running check {} on file: {}",
93+
check.getClass().getSimpleName(),
94+
context.getAst().getDelphiFile().getSourceCodeFile().getName(),
95+
e);
96+
LOG.info("Continuing with next check.");
97+
}
8598
});
8699
}
87100

0 commit comments

Comments
 (0)