Skip to content

Commit 9bb69fd

Browse files
authored
payjoin-cli: Organize config errors (#256)
fix #242 The original error was caused by a bad default `""` `ohttp_relay` value. That has been addressesed as well as the context that's provided when an error does happen. Supplying config error context makes it so the issue outlined in #242 would now throw: ``` Error: Failed to parse config Caused by: missing field `ohttp_relay` ```
2 parents 9ed4c50 + 658dc19 commit 9bb69fd

2 files changed

Lines changed: 3 additions & 6 deletions

File tree

payjoin-cli/src/app/config.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use std::net::SocketAddr;
22
use std::path::PathBuf;
33

4-
use anyhow::Result;
54
use clap::ArgMatches;
6-
use config::{Config, File, FileFormat};
5+
use config::{Config, ConfigError, File, FileFormat};
76
use serde::Deserialize;
87
use url::Url;
98

@@ -25,7 +24,7 @@ pub struct AppConfig {
2524
}
2625

2726
impl AppConfig {
28-
pub(crate) fn new(matches: &ArgMatches) -> Result<Self> {
27+
pub(crate) fn new(matches: &ArgMatches) -> Result<Self, ConfigError> {
2928
let builder = Config::builder()
3029
.set_default("bitcoind_rpchost", "http://localhost:18443")?
3130
.set_override_option(
@@ -55,12 +54,10 @@ impl AppConfig {
5554

5655
#[cfg(feature = "v2")]
5756
let builder = builder
58-
.set_default("ohttp_keys", None::<String>)?
5957
.set_override_option(
6058
"ohttp_keys",
6159
matches.get_one::<String>("ohttp_keys").map(|s| s.as_str()),
6260
)?
63-
.set_default("ohttp_relay", "")?
6461
.set_override_option(
6562
"ohttp_relay",
6663
matches.get_one::<Url>("ohttp_relay").map(|s| s.as_str()),

payjoin-cli/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ async fn main() -> Result<()> {
1616
env_logger::init();
1717

1818
let matches = cli();
19-
let config = AppConfig::new(&matches)?;
19+
let config = AppConfig::new(&matches).with_context(|| "Failed to parse config")?;
2020
let app = App::new(config)?;
2121

2222
match matches.subcommand() {

0 commit comments

Comments
 (0)