@@ -49,6 +49,11 @@ const CONFIG_SOURCE = Object.freeze({
4949 AUTO : "AUTO" ,
5050} ) ;
5151
52+ const CONFIG_MERGE_CONFLICT = Object . freeze ( {
53+ THROW : "THROW" ,
54+ KEEP_EXISTING : "KEEP_EXISTING" ,
55+ } ) ;
56+
5257const CONFIG_KEY = Object . freeze ( {
5358 TYPE : "TYPE" ,
5459 ACTIVE : "ACTIVE" ,
@@ -219,7 +224,7 @@ class FeatureToggles {
219224 }
220225 }
221226
222- _processConfigSource ( source , configFromSource , configFilepath ) {
227+ _processConfigSource ( source , mergeConflictBehavior , configFromSource , configFilepath ) {
223228 let count = 0 ;
224229 if ( ! isObject ( configFromSource ) ) {
225230 return count ;
@@ -229,17 +234,25 @@ class FeatureToggles {
229234 const entries = Object . entries ( configFromSource ) ;
230235 for ( const [ featureKey , value ] of entries ) {
231236 if ( this . __config [ featureKey ] ) {
232- throw new VError (
233- {
234- name : VERROR_CLUSTER_NAME ,
235- info : {
236- featureKey,
237- source,
238- ...( configFilepath && { configFilepath } ) ,
239- } ,
240- } ,
241- "feature is configured twice"
242- ) ;
237+ switch ( mergeConflictBehavior ) {
238+ case CONFIG_MERGE_CONFLICT . KEEP_EXISTING : {
239+ continue ;
240+ }
241+ case CONFIG_MERGE_CONFLICT . THROW : // eslint-disable-current-line no-fallthrough
242+ default : {
243+ throw new VError (
244+ {
245+ name : VERROR_CLUSTER_NAME ,
246+ info : {
247+ featureKey,
248+ source,
249+ ...( configFilepath && { configFilepath } ) ,
250+ } ,
251+ } ,
252+ "feature is configured twice"
253+ ) ;
254+ }
255+ }
243256 }
244257 count ++ ;
245258
@@ -293,13 +306,22 @@ class FeatureToggles {
293306 * Populate this.__config.
294307 */
295308 _processConfig ( { configRuntime, configFromFilesEntries, configAuto } = { } ) {
296- const configRuntimeCount = this . _processConfigSource ( CONFIG_SOURCE . RUNTIME , configRuntime ) ;
309+ const configRuntimeCount = this . _processConfigSource (
310+ CONFIG_SOURCE . RUNTIME ,
311+ CONFIG_MERGE_CONFLICT . THROW ,
312+ configRuntime
313+ ) ;
297314 const configFromFileCount = configFromFilesEntries . reduce (
298315 ( count , [ configFilepath , configFromFile ] ) =>
299- count + this . _processConfigSource ( CONFIG_SOURCE . FILE , configFromFile , configFilepath ) ,
316+ count +
317+ this . _processConfigSource ( CONFIG_SOURCE . FILE , CONFIG_MERGE_CONFLICT . THROW , configFromFile , configFilepath ) ,
300318 0
301319 ) ;
302- const configAutoCount = this . _processConfigSource ( CONFIG_SOURCE . AUTO , configAuto ) ;
320+ const configAutoCount = this . _processConfigSource (
321+ CONFIG_SOURCE . AUTO ,
322+ CONFIG_MERGE_CONFLICT . KEEP_EXISTING ,
323+ configAuto
324+ ) ;
303325
304326 this . __isConfigProcessed = true ;
305327 return {
0 commit comments