-
Notifications
You must be signed in to change notification settings - Fork 150
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
Fix: Self heal out of range segments, fixup internal error calls #805
Conversation
Harden segment handling for our of range, self heal
WalkthroughThe recent updates encompass improvements in error handling and logging throughout various API endpoints and internal functions. Notable changes involve refactoring the Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
for more information, see https://pre-commit.ci
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.
Review Status
Actionable comments generated: 1
Configuration used: CodeRabbit UI
Files selected for processing (8)
- ledfx/api/config.py (2 hunks)
- ledfx/api/device.py (2 hunks)
- ledfx/api/find_launchpad.py (1 hunks)
- ledfx/api/get_nanoleaf_token.py (1 hunks)
- ledfx/api/virtual.py (2 hunks)
- ledfx/api/virtual_effects.py (2 hunks)
- ledfx/api/virtual_presets.py (1 hunks)
- ledfx/virtuals.py (1 hunks)
Additional comments: 12
ledfx/api/find_launchpad.py (1)
- 28-28: The change correctly swaps the order of arguments in the
internal_error
call to align with the expected function signature. This is part of the broader effort to fix error message handling across the API.ledfx/api/get_nanoleaf_token.py (2)
- 61-61: The change correctly swaps the order of arguments in the
internal_error
call to align with the expected function signature. This is part of the broader effort to fix error message handling across the API.- 68-68: The change correctly swaps the order of arguments in the
internal_error
call to align with the expected function signature. This is part of the broader effort to fix error message handling across the API.ledfx/api/device.py (2)
- 68-68: The change correctly swaps the order of arguments in the
internal_error
call to align with the expected function signature. This is part of the broader effort to fix error message handling across the API.- 128-128: The change correctly swaps the order of arguments in the
internal_error
call to align with the expected function signature. This is part of the broader effort to fix error message handling across the API.ledfx/api/virtual.py (2)
- 77-77: The change correctly swaps the order of arguments in the
internal_error
call to align with the expected function signature. This is part of the broader effort to fix error message handling across the API.- 124-124: The change correctly swaps the order of arguments in the
internal_error
call to align with the expected function signature. This is part of the broader effort to fix error message handling across the API.ledfx/api/virtual_presets.py (1)
- 139-139: The change correctly swaps the order of arguments in the
internal_error
call to align with the expected function signature. This is part of the broader effort to fix error message handling across the API.ledfx/api/config.py (2)
- 131-133: The changes in the exception handling for config migration improve error logging and message handling. Using
internal_error
with a detailed message enhances the clarity of migration failures, aligning with the PR's objectives to improve error handling.- 170-170: The use of
internal_error
here with a detailed error message for configuration loading issues is consistent with the PR's goal of improving error handling across the API.ledfx/api/virtual_effects.py (2)
- 151-151: The correction of the argument order in the
internal_error
call within theput
method aligns with the PR objectives to fix the widespread issue of reversed parameters. This change ensures that the error message and payload type are correctly passed, improving error handling and user feedback.- 260-260: Similarly, the adjustment of the argument order in the
internal_error
call within thepost
method is consistent with the PR's goal to correct the parameter reversal issue. This modification enhances the clarity and accuracy of error messages presented to the user.
ledfx/virtuals.py
Outdated
start_pixel < 0 | ||
or end_pixel < 0 | ||
or start_pixel > end_pixel | ||
or start_pixel >= device.pixel_count | ||
or end_pixel >= device.pixel_count | ||
): | ||
msg = f"Invalid segment pixels in Virtual '{self.name}': segment('{device.name}' ({start_pixel}, {end_pixel})) valid pixels between (0, {device.pixel_count - 1})" | ||
valid = False | ||
_LOGGER.warning(f"Invalid segment pixels in Virtual '{self.name}': segment('{device.name}' ({start_pixel}, {end_pixel})) valid pixels between (0, {device.pixel_count - 1})") | ||
if start_pixel < 0: | ||
start_pixel = 0 | ||
if end_pixel < 0: | ||
end_pixel = 0 | ||
if start_pixel > end_pixel: | ||
start_pixel = end_pixel | ||
if start_pixel >= device.pixel_count: | ||
start_pixel = device.pixel_count - 1 | ||
if end_pixel >= device.pixel_count: | ||
end_pixel = device.pixel_count - 1 | ||
segment = [device_id, start_pixel, end_pixel, invert] | ||
_LOGGER.warning(f"Fixed to {segment}") |
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.
The implementation of the self-healing mechanism in the validate_segment
method correctly adjusts invalid segment pixel values to fall within acceptable limits. This change enhances the robustness of segment handling by ensuring that segments based on a reduced pixel count are corrected. However, there are a few points to consider for improvement:
-
Performance: The method performs multiple checks and adjustments on the segment pixel values. While necessary, it's important to ensure that these operations do not significantly impact the performance, especially when dealing with a large number of segments. Consider benchmarking this method with various segment configurations to assess its performance impact.
-
Maintainability: The method now handles more logic related to segment validation and adjustment. Ensure that this complexity does not hinder future maintenance or enhancements. Adding more detailed comments explaining the rationale behind each adjustment can aid in maintainability.
-
Error Handling: The method raises a
ValueError
if the segment format is invalid or the device ID does not exist. While this is appropriate, ensure that upstream code that callsvalidate_segment
properly handles these exceptions to prevent unhandled errors from propagating and affecting the software's stability. -
Logging: The method logs warnings when adjusting invalid segment values. This is useful for debugging and monitoring, but consider the verbosity level of these logs. In a scenario with many invalid segments, excessive logging could clutter the log files. It might be beneficial to provide a way to control the verbosity of these warnings.
Overall, the changes align with the PR's objectives and improve the software's reliability. However, considering the points above can further enhance the quality of this implementation.
Consider the following improvements:
- Benchmark the method with various segment configurations to assess and optimize performance.
- Enhance maintainability by adding detailed comments explaining the logic behind each adjustment.
- Ensure upstream code properly handles exceptions raised by this method.
- Provide a way to control the verbosity of logging for segment adjustments.
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- ledfx/virtuals.py (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- ledfx/virtuals.py
Harden segment handling for our of range, self heal
as per #799
now any bad values are forced to within limits.
Should address a population of such in sentry. This is currently the only scenario I can find to reach such bad segments
Seen to fix an intentional bad segment generated by reducing pixel count on a device against which a segment is based
Changes reach persisted config through natural cycles
All calls to internal_error had reversed params, causing a BAD SNACKBAR error on front end. Now they are fixed and the correct payload type / message is returned, front end needs to correctly display such...
Summary by CodeRabbit