Skip to content
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

null check reanalyze output #456

Merged
merged 1 commit into from
Jun 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 25 additions & 16 deletions client/src/commands/code_analysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@ export type DiagnosticsResultCodeActionsMap = Map<
{ range: Range; codeAction: CodeAction }[]
>;

export type DiagnosticsResultFormat = Array<{
name: string;
kind: string;
file: string;
range: [number, number, number, number];
message: string;
annotate?: {
line: number;
character: number;
text: string;
action: string;
};
}>;

let resultsToDiagnostics = (
results: [
{
name: string;
kind: string;
file: string;
range: [number, number, number, number];
message: string;
annotate?: {
line: number;
character: number;
text: string;
action: string;
};
}
],
results: DiagnosticsResultFormat,
diagnosticsResultCodeActions: DiagnosticsResultCodeActionsMap
): {
diagnosticsMap: Map<string, Diagnostic[]>;
Expand Down Expand Up @@ -202,13 +202,22 @@ export const runCodeAnalysisWithReanalyze = (
p.on("close", () => {
diagnosticsResultCodeActions.clear();

let json: DiagnosticsResultFormat | null = null;

try {
var json = JSON.parse(data);
json = JSON.parse(data);
} catch (e) {
window.showErrorMessage(
`Something went wrong parsing the json output of reanalyze: '${e}'`
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add a bit more. How about encouraging reporting the issue.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll add this in a separate PR when I've figured out what makes sense to tell the user here.

);
}

if (json == null) {
// If reanalyze failed for some reason we'll clear the diagnostics.
diagnosticsCollection.clear();
return;
}

let { diagnosticsMap } = resultsToDiagnostics(
json,
diagnosticsResultCodeActions
Expand Down