Skip to content

Fix deserialization error #1605

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 2 commits into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions extensions/ql-vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## [UNRELEASED]

- Fix a bug where results created in older versions were thought to be unsuccessful. [#1605](https://github.com/github/vscode-codeql/pull/1605)

## 1.7.1 - 12 October 2022

- Fix a bug where it was not possible to add a database folder if the folder name starts with `db-`. [#1565](https://github.com/github/vscode-codeql/pull/1565)
Expand Down
17 changes: 16 additions & 1 deletion extensions/ql-vscode/src/query-serialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { CompletedQueryInfo, LocalQueryInfo } from './query-results';
import { QueryHistoryInfo } from './query-history-info';
import { QueryStatus } from './query-status';
import { QueryEvaluationInfo } from './run-queries-shared';
import { QueryResultType } from './pure/legacy-messages';

export async function slurpQueryHistory(fsPath: string): Promise<QueryHistoryInfo[]> {
try {
Expand Down Expand Up @@ -39,6 +40,17 @@ export async function slurpQueryHistory(fsPath: string): Promise<QueryHistoryInf
Object.setPrototypeOf(q.completedQuery.query, QueryEvaluationInfo.prototype);
// slurped queries do not need to be disposed
q.completedQuery.dispose = () => { /**/ };

// Previously, there was a typo in the completedQuery type. There was a field
// `sucessful` and it was renamed to `successful`. We need to handle this case.
if ('sucessful' in q.completedQuery) {
(q.completedQuery as any).successful = (q.completedQuery as any).sucessful;
delete (q.completedQuery as any).sucessful;
}

if (!('successful' in q.completedQuery)) {
(q.completedQuery as any).successful = q.completedQuery.result?.resultType === QueryResultType.SUCCESS;
}
}
} else if (q.t === 'remote') {
// A bug was introduced that didn't set the completed flag in query history
Expand Down Expand Up @@ -91,7 +103,10 @@ export async function splatQueryHistory(queries: QueryHistoryInfo[], fsPath: str
// remove incomplete local queries since they cannot be recreated on restart
const filteredQueries = queries.filter(q => q.t === 'local' ? q.completedQuery !== undefined : true);
const data = JSON.stringify({
version: 2, // version 2 adds the `variant-analysis` type.
// version 2:
// - adds the `variant-analysis` type
// - ensures a `successful` property exists on completedQuery
version: 2,
queries: filteredQueries
}, null, 2);
await fs.writeFile(fsPath, data);
Expand Down