fix: narrow bare except to specific json exceptions in mcp_integration (F23)#6362
fix: narrow bare except to specific json exceptions in mcp_integration (F23)#6362waefrebeorn wants to merge 1 commit into
Conversation
…n (F23) - Changed 'except Exception: pass' to 'except (json.JSONDecodeError, AttributeError, TypeError):' with explanatory comment - Intentional fallback: if HTTP response body isn't parseable JSON, use generic error string from the exception Closes F23 — rent_a_relic/mcp_integration.py bare pass gap
shadow88sky
left a comment
There was a problem hiding this comment.
Reviewed tools/rent_a_relic/mcp_integration.py for PR #6362.
The PR replaces the previous broad except Exception: pass around HTTP error-body parsing with a narrower fallback for JSON/shape issues. That keeps the existing behavior of returning a generic error string when the response body cannot provide an error field, while avoiding suppression of unrelated failures.
I also checked the helper path: _response_json_object() already handles invalid JSON by logging and returning {}, and non-object JSON similarly falls back to {}. The new outer handler is therefore conservative/redundant for JSONDecodeError, but it does not change the successful or fallback response contract.
Validation performed:
- GitHub PR checks are passing
git diff --check $(git merge-base HEAD origin/main)..HEADpassed.venv/bin/python -m py_compile tools/rent_a_relic/mcp_integration.pypassedPYTHONPATH=. PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 .venv/bin/python -m pytest tests/test_rent_a_relic_mcp_integration.py -q-> 9 passedPYTHONPATH=. PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 .venv/bin/python -m pytest tests/test_rent_a_relic_mcp_integration.py tests/test_rent_a_relic.py -qcould not collect the broader suite in this local environment becausecryptographyis not installed
I received RTC compensation for this review.
jaxint
left a comment
There was a problem hiding this comment.
Great work! Thanks for contributing to RustChain! 🦀
PR Review — #6362 Narrow Bare Except to Specific JSON ExceptionsReviewed: What this PR doesReplaces a bare Technical observationsGood:
Minor note: Conclusion: Correct exception narrowing. The specific exceptions match the specific failure modes of the code, and the change preserves the original graceful error-handling behavior. I received RTC compensation for this review. |
jaxint
left a comment
There was a problem hiding this comment.
Great work! Thanks for contributing to RustChain! 🦀
jaxint
left a comment
There was a problem hiding this comment.
Thanks for this contribution! 🎉
jaxint
left a comment
There was a problem hiding this comment.
Thanks for this contribution! 🎉
jaxint
left a comment
There was a problem hiding this comment.
Thanks for this contribution! 🎉
jaxint
left a comment
There was a problem hiding this comment.
Thanks for this contribution! The code looks well-structured and follows good practices. Appreciate the effort put into this PR.
jaxint
left a comment
There was a problem hiding this comment.
Thanks for this contribution! The code looks well-structured.
Clean replacement for #6331. Single commit, no unrelated files, no p2p.py regression.
RTC Wallet:
RTC17c0d21f04f6f65c1a85c0aeb5d4a305d57531096