Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use thiserror rather than eyre in mijia crate #83

Merged
merged 9 commits into from
Nov 29, 2020
Merged

Use thiserror rather than eyre in mijia crate #83

merged 9 commits into from
Nov 29, 2020

Conversation

qwandor
Copy link
Collaborator

@qwandor qwandor commented Nov 26, 2020

It seems more appropriate for a library.

@qwandor qwandor requested a review from alsuren November 26, 2020 22:17
@qwandor qwandor force-pushed the eyre-ire branch 3 times, most recently from 8bc19e2 to 5f3d016 Compare November 28, 2020 17:59
Base automatically changed from mijia-properties to master November 28, 2020 20:26
Copy link
Owner

@alsuren alsuren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See what this does to the backtraces and then ship it? Would be nice to know whether converting from box dyn Error to thiserror to eyre throws stack frames away. It may be that the backtrace crate registers itself in a magical way that makes everything get preserved, but I'm also okay with losing a few frames of dbus-rs as long as we can still report the place where our thiserror is being constructed.

mijia/src/bluetooth.rs Outdated Show resolved Hide resolved
if value.len() != 6 {
bail!("Wrong length {} for comfort level", value.len());
}
pub(crate) fn decode(value: &[u8]) -> Result<ComfortLevel, DecodeError> {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(probably not something to touch in this PR): Now that I this is feeling quite a lot like the signature of impl TryFrom<&[u8]> for ComfortLevel and decode() feels like impl TryFrom<ComfortLevel> for [u8, 6]

It may be that converting these all to TryInto will destroy the ergonomics at the call site though. We would certainly need provide a newtype for SystemTime if we went in this direction.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would mean that the decoding logic is part of the public API of the crate, which I'm not sure we want. I was considering adding some private traits, but it doesn't really give any advantage, and prevents some of the slight differences in signatures we currently have (e.g. encoding TemperatureUnit can't fail, so doesn't return a Result).

@qwandor
Copy link
Collaborator Author

qwandor commented Nov 29, 2020

Backtraces go up to the point that mijia-homie calls into mijia library methods and have the error which they return as cause, which I think is enough. Unfortunately thiserror only supports backtraces with nightly Rust, not with the backtrace crate. Added #85 to track this.

@qwandor qwandor merged commit 0473453 into master Nov 29, 2020
@qwandor qwandor deleted the eyre-ire branch November 29, 2020 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants