-
Notifications
You must be signed in to change notification settings - Fork 121
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
feat: Add support for custom exception codes #279
Conversation
Thanks for contributing! Some general remarks for discussion. I have noticed that the naming of the types The different naming of the fallback variants |
Yes, having consistency would be great to see, should this be done in this PR or open another one?
I'm not sure either, but personally I'd go with |
The documentation of both types should also mention, that encoding one of the predefined variants as |
We should address the naming of Let's use |
GatewayTargetDevice, | ||
/// None of the above. | ||
/// | ||
/// Although encoding one of the predefined values as this is possible, it is not recommended. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could then add something like the following hint:
Instead of instantiating this variant directly prefer to use [`Self::new()`] to prevent such ambiguities.
CHANGELOG.md
Outdated
@@ -3,6 +3,15 @@ | |||
|
|||
# Changelog | |||
|
|||
## v0.15.0 (Unreleased) | |||
|
|||
- Added `Exception::Other`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Added `Exception::Other`. | |
- Added `Exception::Custom`. |
src/codec/mod.rs
Outdated
@@ -385,34 +385,17 @@ impl TryFrom<Bytes> for ExceptionResponse { | |||
)); | |||
} | |||
let function = fn_err_code - 0x80; | |||
let exception = Exception::try_from(rdr.read_u8()?)?; | |||
let exception = Exception::from(rdr.read_u8()?); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let exception = Exception::from(rdr.read_u8()?); | |
let exception = Exception::new(rdr.read_u8()?); |
src/codec/mod.rs
Outdated
} | ||
}; | ||
Ok(ex) | ||
impl From<u8> for Exception { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to delete this impl From
.
As a user of this crate you probably do not want to convert arbitrary u8
values implicitly into a Modbus exception code with .into()
. With Exception::new()
we now have an explicit constructor to make such a conversion explicit.
I generally try to avoid From
/TryFrom
implementations between types of different abstraction levels. These should be explicitly converted with properly named methods.
Please then also update the changelog accordingly.
src/frame/mod.rs
Outdated
GatewayTargetDevice, | ||
/// None of the above. | ||
/// | ||
/// Although encoding one of the predefined values as this is possible, it is not recommended, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please split into two sentences for readability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one remaining remark.
Reporting a bug and with a follow-up PR that fixes it is nice. Thank you! |
Nice! |
Would close #278
This PR is just for a better insight on my problem and suggested changes (although it compiles, tests run successfully and pre-commit is happy).
As in the context of the linked issue, this introduces breaking changes.