Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Commit

Permalink
fix(config): throw error if value contain not valid json string
Browse files Browse the repository at this point in the history
  • Loading branch information
seth2810 committed Nov 6, 2016
1 parent 6039fd1 commit 60cc4f0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
8 changes: 2 additions & 6 deletions lib/config/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,11 @@ function parseBoolean(value) {
}

function parsePrimitive(str) {
let value;

try {
value = JSON.parse(str);
return JSON.parse(str);
} catch (error) {
// do nothing
throw new GeminiError('a value must be a primitive type');
}

return value;
}

function positiveIntegerOption(defaultValue) {
Expand Down
14 changes: 7 additions & 7 deletions test/unit/config-options/config-options.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,11 @@ describe('config', function() {
});
});

it('should not throws if value from environment is not valid', () => {
it('should throw if value from environment is not valid', () => {
['{a:1}', '{', ']', '\'string\'', '\n'].forEach((value) => {
assert.doesNotThrow(() => {
assert.throw(() => {
assertParsesEnv({property: name, value});
});
}, GeminiError);
});
});

Expand All @@ -251,11 +251,11 @@ describe('config', function() {
});
});

it('should not throws if value from cli is not valid', () => {
it('should throw if value from cli is not valid', () => {
['{a:1}', '{', ']', '\'string\'', '\n'].forEach((value) => {
assert.doesNotThrow(() => {
assert.throw(() => {
assertParsesCli({property: name, value});
});
}, GeminiError);
});
});
}
Expand Down Expand Up @@ -475,7 +475,7 @@ describe('config', function() {
});
});

describe.only('plugins', () => {
describe('plugins', () => {
testObjectOption('system.plugins.plugin');
});
});
Expand Down

0 comments on commit 60cc4f0

Please sign in to comment.