Skip to content

Commit

Permalink
remove more redundant error checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Escalante committed Mar 23, 2016
1 parent 384bfca commit 0460a77
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
12 changes: 2 additions & 10 deletions lib/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ class Template {
questionnaire: Joi.func()
})

Joi.assert(target, Joi.string().required().label('target'))

return node.call(Joi.validate, opts, schema).with(this)
.then((res) => { opts = res })
.then(this.update.bind(this))
Expand Down Expand Up @@ -246,16 +248,6 @@ function validateTemplate () {
}

function validateTarget (target) {
// TODO: remove this, checked already in `save`.
if (!fs.existsSync(this.rootPath)) {
throw new Error(`root path doesn't exist in ${this.name}`)
}

// If target not passed, throw an error.
// TODO: remove this, validate with joi
if (!target) { throw new Error('target path required') }

// If target directory exists, throw an error.
if (fs.existsSync(target)) { throw new Error(`${target} already exists`) }
}

Expand Down
4 changes: 2 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ describe('template',
}
).catch(
function (error) {
error.toString().should.eq("Error: root path doesn't exist in " + name)
error.toString().should.match(/ENOENT: no such file or directory/)
fs.mkdirSync(template.rootPath)
fs.writeFileSync(path.join(template.rootPath, '.keep'), '')
return template.remove().then(
Expand All @@ -705,7 +705,7 @@ describe('template',
}
).catch(
function (error) {
error.toString().should.eq('Error: target path required')
error.toString().should.match(/"target" must be a string/)
return template.remove().then(
function () {
done()
Expand Down

0 comments on commit 0460a77

Please sign in to comment.