Skip to content

Commit

Permalink
fix: pre-stop throws error if project not running (#2)
Browse files Browse the repository at this point in the history
* 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 <francoisvdven@gmail.com>
  • Loading branch information
timvango and francoisvdv authored Feb 23, 2022
1 parent 665f0d3 commit c2a214f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
26 changes: 20 additions & 6 deletions src/Mutagen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand All @@ -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);
}
}
}
}
2 changes: 1 addition & 1 deletion src/MutagenConfigManipulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,4 @@ export class MutagenConfigManipulator {
throw new MutagenConfigWriteError(e);
}
}
}
}
6 changes: 5 additions & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
});
};

0 comments on commit c2a214f

Please sign in to comment.