Skip to content

Commit 136f088

Browse files
committed
Use SemanticError in OfferBuilder::build
1 parent 62e87fa commit 136f088

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

lightning/src/offers/offer.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@
4747
//! .issuer("Foo Bar".to_string())
4848
//! .path(create_blinded_path())
4949
//! .path(create_another_blinded_path())
50-
//! .build()
51-
//! .unwrap();
50+
//! .build()?;
5251
//!
5352
//! // Encode as a bech32 string for use in a QR code.
5453
//! let encoded_offer = offer.to_string();
@@ -212,9 +211,9 @@ impl OfferBuilder {
212211
}
213212

214213
/// Builds an [`Offer`] from the builder's settings.
215-
pub fn build(self) -> Result<Offer, ()> {
214+
pub fn build(self) -> Result<Offer, SemanticError> {
216215
if self.offer.quantity_min() > self.offer.quantity_max() {
217-
return Err(());
216+
return Err(SemanticError::InvalidQuantity);
218217
}
219218

220219
let mut bytes = Vec::new();
@@ -533,6 +532,7 @@ mod tests {
533532
use core::num::NonZeroU64;
534533
use core::time::Duration;
535534
use ln::features::OfferFeatures;
535+
use offers::parse::SemanticError;
536536
use onion_message::{BlindedHop, BlindedPath};
537537
use util::ser::Writeable;
538538

@@ -886,11 +886,10 @@ mod tests {
886886
assert_eq!(tlv_stream.quantity_min, None);
887887
assert_eq!(tlv_stream.quantity_max, Some(9));
888888

889-
assert!(OfferBuilder::new("foo".into(), pubkey(42))
890-
.quantity_range(ten..five)
891-
.build()
892-
.is_err()
893-
);
889+
match OfferBuilder::new("foo".into(), pubkey(42)).quantity_range(ten..five).build() {
890+
Ok(_) => panic!("expected error"),
891+
Err(e) => assert_eq!(e, SemanticError::InvalidQuantity),
892+
}
894893
}
895894
}
896895

0 commit comments

Comments
 (0)