Skip to content

Commit

Permalink
more clear joi error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Escalante committed May 16, 2016
1 parent c008c54 commit 5ab7a1f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
28 changes: 24 additions & 4 deletions lib/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ class Template {
generatorsFolderName: Joi.string().default('generators')
})

let options = Joi.validate(_options, schema)
let options = Joi.validate(_options, schema, {
language: {
messages: { wrapArrays: false },
object: { child: '!![sprout constructor] option {{reason}}' }
}
})
if (options.error) { throw options.error }
options = options.value

Expand Down Expand Up @@ -88,7 +93,12 @@ class Template {

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

return node.call(Joi.validate, opts, schema).with(this)
return node.call(Joi.validate, opts, schema, {
language: {
messages: { wrapArrays: false },
object: { child: '!![sprout init] option {{reason}}' }
}
}).with(this)
.then((res) => { opts = res })
.then(this.update.bind(this))
.then(validateTemplate)
Expand Down Expand Up @@ -151,7 +161,12 @@ class Template {
generatorArgs: Joi.array().single().default([])
})

return node.call(Joi.validate, args, schema)
return node.call(Joi.validate, args, schema, {
language: {
messages: { wrapArrays: false },
object: { child: '!![sprout generator] option {{reason}}' }
}
})
.then((res) => { args = res })
.then(() => {
if (!fs.existsSync(target)) {
Expand Down Expand Up @@ -287,7 +302,12 @@ function loadConfigFile () {
defaults: Joi.object()
})

const result = Joi.validate(require(initPath), schema)
const result = Joi.validate(require(initPath), schema, {
language: {
messages: { wrapArrays: false },
object: { child: '!![sprout init.js] option {{reason}}' }
}
})
if (result.error) { throw result.error }

this.init = result.value
Expand Down
4 changes: 2 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1513,7 +1513,7 @@ describe('template',
}
).catch(
function (error) {
error.toString().should.eq('ValidationError: child "target" fails because ["target" must be a string]')
error.toString().should.eq('ValidationError: [sprout generator] option "target" must be a string')
return template.remove(name).then(
function () {
return rimraf(target, done)
Expand Down Expand Up @@ -1578,7 +1578,7 @@ describe('template',
}
).catch(
function (error) {
error.toString().should.eq('ValidationError: child "generator" fails because ["generator" must be a string]')
error.toString().should.eq('ValidationError: [sprout generator] option "generator" must be a string')
return template.remove(name).then(
function () {
return rimraf(target, done)
Expand Down

0 comments on commit 5ab7a1f

Please sign in to comment.