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:
parent
368e2d9a00
commit
28e182a2a3
@ -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() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user