rust-bitcoin / rust-bech32

Bech32 format encoding and decoding
MIT License
93 stars 49 forks source link

Add `errors` example demo file #151

Open tcharding opened 10 months ago

tcharding commented 10 months ago

Add an errors example that creates and prints various error types from the crate. This is useful for two main purposes:

Run with appropriate features to verify the output, e.g.,

      `cargo run --example errors --no-default-features --features=alloc`

This example is prone to go stale, is it useful? I could not think of any other way to verify that our error output was good (in both std and no-std environments).

apoelstra commented 10 months ago

Hmm, concept ACK 61b6300ad854067c55ef9ce27c3ea3749c74b5c5.

I think in practice this'd be pretty hard to keep in sync with the actual error types. Maybe it should be a collection of unit tests rather than examples?

tcharding commented 10 months ago

Its only about the "meaningfulness" of the error messages, I couldn't think of a way to test this except look at it every now and again. Once we are happy I don't think it will matter if some are missed, since devs will tend to copy the error style currently there.

apoelstra commented 10 months ago

Ok, makes sense.

After running the example all the error messages look great to me except that we should drop code= on the InvalidChar message.

tcharding commented 10 months ago

Sweet! Thanks for running them.

apoelstra commented 10 months ago

Do you want this to be merged?

tcharding commented 10 months ago

Maybe just leave it here and I'll have a go doing it in another repo, then see if it feels like its worth having. I'm not 100% sure it won't just sit and rot never to be touched again.