Skip to content

Commit a0b759e

Browse files
committed
Avoid printing a stack trace when there is no resultsPath
I don't know exactly when this can happen, but a customer has just shown me a stack trace like this: ``` TypeError: Cannot destructure property 'resultsPath' of 'resultsPaths' as it is undefined. at Object.interpretResults (/xxx/.vscode/extensions/github.vscode-codeql-1.4.5/out/query-results.js:120:13) at InterfaceManager._getInterpretedResults (/xxx/.vscode/extensions/github.vscode-codeql-1.4.5/out/interface.js:377:45) at InterfaceManager.showResultsAsDiagnostics (/xxx/.vscode/extensions/github.vscode-codeql-1.4.5/out/interface.js:447:43) at runMicrotasks (<anonymous>) at processTicksAndRejections (internal/process/task_queues.js:97:5) at async InterfaceManager.handleMsgFromView (/xxx/.vscode/extensions/github.vscode-codeql-1.4.5/out/interface.js:151:29) ``` This commit will avoid printing this stack trace and instead print a more descriptive message to the logs.
1 parent 58cf4db commit a0b759e

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

extensions/ql-vscode/src/interface.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -554,24 +554,26 @@ export class InterfaceManager extends DisposableObject {
554554
sourceInfo: cli.SourceInfo | undefined,
555555
sourceLocationPrefix: string,
556556
sortState: InterpretedResultsSortState | undefined
557-
): Promise<Interpretation> {
557+
): Promise<Interpretation | undefined> {
558+
if (!resultsPaths) {
559+
this.logger.log('No results path. Cannot display interpreted results.');
560+
return undefined;
561+
}
562+
558563
const sarif = await interpretResults(
559564
this.cliServer,
560565
metadata,
561566
resultsPaths,
562567
sourceInfo
563568
);
569+
564570
sarif.runs.forEach(run => {
565571
if (run.results !== undefined) {
566572
sortInterpretedResults(run.results, sortState);
567573
}
568574
});
569575

570-
const numTotalResults = (() => {
571-
if (sarif.runs.length === 0) return 0;
572-
if (sarif.runs[0].results === undefined) return 0;
573-
return sarif.runs[0].results.length;
574-
})();
576+
const numTotalResults = sarif.runs[0]?.results?.length || 0;
575577

576578
const interpretation: Interpretation = {
577579
sarif,
@@ -673,6 +675,10 @@ export class InterfaceManager extends DisposableObject {
673675
undefined
674676
);
675677

678+
if (!interpretation) {
679+
return;
680+
}
681+
676682
try {
677683
await this.showProblemResultsAsDiagnostics(interpretation, database);
678684
} catch (e) {

0 commit comments

Comments
 (0)