diff --git a/lib/commands/deploy/index.js b/lib/commands/deploy/index.js index a97e44ad..cf556c67 100644 --- a/lib/commands/deploy/index.js +++ b/lib/commands/deploy/index.js @@ -9,6 +9,7 @@ const optionModel = require('@src/commands/option-model'); const profileHelper = require('@src/utils/profile-helper'); const stringUtils = require('@src/utils/string-utils'); const CONSTANTS = require('@src/utils/constants'); +const CliFileNotFoundError = require('@src/exceptions/cli-file-not-found-error'); const helper = require('./helper'); class DeployCommand extends AbstractCommand { @@ -43,6 +44,10 @@ class DeployCommand extends AbstractCommand { new Manifest(manifestPath); } catch (err) { Messenger.getInstance().error(err); + + if (err instanceof CliFileNotFoundError) { + Messenger.getInstance().warn('Please make sure you are in the root directory of the project.'); + } return cb(err); } diff --git a/lib/exceptions/cli-error.js b/lib/exceptions/cli-error.js new file mode 100644 index 00000000..9179e77f --- /dev/null +++ b/lib/exceptions/cli-error.js @@ -0,0 +1,6 @@ +module.exports = class CliError extends Error { + constructor(message) { + super(message); + this.name = 'CliError'; + } +}; diff --git a/lib/exceptions/cli-file-not-found-error.js b/lib/exceptions/cli-file-not-found-error.js new file mode 100644 index 00000000..30d34eef --- /dev/null +++ b/lib/exceptions/cli-file-not-found-error.js @@ -0,0 +1,8 @@ +const CliError = require('./cli-error'); + +module.exports = class CliFileNotFoundError extends CliError { + constructor(message) { + super(message); + this.name = 'CliFileNotFoundError'; + } +}; diff --git a/lib/model/abstract-config-file.js b/lib/model/abstract-config-file.js index aaebd4df..af000a6a 100644 --- a/lib/model/abstract-config-file.js +++ b/lib/model/abstract-config-file.js @@ -3,8 +3,10 @@ const fs = require('fs'); const path = require('path'); const jsonView = require('@src/view/json-view'); +const CliFileNotFoundError = require('@src/exceptions/cli-file-not-found-error'); const yaml = require('./yaml-parser'); + const FILE_TYPE_JSON = 'JSON'; const FILE_TYPE_YAML = 'YAML'; @@ -97,7 +99,7 @@ module.exports = class ConfigFile { _validateFilePath() { // check existence if (!fs.existsSync(this.path)) { - throw new Error(`File ${this.path} not exists.`); + throw new CliFileNotFoundError(`File ${this.path} not exists.`); } // check access permission try { diff --git a/test/unit/commands/deploy/index-test.js b/test/unit/commands/deploy/index-test.js index 361ef4e4..e73b62ed 100644 --- a/test/unit/commands/deploy/index-test.js +++ b/test/unit/commands/deploy/index-test.js @@ -84,7 +84,7 @@ describe('Commands deploy test - command class test', () => { expect(err.message).equal('File invalidPath not exists.'); expect(errorStub.args[0][0].message).equal('File invalidPath not exists.'); expect(infoStub.callCount).equal(0); - expect(warnStub.callCount).equal(0); + expect(warnStub.callCount).equal(1); done(); }); }); @@ -113,7 +113,7 @@ describe('Commands deploy test - command class test', () => { expect(err.message).equal('File invalidPath not exists.'); expect(errorStub.args[0][0].message).equal('File invalidPath not exists.'); expect(infoStub.callCount).equal(0); - expect(warnStub.callCount).equal(0); + expect(warnStub.callCount).equal(1); done(); }); });