Improve fallback handling, logging, and add test#22
Improve fallback handling, logging, and add test#22sushantkhemalapure wants to merge 2 commits intoOWASP-BLT:mainfrom
Conversation
📊 Monthly LeaderboardHi @sushantkhemalapure! Here's how you rank for March 2026:
Scoring this month (across OWASP-BLT org): Open PRs (+1 each), Merged PRs (+10), Closed (not merged) (−2), Reviews (+5; first two per PR in-month), Comments (+2, excludes CodeRabbit). Run |
|
👋 Hi @sushantkhemalapure! This pull request needs a peer review before it can be merged. Please request a review from a team member who is not:
Once a valid peer review is submitted, this check will pass automatically. Thank you!
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: OWASP-BLT/coderabbit/.coderabbit.yml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughImproved GitHub integration: added logging, explicit JSON parse/error handling, PR-intent fallback to issue body, safer output path handling using temp directories, UTF-8 file I/O, and a new test validating the issue-body intent fallback. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested labels
🚥 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
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/advisory_engine/github_integration.py (1)
32-41:⚠️ Potential issue | 🟠 MajorHarden payload parsing against file I/O errors and non-object JSON
open()failures (e.g., permissions) and valid-but-non-object JSON still escape this guard and can crash later atevent_data.get(...). This weakens the fault-tolerance goal.🔧 Proposed fix
- try: - with open(self.event_path, 'r', encoding='utf-8') as f: - event_data = json.load(f) - except json.JSONDecodeError: - logger.exception("GitHub event payload is not valid JSON: %s", self.event_path) - return None + try: + with open(self.event_path, 'r', encoding='utf-8') as f: + event_data = json.load(f) + except (OSError, json.JSONDecodeError): + logger.exception("Failed to read/parse GitHub event payload: %s", self.event_path) + return None + + if not isinstance(event_data, dict): + logger.warning("GitHub event payload must be a JSON object: %s", self.event_path) + return None🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/advisory_engine/github_integration.py` around lines 32 - 41, The current payload parsing only catches json.JSONDecodeError but misses file I/O errors and valid-but-non-object JSON; update the try/except around opening and json.load(self.event_path) to also catch FileNotFoundError/OSError (or a broad Exception as e) and log via logger.exception including self.event_path and the error, then return None; after loading, verify event_data is a dict (e.g., check isinstance(event_data, dict)) and if not, logger.error that the payload is not a JSON object for self.event_path and return None before accessing event_data.get(...) for pr and issue.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@test_advisory.py`:
- Line 245: The test output contains a mojibake sequence "✓" in the print
statement that prints success; update the string in the print call in
test_advisory.py (the success message for the GitHub issue-body fallback test)
to use a proper checkmark character (e.g., "✓") or a plain ASCII equivalent like
"OK" so the test output is readable and not mis-encoded.
---
Outside diff comments:
In `@src/advisory_engine/github_integration.py`:
- Around line 32-41: The current payload parsing only catches
json.JSONDecodeError but misses file I/O errors and valid-but-non-object JSON;
update the try/except around opening and json.load(self.event_path) to also
catch FileNotFoundError/OSError (or a broad Exception as e) and log via
logger.exception including self.event_path and the error, then return None;
after loading, verify event_data is a dict (e.g., check isinstance(event_data,
dict)) and if not, logger.error that the payload is not a JSON object for
self.event_path and return None before accessing event_data.get(...) for pr and
issue.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: OWASP-BLT/coderabbit/.coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: b830a560-842d-4857-87b6-4b7dedc2b908
📒 Files selected for processing (2)
src/advisory_engine/github_integration.pytest_advisory.py
|
Hi, I’ve opened a PR addressing part of this issue by improving fallback handling, logging, and adding a test. Would appreciate your feedback. |
|
Hi @coderabbitai, I’ve fixed the encoding issue in the test output. Please take a look. |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 13055
🐛
|
|
@sushantkhemalapure Currently we are restricting PRs on gsoc labelled repos as they are supposed to be worked on gsoc period. Feel free to make PRs in any other repo |
|
@S3DFX-CYBER I’ll look into other repositories to contribute. |
What does this PR do?
This PR improves fault tolerance and observability in the advisory workflow by:
tempfile.gettempdir()Why is this useful?
Changes made
github_integration.pytest_advisory.pyTesting
Related to
Partial contribution towards improving fallback fault tolerance (#4)
Summary by CodeRabbit
Bug Fixes
Tests