embedded-hal-mock icon indicating copy to clipboard operation
embedded-hal-mock copied to clipboard

Error message specificity for empty Mock

Open tommy-gilligan opened this issue 5 months ago • 2 comments

In a few places there are error messages like this one:

https://github.com/dbrgn/embedded-hal-mock/blob/3ac0ada5110218682e0dd1939f74cd008ee6d912/src/eh1/pin.rs#L135

This error message is triggered when Mock is empty. I don't think including the method name set_low is useful. Especially because it is followed by

        assert_eq!(
            kind,
            TransactionKind::Set(State::Low),
            "expected pin::set_low"
        );

https://github.com/dbrgn/embedded-hal-mock/blob/3ac0ada5110218682e0dd1939f74cd008ee6d912/src/eh1/pin.rs#L137C1-L141C11

A more generic message should enable more code sharing and more succinct implementation.

tommy-gilligan avatar Jan 31 '24 23:01 tommy-gilligan

Hm, I disagree. If you get a generic error message, this means that a HAL call was issued without an expectation.

If you don't know which call triggered this, it is very hard to debug the issue.

I don't think including the method name set_low is useful. Especially because it is followed by (...)

It doesn't matter what it's followed by, because the expect call will immediately panic.

dbrgn avatar Feb 01 '24 21:02 dbrgn

The error message can retain the function name and be generic with a crate such as function_name, though this does have limitations.

newAM avatar Feb 04 '24 23:02 newAM