Skip to content

Commit 32bbda5

Browse files
committed
Use SemanticError in OfferBuilder::build
1 parent 47e4924 commit 32bbda5

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();
@@ -211,9 +210,9 @@ impl OfferBuilder {
211210
}
212211

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

219218
let mut bytes = Vec::new();
@@ -531,6 +530,7 @@ mod tests {
531530
use core::num::NonZeroU64;
532531
use core::time::Duration;
533532
use ln::features::OfferFeatures;
533+
use offers::parse::SemanticError;
534534
use onion_message::{BlindedHop, BlindedPath};
535535
use util::ser::Writeable;
536536

@@ -884,11 +884,10 @@ mod tests {
884884
assert_eq!(tlv_stream.quantity_min, None);
885885
assert_eq!(tlv_stream.quantity_max, Some(9));
886886

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

0 commit comments

Comments
 (0)