Skip to content

Commit 5666a0f

Browse files
authored
Fb/init config errorhandling (#12)
* better init config error handling * tests for init config problem cases * fix lint problems
1 parent 6ee1692 commit 5666a0f

File tree

3 files changed

+328
-297
lines changed

3 files changed

+328
-297
lines changed

src/featureToggles.js

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -575,23 +575,35 @@ class FeatureToggles {
575575
try {
576576
config = configInput ? configInput : await readConfigFromFile(configFilepath);
577577
} catch (err) {
578-
logger.error(
579-
new VError(
580-
{
581-
name: VERROR_CLUSTER_NAME,
582-
cause: err,
583-
info: {
584-
configFilepath,
585-
...(configInput && { configBaseInput: JSON.stringify(configInput) }),
586-
...(config && { configBase: JSON.stringify(config) }),
587-
},
578+
throw new VError(
579+
{
580+
name: VERROR_CLUSTER_NAME,
581+
cause: err,
582+
info: {
583+
configFilepath,
584+
...(configInput && { configBaseInput: JSON.stringify(configInput) }),
585+
...(config && { configBase: JSON.stringify(config) }),
588586
},
589-
"initialization aborted, could not resolve configuration"
590-
)
587+
},
588+
"initialization aborted, could not resolve configuration"
591589
);
592590
}
593591

594-
const toggleCount = this._processConfig(config);
592+
let toggleCount;
593+
try {
594+
toggleCount = this._processConfig(config);
595+
} catch (err) {
596+
throw new VError(
597+
{
598+
name: VERROR_CLUSTER_NAME,
599+
cause: err,
600+
info: {
601+
...(config && { config: JSON.stringify(config) }),
602+
},
603+
},
604+
"initialization aborted, could not process configuration"
605+
);
606+
}
595607

596608
const validationErrors = await this._validateFallbackValues(this.__fallbackValues);
597609
if (Array.isArray(validationErrors) && validationErrors.length > 0) {

test/integration-local/__snapshots__/featureToggles.test.js.snap

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`local integration test getFeatureValue, changeFeatureValue with scopes 1`] = `
3+
exports[`local integration test after init getFeatureValue, changeFeatureValue with scopes 1`] = `
44
[
55
{
66
"errorMessage": "value "{0}" does not match validation regular expression {1}",
@@ -14,7 +14,7 @@ exports[`local integration test getFeatureValue, changeFeatureValue with scopes
1414
]
1515
`;
1616

17-
exports[`local integration test getFeatureValue, changeFeatureValue with scopes 8`] = `
17+
exports[`local integration test after init getFeatureValue, changeFeatureValue with scopes 8`] = `
1818
[
1919
[
2020
"%s | %O",
@@ -26,7 +26,7 @@ exports[`local integration test getFeatureValue, changeFeatureValue with scopes
2626
]
2727
`;
2828

29-
exports[`local integration test getFeatureValue, changeFeatureValue with scopes and clearSubScopes, resetFeatureValue 5`] = `
29+
exports[`local integration test after init getFeatureValue, changeFeatureValue with scopes and clearSubScopes, resetFeatureValue 5`] = `
3030
[
3131
[
3232
"%s | %O",
@@ -38,7 +38,7 @@ exports[`local integration test getFeatureValue, changeFeatureValue with scopes
3838
]
3939
`;
4040

41-
exports[`local integration test getFeatureValue, changeFeatureValue without scopes 1`] = `
41+
exports[`local integration test after init getFeatureValue, changeFeatureValue without scopes 1`] = `
4242
[
4343
{
4444
"errorMessage": "value "{0}" does not match validation regular expression {1}",
@@ -52,7 +52,7 @@ exports[`local integration test getFeatureValue, changeFeatureValue without scop
5252
]
5353
`;
5454

55-
exports[`local integration test getFeatureValue, changeFeatureValue without scopes 4`] = `
55+
exports[`local integration test after init getFeatureValue, changeFeatureValue without scopes 4`] = `
5656
[
5757
[
5858
"%s | %O",
@@ -64,7 +64,7 @@ exports[`local integration test getFeatureValue, changeFeatureValue without scop
6464
]
6565
`;
6666

67-
exports[`local integration test getFeatureValues, getFeaturesInfos 1`] = `
67+
exports[`local integration test after init getFeatureValues, getFeaturesInfos 1`] = `
6868
{
6969
"test/feature_a": {
7070
"config": {

0 commit comments

Comments
 (0)