Skip to content

Commit ffa537e

Browse files
Don't override DecodeError on BOLT 12 message read
Previously when reading a BOLT 12 message from bytes, if it resulted in a DecodeError then that error would be overridden by DecodeError::InvalidValue specifically. Better to return to underlying specific error.
1 parent 183b337 commit ffa537e

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

lightning/src/offers/invoice.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1403,7 +1403,10 @@ impl LengthReadable for Bolt12Invoice {
14031403
reader: &mut R,
14041404
) -> Result<Self, DecodeError> {
14051405
let bytes: WithoutLength<Vec<u8>> = LengthReadable::read_from_fixed_length_buffer(reader)?;
1406-
Self::try_from(bytes.0).map_err(|_| DecodeError::InvalidValue)
1406+
Self::try_from(bytes.0).map_err(|e| match e {
1407+
Bolt12ParseError::Decode(e) => e,
1408+
_ => DecodeError::InvalidValue,
1409+
})
14071410
}
14081411
}
14091412

lightning/src/offers/invoice_request.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,10 @@ impl Writeable for InvoiceRequestContents {
11231123
impl LengthReadable for InvoiceRequest {
11241124
fn read_from_fixed_length_buffer<R: LengthLimitedRead>(r: &mut R) -> Result<Self, DecodeError> {
11251125
let bytes: WithoutLength<Vec<u8>> = LengthReadable::read_from_fixed_length_buffer(r)?;
1126-
Self::try_from(bytes.0).map_err(|_| DecodeError::InvalidValue)
1126+
Self::try_from(bytes.0).map_err(|e| match e {
1127+
Bolt12ParseError::Decode(e) => e,
1128+
_ => DecodeError::InvalidValue,
1129+
})
11271130
}
11281131
}
11291132

lightning/src/offers/offer.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,10 @@ impl LengthReadable for Offer {
10391039
reader: &mut R,
10401040
) -> Result<Self, DecodeError> {
10411041
let bytes: WithoutLength<Vec<u8>> = LengthReadable::read_from_fixed_length_buffer(reader)?;
1042-
Self::try_from(bytes.0).map_err(|_| DecodeError::InvalidValue)
1042+
Self::try_from(bytes.0).map_err(|e| match e {
1043+
Bolt12ParseError::Decode(e) => e,
1044+
_ => DecodeError::InvalidValue,
1045+
})
10431046
}
10441047
}
10451048

lightning/src/offers/refund.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,10 @@ impl LengthReadable for Refund {
829829
reader: &mut R,
830830
) -> Result<Self, DecodeError> {
831831
let bytes: WithoutLength<Vec<u8>> = LengthReadable::read_from_fixed_length_buffer(reader)?;
832-
Self::try_from(bytes.0).map_err(|_| DecodeError::InvalidValue)
832+
Self::try_from(bytes.0).map_err(|e| match e {
833+
Bolt12ParseError::Decode(e) => e,
834+
_ => DecodeError::InvalidValue,
835+
})
833836
}
834837
}
835838

0 commit comments

Comments
 (0)