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; return false;
} }
await ensureDir(this.dirname, 0o755); 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}`); logger.debug(`Acquired a lock for ${this.kubectlVersion}`);
const bundled = await this.checkBundled(); const bundled = await this.checkBundled();
let isValid = await this.checkBinary(this.path, !bundled); let isValid = await this.checkBinary(this.path, !bundled);
if (!isValid && !bundled) { if (!isValid && !bundled) {
await this.downloadKubectl().catch((error) => { try {
logger.error(error); await this.downloadKubectl();
logger.debug(`Releasing lock for ${this.kubectlVersion}`); } catch (error) {
release(); logger.error(`[KUBECTL]: failed to download kubectl`, error);
logger.debug(`[KUBECTL]: Releasing lock for ${this.kubectlVersion}`);
await release();
return false; return false;
}); }
isValid = await this.checkBinary(this.path, false); isValid = await this.checkBinary(this.path, false);
} }
if (!isValid) { if (!isValid) {
logger.debug(`Releasing lock for ${this.kubectlVersion}`); logger.debug(`[KUBECTL]: Releasing lock for ${this.kubectlVersion}`);
release(); await release();
return false; return false;
} }
logger.debug(`Releasing lock for ${this.kubectlVersion}`);
release(); logger.debug(`[KUBECTL]: Releasing lock for ${this.kubectlVersion}`);
await release();
return true; return true;
}).catch((e) => { } catch (error) {
logger.error(`Failed to get a lock for ${this.kubectlVersion}`); logger.error(`[KUBECTL]: Failed to get a lock for ${this.kubectlVersion}`, error);
logger.error(e);
return false; return false;
}); }
} }
public async downloadKubectl() { public async downloadKubectl() {