Skip to content

In v0.1.1, InvalidLength error prints 'expected' and 'got' values swapped #87

@jirijakes

Description

@jirijakes

While during parsing the values are in order (want, got):

Err(HexToArrayError::InvalidLength(2 * $len, 2 * iter.len()))

Display prints them in order (got, want):

impl fmt::Display for HexToArrayError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use HexToArrayError::*;
match *self {
Conversion(ref e) => crate::write_err!(f, "conversion error"; e),
InvalidLength(got, want) =>
write!(f, "bad hex string length {} (expected {})", got, want),
}
}
}

This was, probably inadvertently, later fixed and v0.2.0 does not suffer from it anymore.

The issue is that rust-bitcoin v0.31.2 depends on hex-conservative v0.1.1 and therefore the error messages in v0.31.2 are incorrect. I know it's too tiny an issue, but if there is will to have this fixed (I can help), perhaps the solution would be to publish v0.1.2 with fix and let rust-bitcoin v0.31.3 depend on it?


Background: I am upgrading rust-lightning to rust-bitcoin v0.31 (see #2745) and it so happens that rust-lightning has a test which fails with v0.31 due to this issue. I have not yet opened PR on rust-lightning, may do so tomorrow.

failures:

---- convert::tests::into_txid_from_json_response_with_invalid_hex_data stdout ----
thread 'convert::tests::into_txid_from_json_response_with_invalid_hex_data' panicked at lightning-block-sync/src/convert.rs:610:17:
assertion `left == right` failed
  left: "bad hex string length 64 (expected 6)"
 right: "bad hex string length 6 (expected 64)"
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

---- convert::tests::into_txid_from_json_response_with_invalid_txid_data stdout ----
thread 'convert::tests::into_txid_from_json_response_with_invalid_txid_data' panicked at lightning-block-sync/src/convert.rs:622:17:
assertion `left == right` failed
  left: "bad hex string length 64 (expected 4)"
 right: "bad hex string length 4 (expected 64)"


failures:
    convert::tests::into_txid_from_json_response_with_invalid_hex_data
    convert::tests::into_txid_from_json_response_with_invalid_txid_data

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions