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

Commit 60cc4f0

Browse files
committed
fix(config): throw error if value contain not valid json string
1 parent 6039fd1 commit 60cc4f0

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

lib/config/util.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,11 @@ function parseBoolean(value) {
4949
}
5050

5151
function parsePrimitive(str) {
52-
let value;
53-
5452
try {
55-
value = JSON.parse(str);
53+
return JSON.parse(str);
5654
} catch (error) {
57-
// do nothing
55+
throw new GeminiError('a value must be a primitive type');
5856
}
59-
60-
return value;
6157
}
6258

6359
function positiveIntegerOption(defaultValue) {

test/unit/config-options/config-options.test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,11 @@ describe('config', function() {
236236
});
237237
});
238238

239-
it('should not throws if value from environment is not valid', () => {
239+
it('should throw if value from environment is not valid', () => {
240240
['{a:1}', '{', ']', '\'string\'', '\n'].forEach((value) => {
241-
assert.doesNotThrow(() => {
241+
assert.throw(() => {
242242
assertParsesEnv({property: name, value});
243-
});
243+
}, GeminiError);
244244
});
245245
});
246246

@@ -251,11 +251,11 @@ describe('config', function() {
251251
});
252252
});
253253

254-
it('should not throws if value from cli is not valid', () => {
254+
it('should throw if value from cli is not valid', () => {
255255
['{a:1}', '{', ']', '\'string\'', '\n'].forEach((value) => {
256-
assert.doesNotThrow(() => {
256+
assert.throw(() => {
257257
assertParsesCli({property: name, value});
258-
});
258+
}, GeminiError);
259259
});
260260
});
261261
}
@@ -475,7 +475,7 @@ describe('config', function() {
475475
});
476476
});
477477

478-
describe.only('plugins', () => {
478+
describe('plugins', () => {
479479
testObjectOption('system.plugins.plugin');
480480
});
481481
});

0 commit comments

Comments
 (0)