upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/nostr/builder.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/nostr/builder.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/nostr/builder.rs')
-rw-r--r--src/nostr/builder.rs34
1 files changed, 16 insertions, 18 deletions
diff --git a/src/nostr/builder.rs b/src/nostr/builder.rs
index 10f7648..9819e37 100644
--- a/src/nostr/builder.rs
+++ b/src/nostr/builder.rs
@@ -567,26 +567,24 @@ pub async fn create_relay(
567 // Clone Arc for the write policy so both relay and policy can access the database 567 // Clone Arc for the write policy so both relay and policy can access the database
568 let git_data_path = config.effective_git_data_path(); 568 let git_data_path = config.effective_git_data_path();
569 569
570 // Parse and log archive configuration 570 // Log archive configuration (config.validate() must be called at startup)
571 if let Ok(archive_config) = config.archive_config() { 571 let archive_config = config.archive_config();
572 if archive_config.enabled() { 572 if archive_config.enabled() {
573 tracing::info!( 573 tracing::info!(
574 "GRASP-05 archive mode enabled: archive_all={}, whitelist_entries={}, read_only={}", 574 "GRASP-05 archive mode enabled: archive_all={}, whitelist_entries={}, read_only={}",
575 archive_config.archive_all, 575 archive_config.archive_all,
576 archive_config.whitelist.len(), 576 archive_config.whitelist.len(),
577 archive_config.read_only 577 archive_config.read_only
578 ); 578 );
579 }
580 } 579 }
581 580
582 // Parse and log repository configuration 581 // Log repository configuration
583 if let Ok(repository_config) = config.repository_config() { 582 let repository_config = config.repository_config();
584 if repository_config.enabled() { 583 if repository_config.enabled() {
585 tracing::info!( 584 tracing::info!(
586 "Repository whitelist enabled: whitelist_entries={}", 585 "Repository whitelist enabled: whitelist_entries={}",
587 repository_config.whitelist.len() 586 repository_config.whitelist.len()
588 ); 587 );
589 }
590 } 588 }
591 589
592 // Create write policy with purgatory integration 590 // Create write policy with purgatory integration