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

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2021-11-03 09:47:59 -04:00
parent b95be78ded
commit 1b1f74520d

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() {