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

Fixed most clippy lints and enabled clippy for all targets #1874

Merged
merged 3 commits into from
Mar 30, 2023

Conversation

Bravo555
Copy link
Contributor

Proposed changes

This PR removes all #[allow()]s and fixes all occurences of clippy::result_large_err and clippy::large_enum_variant warnings and fixes some other remaining lints. Details in commit messages.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Improvement (general improvements like code refactoring that doesn't explicitly fix a bug or add any new functionality)
  • Documentation Update (if none of the other choices apply)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Paste Link to the issue

Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the CLA (in all commits with git commit -s)
  • I ran cargo fmt as mentioned in CODING_GUIDELINES
  • I used cargo clippy as mentioned in CODING_GUIDELINES
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Further 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.

@Bravo555 Bravo555 changed the title Fixed most clippy lints and enabled clippy for all targets. Fixed most clippy lints and enabled clippy for all targets Mar 30, 2023
@Bravo555 Bravo555 temporarily deployed to Test Pull Request March 30, 2023 14:19 — with GitHub Actions Inactive
@github-actions
Copy link
Contributor

github-actions bot commented Mar 30, 2023

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass %
167 0 5 167 100

Passed Tests

Name ⏱️ Duration Suite
Define Child device 1 ID 0.004 s C8Y Child Alarms Rpi
Normal case when the child device does not exist on c8y cloud 2.287 s C8Y Child Alarms Rpi
Normal case when the child device already exists 0.707 s C8Y Child Alarms Rpi
Reconciliation when the new alarm message arrives, restart the mapper 1.369 s C8Y Child Alarms Rpi
Reconciliation when the alarm that is cleared 5.802 s C8Y Child Alarms Rpi
Prerequisite Parent 18.826 s Child Conf Mgmt Plugin
Prerequisite Child 0.76 s Child Conf Mgmt Plugin
Child device bootstrapping 16.09 s Child Conf Mgmt Plugin
Snapshot from device 60.937 s Child Conf Mgmt Plugin
Child device config update 62.297 s Child Conf Mgmt Plugin
Configuration types should be detected on file change (without restarting service) 51.387 s Inotify Crate
Check lock file existence in default folder 1.924 s Lock File
Check starting same service twice 1.958 s Lock File
Switch off lock file creation 3.789 s Lock File
Child devices support sending simple measurements 1.688 s Child Device Telemetry
Child devices support sending custom measurements 1.423 s Child Device Telemetry
Child devices support sending custom events 1.019 s Child Device Telemetry
Child devices support sending custom events overriding the type 0.993 s Child Device Telemetry
Child devices support sending custom alarms #1699 1.298 s Child Device Telemetry
Child devices support sending inventory data via c8y topic 1.097 s Child Device Telemetry
Main device support sending inventory data via c8y topic 1.194 s Child Device Telemetry
Child device supports sending custom child device measurements directly to c8y 1.495 s Child Device Telemetry
Main device supports sending custom child device measurements directly to c8y 2.235 s Child Device Telemetry
Successful firmware operation 65.111 s Firmware Operation
Install with empty firmware name 62.988 s Firmware Operation
Prerequisite Parent 21.047 s Firmware Operation Child Device
Prerequisite Child 7.866 s Firmware Operation Child Device
Child device firmware update 3.855 s Firmware Operation Child Device
Child device firmware update with cache 5.875 s Firmware Operation Child Device
Update Inventory data via inventory.json 1.229 s Inventory Update
Retrieve a JWT tokens 53.219 s Jwt Request
Main device registration 1.646 s Device Registration
Child device registration 2.374 s Device Registration
Supports restarting the device 76.019 s Restart Device
Update tedge version from previous using Cumulocity 102.078 s Tedge Self Update
Test if all c8y services are up 66.875 s Service Monitoring
Test if all c8y services are down 59.751 s Service Monitoring
Test if all c8y services are using configured service type 65.081 s Service Monitoring
Test if all c8y services using default service type when service type configured as empty 45.229 s Service Monitoring
Check health status of tedge-mapper-c8y service on broker stop start 31.77 s Service Monitoring
Check health status of tedge-mapper-c8y service on broker restart 35.253 s Service Monitoring
Check health status of child device service 26.755 s Service Monitoring
Successful shell command with output 3.502 s Shell Operation
Check Successful shell command with literal double quotes output 3.516 s Shell Operation
Execute multiline shell command 3.2359999999999998 s Shell Operation
Failed shell command 2.93 s Shell Operation
Software list should be populated during startup 53.073 s Software
Install software via Cumulocity 69.361 s Software
Software list should only show currently installed software and not candidates 46.491 s Software
Validate updated data path used by tedge-agent 0.585 s Data Path Config
Validate updated data path used by c8y-firmware-plugin 10.722 s Data Path Config
Stop tedge-agent service 0.531 s Log Path Config
Customize the log path 0.195 s Log Path Config
Initialize tedge-agent 0.141 s Log Path Config
Check created folders 0.134 s Log Path Config
Remove created custom folders 0.276 s Log Path Config
Install thin-edge via apt 57.114 s Install Apt
Install latest via script (from current branch) 32.247 s Install Tedge
Install specific version via script (from current branch) 15.914 s Install Tedge
Install latest tedge via script (from main branch) 22.237 s Install Tedge
Support starting and stopping services 45.171 s Service-Control
Supports a reconnect 57.3 s Test-Commands
Supports disconnect then connect 55.359 s Test-Commands
Update unknown setting 36.591 s Test-Commands
Update known setting 24.712 s Test-Commands
Stop c8y-configuration-plugin 0.201 s Health C8Y-Configuration-Plugin
Update the service file 0.299 s Health C8Y-Configuration-Plugin
Reload systemd files 0.706 s Health C8Y-Configuration-Plugin
Start c8y-configuration-plugin 0.143 s Health C8Y-Configuration-Plugin
Start watchdog service 10.17 s Health C8Y-Configuration-Plugin
Check PID of c8y-configuration-plugin 0.293 s Health C8Y-Configuration-Plugin
Kill the PID 0.809 s Health C8Y-Configuration-Plugin
Recheck PID of c8y-configuration-plugin 0.251 s Health C8Y-Configuration-Plugin
Compare PID change 0.001 s Health C8Y-Configuration-Plugin
Stop watchdog service 0.302 s Health C8Y-Configuration-Plugin
Remove entry from service file 0.221 s Health C8Y-Configuration-Plugin
Stop c8y-log-plugin 0.406 s Health C8Y-Log-Plugin
Update the service file 0.327 s Health C8Y-Log-Plugin
Reload systemd files 0.689 s Health C8Y-Log-Plugin
Start c8y-log-plugin 0.146 s Health C8Y-Log-Plugin
Start watchdog service 10.174 s Health C8Y-Log-Plugin
Check PID of c8y-log-plugin 0.412 s Health C8Y-Log-Plugin
Kill the PID 0.448 s Health C8Y-Log-Plugin
Recheck PID of c8y-log-plugin 0.23 s Health C8Y-Log-Plugin
Compare PID change 0.011 s Health C8Y-Log-Plugin
Stop watchdog service 0.253 s Health C8Y-Log-Plugin
Remove entry from service file 0.288 s Health C8Y-Log-Plugin
Stop tedge-mapper 0.36 s Health Tedge Mapper C8Y
Update the service file 0.231 s Health Tedge Mapper C8Y
Reload systemd files 1.024 s Health Tedge Mapper C8Y
Start tedge-mapper 0.243 s Health Tedge Mapper C8Y
Start watchdog service 10.288 s Health Tedge Mapper C8Y
Check PID of tedge-mapper 0.152 s Health Tedge Mapper C8Y
Kill the PID 0.294 s Health Tedge Mapper C8Y
Recheck PID of tedge-mapper 2.225 s Health Tedge Mapper C8Y
Compare PID change 0.001 s Health Tedge Mapper C8Y
Stop watchdog service 0.23 s Health Tedge Mapper C8Y
Remove entry from service file 0.221 s Health Tedge Mapper C8Y
Stop tedge-agent 0.235 s Health Tedge-Agent
Update the service file 0.102 s Health Tedge-Agent
Reload systemd files 0.455 s Health Tedge-Agent
Start tedge-agent 0.151 s Health Tedge-Agent
Start watchdog service 10.355 s Health Tedge-Agent
Check PID of tedge-mapper 0.162 s Health Tedge-Agent
Kill the PID 0.225 s Health Tedge-Agent
Recheck PID of tedge-agent 2.277 s Health Tedge-Agent
Compare PID change 0.001 s Health Tedge-Agent
Stop watchdog service 0.383 s Health Tedge-Agent
Remove entry from service file 0.169 s Health Tedge-Agent
Stop tedge-mapper-az 0.252 s Health Tedge-Mapper-Az
Update the service file 0.171 s Health Tedge-Mapper-Az
Reload systemd files 0.622 s Health Tedge-Mapper-Az
Start tedge-mapper-az 0.166 s Health Tedge-Mapper-Az
Start watchdog service 10.119 s Health Tedge-Mapper-Az
Check PID of tedge-mapper-az 0.107 s Health Tedge-Mapper-Az
Kill the PID 0.321 s Health Tedge-Mapper-Az
Recheck PID of tedge-agent 2.261 s Health Tedge-Mapper-Az
Compare PID change 0.001 s Health Tedge-Mapper-Az
Stop watchdog service 0.128 s Health Tedge-Mapper-Az
Remove entry from service file 0.089 s Health Tedge-Mapper-Az
Stop tedge-mapper-collectd 0.185 s Health Tedge-Mapper-Collectd
Update the service file 0.216 s Health Tedge-Mapper-Collectd
Reload systemd files 0.443 s Health Tedge-Mapper-Collectd
Start tedge-mapper-collectd 0.222 s Health Tedge-Mapper-Collectd
Start watchdog service 10.164 s Health Tedge-Mapper-Collectd
Check PID of tedge-mapper-collectd 0.242 s Health Tedge-Mapper-Collectd
Kill the PID 0.356 s Health Tedge-Mapper-Collectd
Recheck PID of tedge-mapper-collectd 0.116 s Health Tedge-Mapper-Collectd
Compare PID change 0.001 s Health Tedge-Mapper-Collectd
Stop watchdog service 0.171 s Health Tedge-Mapper-Collectd
Remove entry from service file 0.183 s Health Tedge-Mapper-Collectd
c8y-log-plugin health status 5.537 s MQTT health endpoints
c8y-configuration-plugin health status 5.799 s MQTT health endpoints
Publish on a local insecure broker 0.284 s Connect Broker
Publish on a local secure broker 3.355 s Connect Broker
Wrong package name 0.383 s Improve Tedge Apt Plugin Error Messages
Wrong version 0.246 s Improve Tedge Apt Plugin Error Messages
Wrong type 0.389 s Improve Tedge Apt Plugin Error Messages
tedge_connect_test_positive 0.595 s Tedge Connect Test
tedge_connect_test_negative 1.072 s Tedge Connect Test
tedge_connect_test_sm_services 7.658 s Tedge Connect Test
tedge_disconnect_test_sm_services 1.291 s Tedge Connect Test
Install thin-edge.io 12.604 s Call Tedge
call tedge -V 0.11 s Call Tedge
call tedge -h 0.083 s Call Tedge
call tedge -h -V 0.157 s Call Tedge
call tedge help 0.075 s Call Tedge
tedge config list 0.087 s Call Tedge Config List
tedge config list --all 0.125 s Call Tedge Config List
set/unset device.type 0.484 s Call Tedge Config List
set/unset device.key.path 0.463 s Call Tedge Config List
set/unset device.cert.path 0.415 s Call Tedge Config List
set/unset c8y.root.cert.path 0.408 s Call Tedge Config List
set/unset c8y.smartrest.templates 0.458 s Call Tedge Config List
set/unset az.root.cert.path 0.347 s Call Tedge Config List
set/unset az.mapper.timestamp 0.294 s Call Tedge Config List
set/unset mqtt.bind_address 0.339 s Call Tedge Config List
set/unset mqtt.port 0.439 s Call Tedge Config List
set/unset tmp.path 0.336 s Call Tedge Config List
set/unset logs.path 0.285 s Call Tedge Config List
set/unset run.path 0.307 s Call Tedge Config List
Get Put Delete 3.2 s Http File Transfer Api
Set keys should return value on stdout 0.1 s Tedge Config Get
Unset keys should not return anything on stdout and warnings on stderr 0.178 s Tedge Config Get
Invalid keys should not return anything on stdout and warnings on stderr 0.17 s Tedge Config Get
Set configuration via environment variables 0.757 s Tedge Config Get
Set unknown configuration via environment variables 0.082 s Tedge Config Get

@Bravo555 Bravo555 temporarily deployed to Test Pull Request March 30, 2023 16:08 — with GitHub Actions Inactive
@didier-wenzek
Copy link
Contributor

didier-wenzek commented Mar 30, 2023

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.
(more about it here)

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>
Copy link
Contributor

@didier-wenzek didier-wenzek left a 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"
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@Bravo555 Bravo555 temporarily deployed to Test Pull Request March 30, 2023 16:29 — with GitHub Actions Inactive
@didier-wenzek didier-wenzek merged commit 6fd2386 into thin-edge:main Mar 30, 2023
@Bravo555 Bravo555 deleted the error-refactor branch June 12, 2023 15:09
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.

None yet

2 participants