|
26 | 26 | import java.util.LinkedHashSet;
|
27 | 27 | import java.util.List;
|
28 | 28 | import java.util.Map;
|
| 29 | +import java.util.Optional; |
29 | 30 | import java.util.Set;
|
30 | 31 | import java.util.concurrent.CompletableFuture;
|
31 | 32 | import java.util.concurrent.ExecutorService;
|
@@ -1237,19 +1238,29 @@ private void doExtract(FileExtractor extractor, Path file, ExtractorState state)
|
1237 | 1238 | List<ParseError> errors = loc == null ? Collections.emptyList() : loc.getParseErrors();
|
1238 | 1239 | for (ParseError err : errors) {
|
1239 | 1240 | String msg = "A parse error occurred: " + StringUtil.quoteWithBackticks(err.getMessage().trim())
|
1240 |
| - + ". Check the syntax of the file. If the file is invalid, correct the error or [exclude](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/customizing-code-scanning) the file from analysis."; |
1241 |
| - // file, relative to the source root |
1242 |
| - DiagnosticLocation.Builder builder = DiagnosticLocation.builder(); |
| 1241 | + + "."; |
| 1242 | + |
| 1243 | + Optional<DiagnosticLocation> diagLoc = Optional.empty(); |
1243 | 1244 | if (file.startsWith(LGTM_SRC)) {
|
1244 |
| - builder = builder.setFile(file.subpath(LGTM_SRC.getNameCount(), file.getNameCount()).toString()); |
1245 |
| - } |
1246 |
| - DiagnosticLocation diagLoc = builder |
| 1245 | + diagLoc = DiagnosticLocation.builder() |
| 1246 | + .setFile(file.subpath(LGTM_SRC.getNameCount(), file.getNameCount()).toString()) // file, relative to the source root |
1247 | 1247 | .setStartLine(err.getPosition().getLine())
|
1248 | 1248 | .setStartColumn(err.getPosition().getColumn() + 1) // convert from 0-based to 1-based
|
1249 | 1249 | .setEndLine(err.getPosition().getLine())
|
1250 | 1250 | .setEndColumn(err.getPosition().getColumn() + 1) // convert from 0-based to 1-based
|
1251 |
| - .build(); |
1252 |
| - writeDiagnostics(msg, JSDiagnosticKind.PARSE_ERROR, diagLoc); |
| 1251 | + .build() |
| 1252 | + .getOk(); |
| 1253 | + } |
| 1254 | + if (diagLoc.isPresent()) { |
| 1255 | + msg += " Check the syntax of the file. If the file is invalid, correct the error or " |
| 1256 | + + "[exclude](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-" |
| 1257 | + + "your-code-for-vulnerabilities-and-errors/customizing-code-scanning) the file from analysis."; |
| 1258 | + writeDiagnostics(msg, JSDiagnosticKind.PARSE_ERROR, diagLoc.get()); |
| 1259 | + } else { |
| 1260 | + msg += " The affected file is not located within the code being analyzed." |
| 1261 | + + (Env.systemEnv().isActions() ? " Please see the workflow run logs for more information." : ""); |
| 1262 | + writeDiagnostics(msg, JSDiagnosticKind.PARSE_ERROR); |
| 1263 | + } |
1253 | 1264 | }
|
1254 | 1265 | logEndProcess(start, "Done extracting " + file);
|
1255 | 1266 | } catch (OutOfMemoryError oom) {
|
|
0 commit comments