-
Notifications
You must be signed in to change notification settings - Fork 54
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
Fixed most clippy lints and enabled clippy for all targets #1874
Conversation
Robot Results
Passed Tests
|
83604c9
to
6f90dd8
Compare
Thank you for the link - indeed a nicely written post and appealing goals (as a side note, I like a lot this quote cited in the post from Sean Parent about rules vs goals). So yes, I agree that we need to work in that direction and I will do so. |
result-large-err lint was fixed by changing `SmartRestSerializerError` to not contain `csv::IntoInnerError` which contains a writer and is meant to offer a capability to recover from failure. But we simply just returned this error to the caller, so the returned error was changed to inner io::Error. To be able to move the `io::Error` out of `csv::IntoInnerError`, csv crate was upgraded to 1.2.1, which added `IntoInnerError::into_error` function. This addition in patch version is not valid semver, so dependency in `Cargo.toml` is specified as "1.2.1" (<= 1.2.1, < 2.0.0). Additionally the error types of some functions changed. Functions which returned `Result` but didn't actually return any errors were made infallible and functions which returned a large error enums but could actually only return a single variant which wrapped a smaller error, now return this inner error. Overall, these changes were made only to fix the lint, but error handling could be simplified further, improving both readability and performance, as described in thin-edge#1767. Signed-off-by: Marcel Guzik <marcel.guzik@inetum.com>
The lint was fixed primarily by changing error types returned by many functions from big crate-global error enums to smaller error types defined locally. This eliminates dependencies on parents, making these functions more reusable and moves the responsibility of performing `From` conversions to the caller code. In tedge_api, one particularly large field in some variants got boxed because replacing it was just too tedious. As with the preceeding commit, errors could be improved even more, improving readability as described in thin-edge#1767, but it will require more effort and will be done more slowly, just for crates where we decide properly handling errors is particularly painful. Signed-off-by: Marcel Guzik <marcel.guzik@inetum.com>
Fixed lints that were not showing up on PR checks because they were in tests, and configured clippy to run on all targets (bins, libs, tests, benches, examples, etc). Also removed allow for result-large-err. Signed-off-by: Marcel Guzik <marcel.guzik@inetum.com>
6f90dd8
to
e27f36d
Compare
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.
Approved
csv = "1.1" | ||
csv = "1.2.1" |
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 agreed to set only major and minor version of dependencies, ignoring the patch.
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.
Yes, but in this case it has to be 1.2.1 because the method I used got added in 1.2.1 and just leaving csv = "1.2"
means that depending on the lockfile,1.2.0 could be used resulting in compilation errors.
Proposed changes
This PR removes all
#[allow()]
s and fixes all occurences ofclippy::result_large_err
andclippy::large_enum_variant
warnings and fixes some other remaining lints. Details in commit messages.Types of changes
Paste Link to the issue
Checklist
cargo fmt
as mentioned in CODING_GUIDELINEScargo clippy
as mentioned in CODING_GUIDELINESFurther comments
This PR fixes error-related lints and sets up clippy in a way that lints should not gather up unaddressed, but there is still room for improvement relating to the structure of the errors, where the large number of variants, wrapping all possible error sources, and naming the variants in terms of which dependency thrown the error instead of what actually went wrong, make it harder to understand the actual error conditions (more about it here), but as it would be too much work to refactor all the error types and too much disruption of possibly breaking a lot of perfectly working code, these improvements will possibly be made in the future on a module-by-module basis.
In essence, old code can remain as it is, but from now on I'd advise we need to look out for and ensure quality error handling in new code and perhaps slowly improving old code that new code frequently needs to interface with.