Skip to content
This repository has been archived by the owner on Jul 17, 2023. It is now read-only.

Commit

Permalink
feat(atlas): expose additional context when ValidationError is thrown
Browse files Browse the repository at this point in the history
Improves #66 but further work will be necessary.
  • Loading branch information
robertrossmann committed Feb 20, 2019
1 parent 1f5457a commit 56debf1
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/atlas/src/private/component-container.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ class ComponentContainer {
const config = defaults(info.config, this.Component.defaults)

if (!info.validator.validate(info.Component.config, config)) {
throw new ValidationError(info.validator.errors)
throw new ValidationError(info.validator.errors, {
alias: this.alias,
schema: info.Component.config,
config,
})
}

atlas.log.trace({
Expand Down
13 changes: 13 additions & 0 deletions packages/atlas/test/action.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,19 @@ describe('Atlas::action()', () => {
}

expect(() => atlas.action('dummy', action)).to.throw(ValidationError)

try {
atlas.action('dummy', action)
} catch (err) {
expect(err.context).to.have.all.keys([
'schema',
'config',
'alias',
])
expect(err.context.schema).to.equal(action.config)
expect(err.context.config).to.equal(options.config.actions.dummy)
expect(err.context.alias).to.equal('dummy')
}
})

it('works when user config passes component config schema', () => {
Expand Down
13 changes: 13 additions & 0 deletions packages/atlas/test/hook.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,19 @@ describe('Atlas::hook()', () => {
}

expect(() => atlas.hook('dummy', hook)).to.throw(ValidationError)

try {
atlas.hook('dummy', hook)
} catch (err) {
expect(err.context).to.have.all.keys([
'schema',
'config',
'alias',
])
expect(err.context.schema).to.equal(hook.config)
expect(err.context.config).to.equal(options.config.hooks.dummy)
expect(err.context.alias).to.equal('dummy')
}
})

it('works when user config passes component config schema', () => {
Expand Down
13 changes: 13 additions & 0 deletions packages/atlas/test/service.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,19 @@ describe('Atlas::service()', () => {
}

expect(() => atlas.service('dummy', service)).to.throw(ValidationError)

try {
atlas.service('dummy', service)
} catch (err) {
expect(err.context).to.have.all.keys([
'schema',
'config',
'alias',
])
expect(err.context.schema).to.equal(service.config)
expect(err.context.config).to.equal(options.config.services.dummy)
expect(err.context.alias).to.equal('dummy')
}
})

it('works when user config passes component config schema', () => {
Expand Down

0 comments on commit 56debf1

Please sign in to comment.