Skip to content

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

Merged
merged 3 commits into from
Apr 26, 2023

Conversation

henrymercer
Copy link
Contributor

This PR updates the JS autobuilder's use of the DiagnosticLocation class to take advantage of an internal change that more gracefully handles invalid locations.

@henrymercer henrymercer added the depends on internal PR This PR should only be merged in sync with an internal Semmle PR label Apr 20, 2023
@henrymercer henrymercer requested a review from a team as a code owner April 20, 2023 17:10
@github-actions github-actions bot added the JS label Apr 20, 2023
erik-krogh
erik-krogh previously approved these changes Apr 21, 2023
Copy link
Contributor

@erik-krogh erik-krogh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

But I think some of the indentation looks weird.

Comment on lines 690 to 691
@Override
public int compare(File f1, File f2) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This indentation looks weird?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed. Out of interest, how do you tend to edit these files? There doesn't seem to be a formatter configured in Eclipse.

if (diagLoc.isPresent()) {
writeDiagnostics(msg, JSDiagnosticKind.PARSE_ERROR, diagLoc.get());
} else {
msg += "\n\nRelated file: " + file;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we should "leak" the folder hierarchy of the machine on which the analysis was run into the diagnostic message.

We should probably include a DiagnosticLocation with just the file path if the build() method fails due to invalid position information.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we should "leak" the folder hierarchy of the machine on which the analysis was run into the diagnostic message.

That seems reasonable, particularly for the status page. Done.

We should probably include a DiagnosticLocation with just the file path if the build() method fails due to invalid position information.

We're just checking startLine <= endLine, so my understanding is we should never fail here due to invalid position information.

@henrymercer henrymercer force-pushed the henrymercer/diagnostics-verify-one-based branch from c3f98c4 to f91da38 Compare April 24, 2023 19:35
@henrymercer henrymercer force-pushed the henrymercer/diagnostics-verify-one-based branch from f91da38 to 927522c Compare April 24, 2023 19:54
@henrymercer
Copy link
Contributor Author

@aibaars @erik-krogh Would you mind taking another look? Thanks!

.build();
writeDiagnostics(msg, JSDiagnosticKind.PARSE_ERROR, diagLoc);
.build()
.getOk();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ql/javascript/extractor/src/com/semmle/js/extractor/AutoBuild.java:1252: error: cannot find symbol
            .getOk();
            ^
  symbol:   method getOk()
  location: class DiagnosticLocation

Copy link
Contributor Author

@henrymercer henrymercer Apr 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is due to us changing the DiagnosticLocation API in the corresponding internal PR (backlinked above). The tests are passing there.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this PR depends on another PR.

@henrymercer henrymercer merged commit 1ae116c into main Apr 26, 2023
@henrymercer henrymercer deleted the henrymercer/diagnostics-verify-one-based branch April 26, 2023 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
depends on internal PR This PR should only be merged in sync with an internal Semmle PR JS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants