-
Notifications
You must be signed in to change notification settings - Fork 1.8k
JS: Update DiagnosticLocation
call to gracefully handle invalid locations
#12895
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
import java.util.LinkedHashSet; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.ExecutorService; | ||
|
@@ -1237,19 +1238,29 @@ private void doExtract(FileExtractor extractor, Path file, ExtractorState state) | |
List<ParseError> errors = loc == null ? Collections.emptyList() : loc.getParseErrors(); | ||
for (ParseError err : errors) { | ||
String msg = "A parse error occurred: " + StringUtil.quoteWithBackticks(err.getMessage().trim()) | ||
+ ". 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."; | ||
// file, relative to the source root | ||
DiagnosticLocation.Builder builder = DiagnosticLocation.builder(); | ||
+ "."; | ||
|
||
Optional<DiagnosticLocation> diagLoc = Optional.empty(); | ||
if (file.startsWith(LGTM_SRC)) { | ||
builder = builder.setFile(file.subpath(LGTM_SRC.getNameCount(), file.getNameCount()).toString()); | ||
} | ||
DiagnosticLocation diagLoc = builder | ||
diagLoc = DiagnosticLocation.builder() | ||
.setFile(file.subpath(LGTM_SRC.getNameCount(), file.getNameCount()).toString()) // file, relative to the source root | ||
.setStartLine(err.getPosition().getLine()) | ||
.setStartColumn(err.getPosition().getColumn() + 1) // convert from 0-based to 1-based | ||
.setEndLine(err.getPosition().getLine()) | ||
.setEndColumn(err.getPosition().getColumn() + 1) // convert from 0-based to 1-based | ||
.build(); | ||
writeDiagnostics(msg, JSDiagnosticKind.PARSE_ERROR, diagLoc); | ||
.build() | ||
.getOk(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is due to us changing the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess this PR depends on another PR. |
||
} | ||
if (diagLoc.isPresent()) { | ||
msg += " 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."; | ||
writeDiagnostics(msg, JSDiagnosticKind.PARSE_ERROR, diagLoc.get()); | ||
} else { | ||
msg += " The affected file is not located within the code being analyzed." | ||
+ (Env.systemEnv().isActions() ? " Please see the workflow run logs for more information." : ""); | ||
writeDiagnostics(msg, JSDiagnosticKind.PARSE_ERROR); | ||
} | ||
} | ||
logEndProcess(start, "Done extracting " + file); | ||
} catch (OutOfMemoryError oom) { | ||
|
Uh oh!
There was an error while loading. Please reload this page.