From 1651fd5a476b9d19ba065f00a873743d42856ef3 Mon Sep 17 00:00:00 2001
From: Awiteb
Date: Sat, 14 Jun 2025 10:44:15 +0000
Subject: [PATCH] fix: Not to return an error if `nostr-address` file does not
exist
Signed-off-by: Awiteb
---
CHANGELOG.md | 4 ++++
src/nostr_utils/utils.rs | 12 +++++++++---
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d9d39b2..f1915db 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -18,6 +18,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- New `patch fetch` command to fetch patches - by Awiteb
- New `issue {reopen,close,resolve}` commands to manage issue status - by Awiteb
+### Fixed
+
+- Not to return an error if `nostr-address` file does not exist - by Awiteb
+
### Refactor
- Store the config in `CliOptions` instead of its path - by Awiteb
diff --git a/src/nostr_utils/utils.rs b/src/nostr_utils/utils.rs
index 16e92bb..f8b2717 100644
--- a/src/nostr_utils/utils.rs
+++ b/src/nostr_utils/utils.rs
@@ -227,8 +227,9 @@ pub fn nostr_address_path() -> std::io::Result {
std::env::current_dir().map(|p| p.join(NOSTR_ADDRESS_FILE))
}
-/// If the given coordinate is Some, return it. Otherwise, try to read and parse
-/// the first non-comment line from the `nostr-address` file.
+/// Returns the given coordinates if Some, otherwise attempts to read and parse
+/// coordinates from the specified file. Returns an empty vector if the file
+/// doesn't exist.
pub fn naddrs_or_file(
naddrs: Option>,
address_file_path: &Path,
@@ -236,7 +237,12 @@ pub fn naddrs_or_file(
if let Some(naddrs) = naddrs {
return Ok(naddrs);
}
- parsers::parse_nostr_address_file(address_file_path)
+
+ if address_file_path.exists() {
+ parsers::parse_nostr_address_file(address_file_path)
+ } else {
+ Ok(Vec::new())
+ }
}
/// Generate a reply tag for an event with the given ID, relay URL (if any), and