bugsnag-build-reporter
Version:
A tool for reporting your application’s builds to Bugsnag
13 lines (11 loc) • 477 B
JavaScript
const inspect = require('util').inspect
module.exports = schema => (opts, cb) => {
const errors = Object.keys(schema).reduce((accum, key) => {
if (schema[key].validate(opts[key])) return accum
return accum.concat({ key, message: schema[key].message, value: inspect(opts[key]) })
}, [])
if (!errors.length) return cb(null, opts)
const err = new Error('Configuration error')
err.errors = errors.map(e => `${e.key} ${e.message} (got "${e.value}")`)
cb(err)
}