Skip to content

Commit

Permalink
Improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
cookpete committed Sep 9, 2016
1 parent bfdfc0a commit 96b7666
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ commander
.version(version)
.parse(process.argv)

const Template = templates[commander.template]

if (!Template) {
throw new Error(`Template '${commander.template}' was not found`)
}

function getCommits () {
return cmd(`git log --shortstat --pretty=format:${LOG_FORMAT}`).then(parseCommits)
}
Expand All @@ -53,6 +47,11 @@ function getPackageVersion () {
}

function generateLog ([ commits, origin, packageVersion ]) {
const Template = templates[commander.template]
if (!Template) {
throw new Error(`Template '${commander.template}' was not found`)
}

const releases = parseReleases(commits, packageVersion)
const log = new Template(origin).render(releases)

Expand All @@ -71,9 +70,9 @@ function success (log) {
}

function error (error) {
throw new Error(error)
console.error(error.message)
}

const promises = [ getCommits(), parseOrigin(), getPackageVersion() ]

Promise.all(promises).then(generateLog).then(success, error)
Promise.all(promises).then(generateLog).then(success).catch(error)

0 comments on commit 96b7666

Please sign in to comment.