Skip to content

Commit

Permalink
feat: add message to check that user in root directory of the project…
Browse files Browse the repository at this point in the history
… when config file not found
  • Loading branch information
kakha urigashvili committed Feb 5, 2020
1 parent 00d94b4 commit b92d864
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
5 changes: 5 additions & 0 deletions lib/commands/deploy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}

Expand Down
6 changes: 6 additions & 0 deletions lib/exceptions/cli-error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = class CliError extends Error {
constructor(message) {
super(message);
this.name = 'CliError';
}
};
8 changes: 8 additions & 0 deletions lib/exceptions/cli-file-not-found-error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const CliError = require('./cli-error');

module.exports = class CliFileNotFoundError extends CliError {
constructor(message) {
super(message);
this.name = 'CliFileNotFoundError';
}
};
4 changes: 3 additions & 1 deletion lib/model/abstract-config-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/commands/deploy/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
Expand Down Expand Up @@ -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();
});
});
Expand Down

0 comments on commit b92d864

Please sign in to comment.