From c2a214f630d28a55d055b8293fd9a3505b842351 Mon Sep 17 00:00:00 2001 From: Tim van Gompel Date: Thu, 24 Feb 2022 00:14:58 +0100 Subject: [PATCH] fix: pre-stop throws error if project not running (#2) * fix: pre-stop throws error if project not running When the mutagen project was not running, but there was a .lando.mutagen.yml.tmp present, the plugin would throw an error. The .tmp file had to be manually deleted to get the project working again. This fixes the issue by first checking if the project is running with the 'mutagen project list' command. Also, the plugin no longer throws an error if the .tmp file is not found, but it now prints a verbose line. * refactor: move isRunning check to its own method * refactor: add softFail option to removeManipulatedMutagenConfigFile If the removeManipulatedMutagenConfigFile throws an error on pre-stop, the process quits, which prevents Lando from continuing. By setting softFail to true, only a verbose line is printed, which allows the Lando process to continue regardless. * fix: isRunning called as property instead of function * fix: remove type declaration from softFail @typescript-eslint/no-inferrable-types * refactor: make caller of removeManipulatedMutagenConfigFile handle exceptions * chore: Removed unused softfail parameter from removeManipulatedConfigFile function * chore: Removed unused parameter from removeManipulatedMutagenConfigFile call Co-authored-by: Francois van der Ven --- src/Mutagen.ts | 26 ++++++++++++++++++++------ src/MutagenConfigManipulator.ts | 2 +- src/app.ts | 6 +++++- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/Mutagen.ts b/src/Mutagen.ts index b7fcf20..f7fac6b 100644 --- a/src/Mutagen.ts +++ b/src/Mutagen.ts @@ -49,6 +49,17 @@ export class Mutagen { return true; } + isRunning(mutagenConfigFile: string): boolean { + try { + // Check if the mutagen project is running + process.execSync(`mutagen project list -f ${mutagenConfigFile}`); + } + catch (e) { + return false; + } + return true; + } + start(mutagenConfigFile: string) { try { this.logger.verbose(`starting mutagen`); @@ -59,12 +70,15 @@ export class Mutagen { } } stop(mutagenConfigFile: string) { - try { - this.logger.verbose(`stopping mutagen`); - const stdout = process.execSync(`mutagen project terminate -f ${mutagenConfigFile}`); - this.logger.verbose(`stopped mutagen: ${stdout}`); - } catch (e) { - throw new MutagenProcessError(e); + // If the project is running, stop it. + if (this.isRunning(mutagenConfigFile)) { + try { + this.logger.verbose(`stopping mutagen`); + const stdout = process.execSync(`mutagen project terminate -f ${mutagenConfigFile}`); + this.logger.verbose(`stopped mutagen: ${stdout}`); + } catch (e) { + throw new MutagenProcessError(e); + } } } } diff --git a/src/MutagenConfigManipulator.ts b/src/MutagenConfigManipulator.ts index 5dcbec5..fb5e45c 100644 --- a/src/MutagenConfigManipulator.ts +++ b/src/MutagenConfigManipulator.ts @@ -111,4 +111,4 @@ export class MutagenConfigManipulator { throw new MutagenConfigWriteError(e); } } -} \ No newline at end of file +} diff --git a/src/app.ts b/src/app.ts index a119284..96d5279 100644 --- a/src/app.ts +++ b/src/app.ts @@ -65,7 +65,11 @@ export = (app: App) => { logger.info('stopped mutagen'); } catch (e) { - handleError(e, logger); + if (e instanceof MutagenConfigNotFoundError) { + logger.verbose('mutagen config not found: ' + e.message); + } else { + handleError(e, logger); + } } }); };