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

[miio] Elimate several SAT warnings #9289

Merged
merged 9 commits into from Dec 12, 2020
Merged

Conversation

marcelrv
Copy link
Contributor

@marcelrv marcelrv commented Dec 8, 2020

eliminating sat warnings and minor improvements in the miloudconnector for failed attempts

Signed-off-by: Marcel Verpaalen <marcel@verpaalen.com>
Signed-off-by: Marcel Verpaalen <marcel@verpaalen.com>
Signed-off-by: Marcel Verpaalen <marcel@verpaalen.com>
Signed-off-by: Marcel Verpaalen <marcel@verpaalen.com>
@marcelrv marcelrv added the bug An unexpected problem or unintended behavior of an add-on label Dec 8, 2020
@marcelrv
Copy link
Contributor Author

marcelrv commented Dec 8, 2020

Builderror in Jenkins unrelated to the PR

Signed-off-by: Marcel Verpaalen <marcel@verpaalen.com>
Signed-off-by: Marcel Verpaalen <marcel@verpaalen.com>
@marcelrv marcelrv added rebuild Triggers Jenkins PR build and removed rebuild Triggers Jenkins PR build labels Dec 8, 2020
Signed-off-by: Marcel Verpaalen <marcel@verpaalen.com>
@marcelrv marcelrv added rebuild Triggers Jenkins PR build and removed rebuild Triggers Jenkins PR build labels Dec 11, 2020
Comment on lines 652 to 653
cmdResponse.get(0).isJsonPrimitive() ? cmdResponse.get(0)
: new JsonPrimitive(cmdResponse.get(0).toString()));
Copy link
Contributor

Choose a reason for hiding this comment

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

Please cache cmdResponse.get(0) in a local variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agree. done

}
} else {
errorMsg = "Received message is invalid JSON";
} catch (ClassCastException | IllegalStateException e) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What would throw either of these exceptions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

During my testing I had all sorts of garbage responses that came form the Xiaomi cloud. (so invalid json)
Causing exceptions during the reading and processing of the json responses.
At most places I was already catching these, but seems this one not.

return "";
}

} catch (JsonSyntaxException | NullPointerException e) {
} catch (JsonParseException | IllegalStateException | ClassCastException e) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What would throw a ClassCastException or IllegalStateException here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

as before comment, the responses of Xiaomi cloud are many times corrupt.
maybe I'm overly caution here to catch all possible errors that can be thrown in this part of the process.
During my testing for this PR I had some JsonParseException & IllegalStateExceptions in the module, not 100% sure anymore if it was in this specific step. I may have added it to multiple steps to avoid the same.

@marcelrv
Copy link
Contributor Author

@cpmeister are you okay with the changes implemented, or still something not fine for merging?

@cpmeister
Copy link
Contributor

did you miss my last review?

marcelrv and others added 2 commits December 12, 2020 01:31
Co-authored-by: Connor Petty <mistercpp2000@gmail.com>
Signed-off-by: Marcel Verpaalen <marcel@verpaalen.com>
@marcelrv marcelrv added rebuild Triggers Jenkins PR build and removed rebuild Triggers Jenkins PR build labels Dec 12, 2020
@marcelrv
Copy link
Contributor Author

@cpmeister let me know your thoughts on catching the multiple exceptions.
I understand in OH we don't want to catch Exception (don't quite understand the background of that though, why that needs to be avoided), so basically I'm trying to understand what are all possible exceptions that part of the code can throw and catch them.

I don't want that a exception in the cloud would prevent other parts of the process to stop (e.g. the discovery checks for the device details from the cloud, but if that runs into an exception, I still want the discover to proceed and submit the found device with a less specific details)

@marcelrv
Copy link
Contributor Author

did you miss my last review?

I think we crossed messages.... when I wrote it the review was not in yet, so most likely I wrote is while you were commenting

@cpmeister cpmeister added rebuild Triggers Jenkins PR build and removed rebuild Triggers Jenkins PR build labels Dec 12, 2020
@marcelrv
Copy link
Contributor Author

Jenkins build error unrelated to the binding/PR

@cpmeister cpmeister merged commit 5bfc894 into openhab:main Dec 12, 2020
@cpmeister cpmeister added this to the 3.0.0.RC1 milestone Dec 12, 2020
@marcelrv marcelrv deleted the miio-warnings branch December 14, 2020 08:23
nowaterman pushed a commit to nowaterman/openhab-addons that referenced this pull request Jan 19, 2021
* [miio] eliminate warnings from mapdraw
* [miio] clean warnings from basic handler
* [miio] avoid apache commons warning in utils
* [miio] eliminate warnings from micloudconnector
marcfischerboschio pushed a commit to bosch-io/openhab-addons that referenced this pull request May 5, 2022
* [miio] eliminate warnings from mapdraw
* [miio] clean warnings from basic handler
* [miio] avoid apache commons warning in utils
* [miio] eliminate warnings from micloudconnector

Signed-off-by: Marcel Verpaalen <marcel@verpaalen.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An unexpected problem or unintended behavior of an add-on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants