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

Delete encrypted storage in a try catch to avoid errors. #5942

Merged
merged 2 commits into from
May 20, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions news/2 Fixes/5934.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Delete encrypted storage in a try catch to avoid errors.
15 changes: 12 additions & 3 deletions src/client/common/application/encryptedStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { inject, injectable } from 'inversify';
import { ExtensionMode } from 'vscode';
import { IS_REMOTE_NATIVE_TEST } from '../../../test/constants';
import { traceError } from '../logger';
import { IExtensionContext } from '../types';
import { IEncryptedStorage } from './types';

Expand All @@ -24,7 +25,11 @@ export class EncryptedStorage implements IEncryptedStorage {
}

if (!value) {
await this.extensionContext.secrets.delete(`${service}.${key}`);
try {
await this.extensionContext.secrets.delete(`${service}.${key}`);
} catch (e) {
traceError(e);
}
} else {
await this.extensionContext.secrets.store(`${service}.${key}`, value);
}
Expand All @@ -40,8 +45,12 @@ export class EncryptedStorage implements IEncryptedStorage {
return val;
} catch (e) {
// If we get an error trying to get a secret, it might be corrupted. So we delete it.
await this.extensionContext.secrets.delete(`${service}.${key}`);
return;
try {
this.extensionContext.secrets.delete(`${service}.${key}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this won't be caught here. The promise is ignored.

You might try this instead:

this.extensionContext.secrets.delete(`${service}.${key}`).catch(traceError);

Copy link
Author

Choose a reason for hiding this comment

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

thenables don't have .catch

Copy link
Author

Choose a reason for hiding this comment

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

I'll put the await back

return;
} catch (e) {
traceError(e);
}
}
}
}