Skip to content

Commit

Permalink
chore: improve error message when config file is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
kakha urigashvili authored and RonWang committed Dec 8, 2020
1 parent 9f5c912 commit ef32432
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/model/abstract-config-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ module.exports = class ConfigFile {
this.path = filePath;
this.content = null;
this.fileType = null;
this.fileNotFoundHintMessage = '';
}

/**
Expand Down Expand Up @@ -104,7 +105,7 @@ module.exports = class ConfigFile {
_validateFilePath() {
// check existence
if (!fs.existsSync(this.path)) {
throw new CliFileNotFoundError(`File ${this.path} not exists.`);
throw new CliFileNotFoundError(`File ${this.path} not exists.${this.fileNotFoundHintMessage}`);
}
// check access permission
try {
Expand Down
4 changes: 4 additions & 0 deletions lib/model/resources-config/ask-resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const BASE = {
profiles: {}
};

const FILE_NOT_FOUND_HINT_MESSAGE = ' If this is a skill project managed by v1 ask-cli, '
+ 'please run \'ask util upgrade-project\' then try the command again.';

module.exports = class AskResources extends ConfigFile {
/**
* Constructor for AskResources class
Expand All @@ -20,6 +23,7 @@ module.exports = class AskResources extends ConfigFile {
}
// init by calling super() if instance not exists
super(filePath);
this.fileNotFoundHintMessage = FILE_NOT_FOUND_HINT_MESSAGE;
this.read();
instance = this;
}
Expand Down
3 changes: 2 additions & 1 deletion test/unit/commands/deploy/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ describe('Commands deploy test - command class test', () => {
// call
instance.handle(TEST_CMD, (err) => {
// verify
expect(err.message).equal('File invalidPath not exists.');
expect(err.message).includes('File invalidPath not exists.');
expect(err.message).includes('please run \'ask util upgrade-project\'');
expect(errorStub.callCount).equal(0);
expect(infoStub.callCount).equal(0);
expect(warnStub.callCount).equal(1);
Expand Down
3 changes: 2 additions & 1 deletion test/unit/commands/new/helper-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ describe('Commands new test - helper test', () => {
helper.loadSkillProjectModel(TEST_SKILL_FOLDER_NAME, TEST_PROFILE);
} catch (e) {
// verify
expect(e.message).equal(`File ${FIXTURE_RESOURCES_CONFIG_FILE_PATH} not exists.`);
expect(e.message).includes(`File ${FIXTURE_RESOURCES_CONFIG_FILE_PATH} not exists.`);
expect(e.message).includes('please run \'ask util upgrade-project\'');
}
});

Expand Down

0 comments on commit ef32432

Please sign in to comment.