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
@@ -55,62 +59,54 @@ def init_from_dict(self, config_dict: dict[Any, Any]) -> None:
5559 @property
5660 def configuration (self ) -> Configuration :
5761 """Return the whole configuration."""
58- assert (
59- self ._configuration is not None
60- ), "logic error: configuration is not loaded"
62+ if self ._configuration is None :
63+ raise LogicError ("logic error: configuration is not loaded" )
6164 return self ._configuration
6265
6366 @property
6467 def service_configuration (self ) -> ServiceConfiguration :
6568 """Return service configuration."""
66- assert (
67- self ._configuration is not None
68- ), "logic error: configuration is not loaded"
69+ if self ._configuration is None :
70+ raise LogicError ("logic error: configuration is not loaded" )
6971 return self ._configuration .service
7072
7173 @property
7274 def llama_stack_configuration (self ) -> LlamaStackConfiguration :
7375 """Return Llama stack configuration."""
74- assert (
75- self ._configuration is not None
76- ), "logic error: configuration is not loaded"
76+ if self ._configuration is None :
77+ raise LogicError ("logic error: configuration is not loaded" )
7778 return self ._configuration .llama_stack
7879
7980 @property
8081 def user_data_collection_configuration (self ) -> UserDataCollection :
8182 """Return user data collection configuration."""
82- assert (
83- self ._configuration is not None
84- ), "logic error: configuration is not loaded"
83+ if self ._configuration is None :
84+ raise LogicError ("logic error: configuration is not loaded" )
8585 return self ._configuration .user_data_collection
8686
8787 @property
8888 def mcp_servers (self ) -> list [ModelContextProtocolServer ]:
8989 """Return model context protocol servers configuration."""
90- assert (
91- self ._configuration is not None
92- ), "logic error: configuration is not loaded"
90+ if self ._configuration is None :
91+ raise LogicError ("logic error: configuration is not 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+ if self ._configuration is None :
98+ raise LogicError ("logic error: configuration is not loaded" )
10199
102- assert (
103- self ._configuration .authentication is not None
104- ), "logic error: authentication configuration is not loaded"
100+ if self ._configuration .authentication is None :
101+ raise LogicError ("logic error: authentication configuration is not loaded" )
105102
106103 return self ._configuration .authentication
107104
108105 @property
109106 def authorization_configuration (self ) -> AuthorizationConfiguration :
110107 """Return authorization configuration or default no-op configuration."""
111- assert (
112- self ._configuration is not None
113- ), "logic error: configuration is not loaded"
108+ if self ._configuration is None :
109+ raise LogicError ("logic error: configuration is not loaded" )
114110
115111 if self ._configuration .authorization is None :
116112 return AuthorizationConfiguration ()
@@ -120,25 +116,22 @@ def authorization_configuration(self) -> AuthorizationConfiguration:
120116 @property
121117 def customization (self ) -> Optional [Customization ]:
122118 """Return customization configuration."""
123- assert (
124- self ._configuration is not None
125- ), "logic error: configuration is not loaded"
119+ if self ._configuration is None :
120+ raise LogicError ("logic error: configuration is not loaded" )
126121 return self ._configuration .customization
127122
128123 @property
129124 def inference (self ) -> InferenceConfiguration :
130125 """Return inference configuration."""
131- assert (
132- self ._configuration is not None
133- ), "logic error: configuration is not loaded"
126+ if self ._configuration is None :
127+ raise LogicError ("logic error: configuration is not loaded" )
134128 return self ._configuration .inference
135129
136130 @property
137131 def database_configuration (self ) -> DatabaseConfiguration :
138132 """Return database configuration."""
139- assert (
140- self ._configuration is not None
141- ), "logic error: configuration is not loaded"
133+ if self ._configuration is None :
134+ raise LogicError ("logic error: configuration is not loaded" )
142135 return self ._configuration .database
143136
144137
0 commit comments