Skip to content

Commit

Permalink
Delete extension context secrets if we get an error when getting them. (
Browse files Browse the repository at this point in the history
#5426)

Small fixes on error handling.
  • Loading branch information
David Kutugata authored Apr 6, 2021
1 parent 1e03459 commit 54bc65d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
2 changes: 2 additions & 0 deletions news/2 Fixes/5419.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Delete extension context secrets if we get an error when getting them.
Small fixes on error handling.
12 changes: 9 additions & 3 deletions src/client/common/application/encryptedStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,14 @@ export class EncryptedStorage implements IEncryptedStorage {
if (IS_REMOTE_NATIVE_TEST && this.extensionContext.extensionMode !== ExtensionMode.Production) {
return this.testingState.get(`${service}#${key}`);
}
// eslint-disable-next-line
const val = await this.extensionContext.secrets.get(`${service}.${key}`);
return val;
try {
// eslint-disable-next-line
const val = await this.extensionContext.secrets.get(`${service}.${key}`);
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;
}
}
}
4 changes: 3 additions & 1 deletion src/client/common/errors/errorUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ export function getLastFrameFromPythonTraceback(
}
// File "/Users/donjayamanne/miniconda3/envs/env3/lib/python3.7/site-packages/appnope/_nope.py", line 38, in C

const lastFrame = traceback
// This parameter might be either a string or a string array
const fixedTraceback: string = Array.isArray(traceback) ? traceback[0] : traceback;
const lastFrame = fixedTraceback
.split('\n')
.map((item) => item.trim().toLowerCase())
.filter((item) => item.length)
Expand Down
8 changes: 6 additions & 2 deletions src/client/common/errors/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ const taggers = [
];
export function getErrorTags(stdErrOrStackTrace: string) {
const tags: string[] = [];
stdErrOrStackTrace = stdErrOrStackTrace.toLowerCase();
taggers.forEach((tagger) => tagger(stdErrOrStackTrace, tags));

// This parameter might be either a string or a string array
let stdErrOrStackTraceLowered = Array.isArray(stdErrOrStackTrace)
? stdErrOrStackTrace[0].toLowerCase()
: stdErrOrStackTrace.toLowerCase();
taggers.forEach((tagger) => tagger(stdErrOrStackTraceLowered, tags));

return Array.from(new Set(tags)).join(',');
}
Expand Down

0 comments on commit 54bc65d

Please sign in to comment.