From 0460a777b730af7cb058e92216f0058306ac768c Mon Sep 17 00:00:00 2001 From: Jeff Escalante Date: Wed, 23 Mar 2016 16:48:46 -0400 Subject: [PATCH] remove more redundant error checks --- lib/template.js | 12 ++---------- test/test.js | 4 ++-- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/lib/template.js b/lib/template.js index 552abef..f1e1f63 100644 --- a/lib/template.js +++ b/lib/template.js @@ -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)) @@ -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`) } } diff --git a/test/test.js b/test/test.js index 776d9ff..a88c837 100644 --- a/test/test.js +++ b/test/test.js @@ -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( @@ -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()