diff --git a/src/chain.rs b/src/chain.rs index d21b05aa61..e8ff2a2d10 100644 --- a/src/chain.rs +++ b/src/chain.rs @@ -66,11 +66,8 @@ impl Chain { } } - pub(crate) fn address_from_script( - self, - script: &Script, - ) -> Result { - Address::from_script(script, self.network()) + pub(crate) fn address_from_script(self, script: &Script) -> Result { + Address::from_script(script, self.network()).snafu_context(error::AddressConversion) } pub(crate) fn join_with_data_dir(self, data_dir: impl AsRef) -> PathBuf { @@ -110,7 +107,7 @@ impl Display for Chain { } impl FromStr for Chain { - type Err = Error; + type Err = SnafuError; fn from_str(s: &str) -> Result { match s { @@ -118,7 +115,9 @@ impl FromStr for Chain { "regtest" => Ok(Self::Regtest), "signet" => Ok(Self::Signet), "testnet" => Ok(Self::Testnet), - _ => bail!("invalid chain `{s}`"), + _ => Err(SnafuError::InvalidChain { + chain: s.to_string(), + }), } } } @@ -135,7 +134,7 @@ mod tests { assert_eq!("testnet".parse::().unwrap(), Chain::Testnet); assert_eq!( "foo".parse::().unwrap_err().to_string(), - "invalid chain `foo`" + "Invalid chain `foo`" ); } }