@@ -395,7 +395,10 @@ def __post_init_post_parse__(self):
395395 _logger .info ('Substituting index templates' )
396396 for index_name , index_config in self .indexes .items ():
397397 if isinstance (index_config , IndexTemplateConfig ):
398- template = self .templates [index_config .template ]
398+ try :
399+ template = self .templates [index_config .template ]
400+ except KeyError as e :
401+ raise ConfigurationError (f'Template `{ index_config .template } ` not found in `templates` config section' ) from e
399402 raw_template = json .dumps (template , default = pydantic_encoder )
400403 for key , value in index_config .values .items ():
401404 value_regex = r'<[ ]*' + key + r'[ ]*>'
@@ -410,17 +413,26 @@ def __post_init_post_parse__(self):
410413 for index_config in self .indexes .values ():
411414 if isinstance (index_config , OperationIndexConfig ):
412415 if isinstance (index_config .datasource , str ):
413- index_config .datasource = self .datasources [index_config .datasource ]
416+ try :
417+ index_config .datasource = self .datasources [index_config .datasource ]
418+ except KeyError as e :
419+ raise ConfigurationError (f'Datasource `{ index_config .datasource } ` not found in `datasources` config section' ) from e
414420
415421 for i , contract in enumerate (index_config .contracts ):
416422 if isinstance (contract , str ):
417- index_config .contracts [i ] = self .contracts [contract ]
423+ try :
424+ index_config .contracts [i ] = self .contracts [contract ]
425+ except KeyError as e :
426+ raise ConfigurationError (f'Contract `{ contract } ` not found in `contracts` config section' ) from e
418427
419428 for handler in index_config .handlers :
420429 callback_patterns [handler .callback ].append (handler .pattern )
421430 for pattern in handler .pattern :
422431 if isinstance (pattern .destination , str ):
423- pattern .destination = self .contracts [pattern .destination ]
432+ try :
433+ pattern .destination = self .contracts [pattern .destination ]
434+ except KeyError as e :
435+ raise ConfigurationError (f'Contract `{ pattern .destination } ` not found in `contracts` config section' ) from e
424436
425437 elif isinstance (index_config , BigMapIndexConfig ):
426438 if isinstance (index_config .datasource , str ):
@@ -430,7 +442,10 @@ def __post_init_post_parse__(self):
430442 callback_patterns [handler .callback ].append (handler .pattern )
431443 for pattern in handler .pattern :
432444 if isinstance (pattern .contract , str ):
433- pattern .contract = self .contracts [pattern .contract ]
445+ try :
446+ pattern .contract = self .contracts [pattern .contract ]
447+ except KeyError as e :
448+ raise ConfigurationError (f'Contract `{ pattern .contract } ` not found in `contracts` config section' ) from e
434449
435450 else :
436451 raise NotImplementedError (f'Index kind `{ index_config .kind } ` is not supported' )
@@ -474,6 +489,8 @@ def load(
474489 for match in re .finditer (ENV_VARIABLE_REGEX , raw_config ):
475490 variable , default_value = match .group (1 ), match .group (2 )
476491 value = env .get (variable )
492+ if not default_value and not value :
493+ raise ConfigurationError (f'Environment variable `{ variable } ` is not set' )
477494 placeholder = '${' + variable + ':-' + default_value + '}'
478495 raw_config = raw_config .replace (placeholder , value or default_value )
479496
0 commit comments