Skip to content

Commit

Permalink
fix(systemd): improve systemd precheck error messages (#628)
Browse files Browse the repository at this point in the history
  • Loading branch information
aileen authored and acburdine committed Feb 6, 2018
1 parent a195fc1 commit 208bb15
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
11 changes: 9 additions & 2 deletions extensions/systemd/systemd.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const fs = require('fs');
const execa = require('execa');
const cli = require('../../lib');
const getUid = require('./get-uid');
const chalk = require('chalk');

class SystemdProcessManager extends cli.ProcessManager {
get systemdName() {
Expand Down Expand Up @@ -101,14 +102,20 @@ class SystemdProcessManager extends cli.ProcessManager {
const uid = getUid(this.instance.dir);

if (!uid) {
throw new cli.errors.SystemError('Systemd process manager has not been set up. Run `ghost setup linux-user systemd` and try again.')
throw new cli.errors.SystemError({
message: 'Systemd process manager has not been set up or is corrupted.',
help: `Run ${chalk.green('ghost setup linux-user systemd')} and try again.`
});
}

if (fs.existsSync(`/lib/systemd/system/${this.systemdName}.service`)) {
return;
}

throw new cli.errors.SystemError('Systemd process manager has not been set up. Run `ghost setup systemd` and try again.');
throw new cli.errors.SystemError({
message: 'Systemd process manager has not been set up or is corrupted.',
help: `Run ${chalk.green('ghost setup systemd')} and try again.`
});
}

static willRun() {
Expand Down
6 changes: 4 additions & 2 deletions extensions/systemd/test/systemd-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,8 @@ describe('Unit: Systemd > Process Manager', function () {
expect(proxyOpts['./get-uid'].calledOnce).to.be.true;
expect(error).to.be.ok;
expect(error).to.be.instanceOf(errors.SystemError);
expect(error.message).to.match(/ghost setup linux-user systemd/);
expect(error.message).to.match(/Systemd process manager has not been set up or is corrupted./);
expect(error.options.help).to.match(/ghost setup linux-user systemd/);
}
});

Expand All @@ -337,7 +338,8 @@ describe('Unit: Systemd > Process Manager', function () {
expect(fsStub.calledOnce).to.be.true;
expect(error).to.be.ok;
expect(error).to.be.instanceOf(errors.SystemError);
expect(error.message).to.match(/ghost setup systemd/);
expect(error.message).to.match(/Systemd process manager has not been set up or is corrupted./);
expect(error.options.help).to.match(/ghost setup systemd/);
}
});
});
Expand Down

0 comments on commit 208bb15

Please sign in to comment.