upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2026-01-12 21:20:00 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2026-01-12 21:21:53 +0000
commit1948312d40f34fca868d1ef6d6d94e165c09738c (patch)
treef25f930785145023be6fe33e52904a5d8383a62d /src/main.rs
parent82b56c37b26a2fac1a294873e539b19b9325dca6 (diff)
refactor(config): validate eagerly at startup and remove Result from runtime config methods
Refactors configuration validation to fail fast on fatal errors at startup while gracefully handling recoverable issues (e.g., malformed whitelist entries). Changes: - Add Config::validate() for eager validation called immediately after load - Remove Result<> from archive_config() and repository_config() methods - WhitelistEntry::parse_whitelist() skips invalid entries with warnings - Validate relay_owner_nsec format in Config::validate() - Update all call sites to remove Result handling from config getters Benefits: - Fatal config errors (incompatible settings) fail at startup, not runtime - Recoverable errors (bad whitelist entries) logged as warnings and skipped - No Result handling scattered throughout runtime code after validation - Config methods safe to call without error handling after validate() Testing: - Add 7 new tests for validation edge cases and error handling - Total config tests: 40 (up from 33) - All 320 library tests passing Breaking change: Config users must call config.validate() after Config::load() to ensure configuration is valid. This is enforced in main.rs.
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index 8b959a6..a6f1d9d 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -28,7 +28,14 @@ async fn main() -> Result<()> {
28 // Load configuration (priority: CLI flags > env vars > .env file > defaults) 28 // Load configuration (priority: CLI flags > env vars > .env file > defaults)
29 let config = Config::load()?; 29 let config = Config::load()?;
30 30
31 info!("Configuration loaded: {}", config.bind_address); 31 // Validate configuration and fail fast on fatal errors
32 // Recoverable issues (e.g., malformed whitelist entries) are logged as warnings
33 config.validate()?;
34
35 info!(
36 "Configuration loaded and validated: {}",
37 config.bind_address
38 );
32 info!("Domain: {}", config.domain); 39 info!("Domain: {}", config.domain);
33 info!("Relay name: {}", config.relay_name()); 40 info!("Relay name: {}", config.relay_name());
34 info!("Git data directory: {}", config.effective_git_data_path()); 41 info!("Git data directory: {}", config.effective_git_data_path());