2525logger = logging .getLogger (__name__ )
2626
2727
28+ class LogicError (Exception ):
29+ """Error in application logic."""
30+
31+
2832class AppConfig :
2933 """Singleton class to load and store the configuration."""
3034
@@ -52,65 +56,55 @@ def init_from_dict(self, config_dict: dict[Any, Any]) -> None:
5256 """Initialize configuration from a dictionary."""
5357 self ._configuration = Configuration (** config_dict )
5458
59+ def check_configuration_loaded (self ):
60+ """Check that configuration is loaded, raise exception instead."""
61+ if self ._configuration is None :
62+ raise LogicError ("logic error: configuration is not loaded" )
63+
5564 @property
5665 def configuration (self ) -> Configuration :
5766 """Return the whole configuration."""
58- assert (
59- self ._configuration is not None
60- ), "logic error: configuration is not loaded"
67+ self .check_configuration_loaded ()
6168 return self ._configuration
6269
6370 @property
6471 def service_configuration (self ) -> ServiceConfiguration :
6572 """Return service configuration."""
66- assert (
67- self ._configuration is not None
68- ), "logic error: configuration is not loaded"
73+ self .check_configuration_loaded ()
6974 return self ._configuration .service
7075
7176 @property
7277 def llama_stack_configuration (self ) -> LlamaStackConfiguration :
7378 """Return Llama stack configuration."""
74- assert (
75- self ._configuration is not None
76- ), "logic error: configuration is not loaded"
79+ self .check_configuration_loaded ()
7780 return self ._configuration .llama_stack
7881
7982 @property
8083 def user_data_collection_configuration (self ) -> UserDataCollection :
8184 """Return user data collection configuration."""
82- assert (
83- self ._configuration is not None
84- ), "logic error: configuration is not loaded"
85+ self .check_configuration_loaded ()
8586 return self ._configuration .user_data_collection
8687
8788 @property
8889 def mcp_servers (self ) -> list [ModelContextProtocolServer ]:
8990 """Return model context protocol servers configuration."""
90- assert (
91- self ._configuration is not None
92- ), "logic error: configuration is not loaded"
91+ self .check_configuration_loaded ()
9392 return self ._configuration .mcp_servers
9493
9594 @property
9695 def authentication_configuration (self ) -> AuthenticationConfiguration :
9796 """Return authentication configuration."""
98- assert (
99- self ._configuration is not None
100- ), "logic error: configuration is not loaded"
97+ self .check_configuration_loaded ()
10198
102- assert (
103- self ._configuration .authentication is not None
104- ), "logic error: authentication configuration is not loaded"
99+ if self ._configuration .authentication is None :
100+ raise LogicError ("logic error: authentication configuration is not loaded" )
105101
106102 return self ._configuration .authentication
107103
108104 @property
109105 def authorization_configuration (self ) -> AuthorizationConfiguration :
110106 """Return authorization configuration or default no-op configuration."""
111- assert (
112- self ._configuration is not None
113- ), "logic error: configuration is not loaded"
107+ self .check_configuration_loaded ()
114108
115109 if self ._configuration .authorization is None :
116110 return AuthorizationConfiguration ()
@@ -120,25 +114,19 @@ def authorization_configuration(self) -> AuthorizationConfiguration:
120114 @property
121115 def customization (self ) -> Optional [Customization ]:
122116 """Return customization configuration."""
123- assert (
124- self ._configuration is not None
125- ), "logic error: configuration is not loaded"
117+ self .check_configuration_loaded ()
126118 return self ._configuration .customization
127119
128120 @property
129121 def inference (self ) -> InferenceConfiguration :
130122 """Return inference configuration."""
131- assert (
132- self ._configuration is not None
133- ), "logic error: configuration is not loaded"
123+ self .check_configuration_loaded ()
134124 return self ._configuration .inference
135125
136126 @property
137127 def database_configuration (self ) -> DatabaseConfiguration :
138128 """Return database configuration."""
139- assert (
140- self ._configuration is not None
141- ), "logic error: configuration is not loaded"
129+ self .check_configuration_loaded ()
142130 return self ._configuration .database
143131
144132
0 commit comments