1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Properly propagate promises in Kubectl.ensureKubectl to avoid UnhandledPromiseRejections (#4243)

This commit is contained in:
Sebastian Malton 2021-11-03 12:28:12 -04:00 committed by GitHub
parent 368e2d9a00
commit 28e182a2a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -257,40 +257,46 @@ export class Kubectl {
return false;
}
await ensureDir(this.dirname, 0o755);
return lockFile.lock(this.dirname).then(async (release) => {
try {
const release = await lockFile.lock(this.dirname);
logger.debug(`Acquired a lock for ${this.kubectlVersion}`);
const bundled = await this.checkBundled();
let isValid = await this.checkBinary(this.path, !bundled);
if (!isValid && !bundled) {
await this.downloadKubectl().catch((error) => {
logger.error(error);
logger.debug(`Releasing lock for ${this.kubectlVersion}`);
release();
try {
await this.downloadKubectl();
} catch (error) {
logger.error(`[KUBECTL]: failed to download kubectl`, error);
logger.debug(`[KUBECTL]: Releasing lock for ${this.kubectlVersion}`);
await release();
return false;
});
}
isValid = await this.checkBinary(this.path, false);
}
if (!isValid) {
logger.debug(`Releasing lock for ${this.kubectlVersion}`);
release();
logger.debug(`[KUBECTL]: Releasing lock for ${this.kubectlVersion}`);
await release();
return false;
}
logger.debug(`Releasing lock for ${this.kubectlVersion}`);
release();
logger.debug(`[KUBECTL]: Releasing lock for ${this.kubectlVersion}`);
await release();
return true;
}).catch((e) => {
logger.error(`Failed to get a lock for ${this.kubectlVersion}`);
logger.error(e);
} catch (error) {
logger.error(`[KUBECTL]: Failed to get a lock for ${this.kubectlVersion}`, error);
return false;
});
}
}
public async downloadKubectl() {