Skip to content

Commit

Permalink
♻️ Improve error messages for preset system (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
frinyvonnick authored Jan 5, 2020
1 parent b27f6f9 commit a51fee2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/gitmoji-changelog-cli/src/cli.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,26 @@ describe('generate changelog', () => {

expect(output.toString('utf8')).includes(["The preset unknown doesn't exist"])
})

it('should throw an Error if the preset could not find configuration', () => {
fs.unlinkSync(path.join(testDir, 'package.json'))

const output = gitmojiChangelog()

expect(output.toString('utf8')).includes(['Cannot retrieve configuration'])
})

it('should throw an Error if the preset did not return a version', () => {
const pkg = path.join(testDir, 'package.json')
// eslint-disable-next-line global-require
const content = JSON.parse(fs.readFileSync(pkg).toString('utf8'))
delete content.version
fs.writeFileSync(pkg, JSON.stringify(content))

const output = gitmojiChangelog()

expect(output.toString('utf8')).includes(['Cannot retrieve the version from your configuration'])
})
})

describe('init', () => {
Expand Down
8 changes: 8 additions & 0 deletions packages/gitmoji-changelog-cli/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ async function main(options = {}) {
// eslint-disable-next-line global-require
const loadProjectInfo = require(`./presets/${options.preset}.js`)
projectInfo = await loadProjectInfo()

if (!projectInfo) {
throw Error(`Cannot retrieve configuration for preset ${options.preset}.`)
}

if (!projectInfo.version) {
throw Error('Cannot retrieve the version from your configuration. Check it or you can do "gitmoji-changelog <wanted version>".')
}
} catch (e) {
logger.error(e)
// Force quit if the requested preset doesn't exist
Expand Down

0 comments on commit a51fee2

Please sign in to comment.