upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/nostr/events.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/events.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/events.rs')
-rw-r--r--src/nostr/events.rs12
1 files changed, 3 insertions, 9 deletions
diff --git a/src/nostr/events.rs b/src/nostr/events.rs
index 3ec075d..3b4ef25 100644
--- a/src/nostr/events.rs
+++ b/src/nostr/events.rs
@@ -400,15 +400,9 @@ pub fn validate_announcement(
400 Err(e) => return AnnouncementResult::Reject(format!("Invalid announcement: {}", e)), 400 Err(e) => return AnnouncementResult::Reject(format!("Invalid announcement: {}", e)),
401 }; 401 };
402 402
403 // Get archive and repository configs (fail-secure: reject on config errors) 403 // Get validated configs (config.validate() must be called at startup)
404 let archive_config = match config.archive_config() { 404 let archive_config = config.archive_config();
405 Ok(c) => c, 405 let repository_config = config.repository_config();
406 Err(e) => return AnnouncementResult::Reject(format!("Config error: {}", e)),
407 };
408 let repository_config = match config.repository_config() {
409 Ok(c) => c,
410 Err(e) => return AnnouncementResult::Reject(format!("Config error: {}", e)),
411 };
412 406
413 let npub = announcement.owner_npub(); 407 let npub = announcement.owner_npub();
414 let lists_service = announcement.lists_service(&config.domain); 408 let lists_service = announcement.lists_service(&config.domain);