refactor: extract firmware check logic into a dedicated helper method to reduce duplication#527
refactor: extract firmware check logic into a dedicated helper method to reduce duplication#527
Conversation
… to reduce duplication
📝 WalkthroughWalkthroughRefactors OpenEVSE.firmware_check to extract session-based HTTP logic into a new private helper Changes
Sequence Diagram(s)sequenceDiagram
participant OpenEVSE as OpenEVSE
participant Session as aiohttp.ClientSession
participant GitHub as GitHub API
OpenEVSE->>Session: _firmware_check_with_session(url, method)
Session->>GitHub: HTTP GET /releases/latest
GitHub-->>Session: HTTP 200 + JSON payload
Session-->>OpenEVSE: parsed JSON (dict) or error
alt parsed dict
OpenEVSE->>OpenEVSE: build {latest_version, release_notes, release_url}
else JSON decode / type error / connector error
OpenEVSE->>OpenEVSE: return None or {}
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@openevsehttp/__main__.py`:
- Around line 624-629: Wrap the JSON parsing and key access in a defensive
try/except: when calling json.loads(message) (variable message) catch
json.JSONDecodeError and handle by logging and returning an empty/neutral
response; likewise either use message.get("tag_name"), message.get("body"),
message.get("html_url") or catch KeyError around the dict accesses that populate
response["latest_version"], response["release_notes"], response["release_url"]
so unexpected response shapes don't raise—make the helper return a safe response
(e.g., empty dict or keys set to None) that the existing firmware_check
try/except and the pattern used in _process_request_with_session can handle.
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
openevsehttp/__main__.py (1)
625-629: Preserve traceback for JSON parse failures.At Line 628, using
_LOGGER.exception(...)instead of_LOGGER.error(...)keeps stack context for easier debugging.Proposed tweak
try: message = json.loads(message) except json.JSONDecodeError: - _LOGGER.error("Failed to parse JSON response: %s", message) + _LOGGER.exception("Failed to parse JSON response: %s", message) return None🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@openevsehttp/__main__.py` around lines 625 - 629, The except block catching json.JSONDecodeError around the json.loads(...) call should log the failure with the traceback; replace the call to _LOGGER.error(...) with _LOGGER.exception(...) so the exception stack context is preserved while still including the original message content, i.e., update the JSON decoding error handling in the try/except that surrounds json.loads(message) to call _LOGGER.exception("Failed to parse JSON response: %s", message) before returning None.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@openevsehttp/__main__.py`:
- Around line 625-629: The except block catching json.JSONDecodeError around the
json.loads(...) call should log the failure with the traceback; replace the call
to _LOGGER.error(...) with _LOGGER.exception(...) so the exception stack context
is preserved while still including the original message content, i.e., update
the JSON decoding error handling in the try/except that surrounds
json.loads(message) to call _LOGGER.exception("Failed to parse JSON response:
%s", message) before returning None.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: f580b12b-645e-48b5-b1c6-6b68681af49b
📒 Files selected for processing (2)
openevsehttp/__main__.pytests/test_main.py
Summary by CodeRabbit