-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
Add exception translations to ring integration #136468
Add exception translations to ring integration #136468
Conversation
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.
Exception translations are meant to provide a user-friendly message back to the user on why something went wrong. I think you're mixing up the purpose of that with the desire to capture the technical reason that something failed. Log that instead.
You can also raise the HomeAssistantError
(and derivatives) from an existing exception, which will capture the stack traceback and message in the logs.
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
Hey @andrewsayre, have responded on this, let me know your thoughts. I have assumed the point you're making applies to all the exceptions, and not just the auth one in coordinator, but let me know if I've misunderstood that. |
"message": "Error communicating with Ring API for device {device} - {func}: {exc}" | ||
}, | ||
"sdp_m_line_index_required": { | ||
"message": "The sdp_m_line_index is required for ring webrtc streaming from {device}" |
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.
And what does that mean?
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.
This is re-worded to "Error negotiating stream for {device}"
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.
But like, reading this sounds like something was required, but what does that mean and how does someone get this? Like, I am no expert on camera streams, but if the technical reason is that something is required, that sounds like something that can be provided and then work?
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.
To give Joost some context, the sdp_m_line_index
is the index of the sdp m
config in the WebRTC offer.
The frontend will include it, when sending the candidates to HA. The spec defines that the default value is None
as so it's possible that None
is received
Thanks for your responses, @sdb9696! Yes, that applies to anything that would be user-facing in the UI. 😄 Here's some thoughts on what I'd like to see changed to move this PR forward:
@joostlek any thing you want to change or add to what I said above? :) |
Well if something is truly exceptional, I don't expect it to be easy to reproduce, so I would opt to log with
I believe they are but I don't have any example at hand. But if they didn't they should |
I did some testing and the coordinator error does appear in the UI during setup. I have updated the PR to exclude the technical details from the exception translations and instead use |
This will log the error twice, which should be avoided. I saw that most exceptions will be created with |
There is no stack trace in the log for the base coordinator error. This is the log output from one of the test cases:
The error from the base coordinator just contains the translation information. |
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.
Great job, @sdb9696! Two smaller things to look at and this is good to go!
tests/components/ring/test_init.py
Outdated
assert log_msg not in caplog.text | ||
assert str(error_type) not in caplog.text |
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.
Asserting the negative isn't great because the code could have not ran at all, or the translation strings could have been changed, and this would still pass. 😃
What about checking that the mocked API method was called and the coordinator's last_update_success==True
or last_exception is None
?
Change in the test below too.
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.
Agree with checking the mocked api method was called. Not sure how to get hold of the coordinator in the test though, never done that before.
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.
You should be able to get to it from mock_config_entry.runtime_data.devices_coordinator
. Type the entry to RingConfigEntry
to get type hinting.
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.
Ok cool will try that out tomorrow, thanks!
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.
Asserting the negative isn't great because the code could have not ran at all, or the translation strings could have been changed, and this would still pass. 😃
What about checking that the mocked API method was called and the coordinator's
last_update_success==True
orlast_exception is None
?
Updated both tests to check that the method was called and check the coordinator.last_exception
is correctly set. Have still kept the negative log check as checking last_update_success==True
doesn't work, because the subsequent updates should not be succeeding for this test.
It's currently implemented that on a UpdateFailed Exception, we are only logging the error message. Please see the base implementation of the coordinator to see what is logged on which exception. core/homeassistant/helpers/update_coordinator.py Lines 401 to 406 in 600fe87
core/homeassistant/helpers/update_coordinator.py Lines 441 to 444 in 600fe87
Will put this PR on the agenda of the next core meeting as I don't like to log errors twice. Please keep the PR in draft until I come back with a decision |
imo fwiw, I agree that it would be better to only log once and do |
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 discussed this PR internally and concluded the following:
- the "golden" Rule is log or rethrow. Therefore, we will not accept that the exception is logged before raising. Debug logs are fine if they add additional value/context. Only logging the error on debug level is not required as this will implemented.
- Known/expected exceptions like
AuthenticationError
,Timeout
should not log any stacktrace - I will create a separate PR, where I will update the update coordinator to log stacktrace of
UpdateFailed
on a debug level. So you have the stacktrace available during debugging. - Unknown errors should not be translated and not wrapped in any HA error. Instead they should bubble up, where they than will be logged with the stacktrace
I'm not familiar with the ring lib, so I'm unsure if RingError
is a unexpected/unknown error or it that one will be also raised for expected ones.
Please adopt the PR
That's all done. |
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.
Thanks for making the changes! Just a few smaller items.
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.
Thank you, looks good! I like how much more straightforward this code became! Nice work!
Requested changes implemented; reviewed and approved by other member.
Thanks @andrewsayre ! |
Proposed change
SSIA
Type of change
Additional information
Checklist
ruff format homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
.To help with the load of incoming pull requests: