Skip to content

Commit 1f8df89

Browse files
committed
fix: ensure EnsembleConfigService is initialized before accessing config
1 parent b026253 commit 1f8df89

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

modules/ensemble/lib/ensemble.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ class Ensemble extends WithEnsemble with EnsembleRouteObserver {
106106
try {
107107
// this code block is guaranteed to run at most once
108108
await StorageManager().init();
109+
await SecretsStore().initialize();
109110
Device().initDeviceInfo();
110111
AppInfo().initPackageInfo(_config);
111112
_completer!.complete();
@@ -139,9 +140,10 @@ class Ensemble extends WithEnsemble with EnsembleRouteObserver {
139140
if (_config != null) {
140141
return Future<EnsembleConfig>.value(_config);
141142
}
142-
// Intialize the config service to get `ensemble-config.yaml` file to access the configuration using static property as `EnsembleConfigService.config`
143-
await EnsembleConfigService.initialize();
144-
await SecretsStore().initialize();
143+
// Initialize the config service to get `ensemble-config.yaml` file to access the configuration using static property as `EnsembleConfigService.config`
144+
if (!EnsembleConfigService.isInitialized) {
145+
await EnsembleConfigService.initialize();
146+
}
145147

146148
// get the config YAML
147149
final YamlMap yamlMap = EnsembleConfigService.config;

modules/ensemble/lib/framework/ensemble_config_service.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,26 @@ import 'package:yaml/yaml.dart';
44
// EnsembleConfigService is a service that provides access to the ensemble-config.yaml file through static property once initialized
55
class EnsembleConfigService {
66
static YamlMap? _config;
7+
static bool _isInitialized = false;
78

89
static Future<void> initialize() async {
910
final yamlString = await rootBundle.loadString('ensemble/ensemble-config.yaml');
1011
_config = loadYaml(yamlString);
12+
_isInitialized = true;
1113
}
1214

1315
static YamlMap get config {
1416
if (_config == null) {
15-
throw StateError('EnsembleConfig not initialized');
17+
// if config is not available, load the default config
18+
_config = loadYaml('''
19+
definitions:
20+
from: 'ensemble'
21+
''');
22+
_isInitialized =
23+
true;
1624
}
1725
return _config!;
1826
}
27+
28+
static bool get isInitialized => _isInitialized;
1929
}

modules/ensemble/lib/framework/secrets.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ class SecretsStore with Invokable {
2828

2929
// add local overrides
3030
try {
31+
if (!EnsembleConfigService.isInitialized) {
32+
await EnsembleConfigService.initialize();
33+
}
3134
String provider = EnsembleConfigService.config["definitions"]?['from'];
3235
if (provider == 'local') {
3336
String path =

0 commit comments

Comments
 (0)