|
1 | | -use anyhow::Result; |
| 1 | +use anyhow::{Context, Result}; |
2 | 2 | use async_nats::jetstream::{self}; |
3 | 3 | use async_nats::HeaderMap; |
4 | 4 | use clap::Parser; |
@@ -212,33 +212,30 @@ async fn fetch_price_updates(jetstream: jetstream::Context, config: &AppConfig) |
212 | 212 | } |
213 | 213 |
|
214 | 214 | fn load_config(args: &Args) -> Result<AppConfig> { |
215 | | - let mut config = Config::builder(); |
| 215 | + let mut builder = Config::builder(); |
216 | 216 | if let Some(config_path) = args.config.as_ref() { |
217 | 217 | info!("Loading configuration from file: {:?}", config_path); |
218 | | - config = config.add_source(config::File::from(config_path.clone())); |
| 218 | + builder = builder.add_source(config::File::from(config_path.clone())); |
219 | 219 | } else { |
220 | 220 | info!("No config file specified, using default 'config.toml'"); |
221 | | - config = config.add_source(config::File::with_name("config.toml").required(false)); |
| 221 | + builder = builder.add_source(config::File::with_name("config.toml").required(false)); |
222 | 222 | } |
223 | 223 |
|
224 | 224 | // Add environment variables |
225 | 225 | info!("Adding environment variables to configuration"); |
226 | | - config = config.add_source(config::Environment::with_prefix("PYTH")); |
| 226 | + builder = builder.add_source(config::Environment::with_prefix("PYTH").separator("__")); |
227 | 227 |
|
228 | 228 | // Build the configuration |
229 | 229 | info!("Building configuration"); |
230 | | - let config: AppConfig = match config.build()?.try_deserialize() { |
231 | | - Ok(cfg) => { |
232 | | - debug!("Configuration loaded successfully: {:?}", cfg); |
233 | | - cfg |
234 | | - } |
235 | | - Err(e) => { |
236 | | - error!("Failed to deserialize configuration: {}", e); |
237 | | - return Err(anyhow::anyhow!("Configuration error: {}", e)); |
238 | | - } |
239 | | - }; |
| 230 | + let config = builder.build()?; |
| 231 | + |
| 232 | + debug!("Raw config: {:?}", config); |
| 233 | + let app_config: AppConfig = config |
| 234 | + .try_deserialize() |
| 235 | + .context("Failed to deserialize configuration")?; |
240 | 236 |
|
241 | | - Ok(config) |
| 237 | + debug!("Parsed config: {:?}", app_config); |
| 238 | + Ok(app_config) |
242 | 239 | } |
243 | 240 |
|
244 | 241 | #[tokio::main] |
|
0 commit comments