Skip to content

Commit

Permalink
throw config error based on the joi validation error (elastic#29137)
Browse files Browse the repository at this point in the history
  • Loading branch information
kobelb committed Jan 23, 2019
1 parent 765adc1 commit 0df5719
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/server/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ export class Config {
});

if (results.error) {
throw results.error;
const error = new Error(results.error.message);
error.name = results.error.name;
error.stack = results.error.stack;
throw error;
}

this[vals] = results.value;
Expand Down
8 changes: 6 additions & 2 deletions src/server/config/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ describe('lib/config/config', function () {
});

it('should thow an exception when setting a value with the wrong type', function (done) {
expect.assertions(2);
expect.assertions(4);

const run = function () {
config.set('test.enable', 'something');
Expand All @@ -184,7 +184,11 @@ describe('lib/config/config', function () {
run();
} catch (err) {
expect(err).toHaveProperty('name', 'ValidationError');
expect(err.details[0].message).toBe('"enable" must be a boolean');
expect(err).toHaveProperty('message',
'child \"test\" fails because [child \"enable\" fails because [\"enable\" must be a boolean]]'
);
expect(err).not.toHaveProperty('details');
expect(err).not.toHaveProperty('_object');
}

done();
Expand Down

0 comments on commit 0df5719

Please sign in to comment.