fix: Resolve #1525 - Fix: agent creation limit conflict swallowing and standardize endpoint exception mapping#1527
Conversation
Signed-off-by: washim0988-art <islowashin@gmail.com>
📝 WalkthroughWalkthroughAdds FastAPI exception mapping for domain and unexpected failures, implements agent CRUD-like helpers, and wraps a session flow that creates, retrieves, lists, and deletes an agent. ChangesAgent error handling
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✨ 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: 2
🧹 Nitpick comments (1)
fix_1525.py (1)
21-24: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueRemove redundant exception handlers.
Since
map_error_to_http_exceptioninternally evaluates the exception type and processes bothAgentErrorand genericExceptiontypes, catching them separately to perform identical logic is unnecessary.♻️ Proposed refactor
- except AgentError as e: - raise map_error_to_http_exception(e) except Exception as e: raise map_error_to_http_exception(e)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@fix_1525.py` around lines 21 - 24, In the exception-handling flow around map_error_to_http_exception, remove the separate AgentError and generic Exception handlers and replace them with one Exception handler that passes the caught exception to map_error_to_http_exception. Preserve the existing exception mapping and re-raise behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@fix_1525.py`:
- Around line 7-13: Update map_error_to_http_exception to reuse the existing
mapper from memanto/app/utils/errors.py, or add an HTTPException passthrough
before the AgentError and generic Exception checks so existing status codes,
including 409 Conflict, are preserved.
- Around line 44-52: The sessions function double-maps exceptions because
create_agent, get_agent, list_agents, and delete_agent already raise
HTTPException; remove its broad map_error_to_http_exception handling and let
those HTTP exceptions propagate unchanged.
---
Nitpick comments:
In `@fix_1525.py`:
- Around line 21-24: In the exception-handling flow around
map_error_to_http_exception, remove the separate AgentError and generic
Exception handlers and replace them with one Exception handler that passes the
caught exception to map_error_to_http_exception. Preserve the existing exception
mapping and re-raise behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
Refactor error handling in agent functions to preserve HTTPException status codes and simplify agent creation logic.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
fix_1525.py (1)
6-17: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueSimplify fallback logic and remove dead code.
Since this mapper is called after catching
Exception(e.g., insessions()),excwill always be an instance ofException. Theelseblock mapping to "Unknown Error" is unreachable.You can simplify the function by removing the redundant
isinstancecheck and the deadelseblock, leaving a clean, unconditional fallback for unexpected errors.♻️ Proposed refactor
def map_error_to_http_exception(exc): # 1. Add passthrough for HTTPException to prevent overriding status codes if isinstance(exc, HTTPException): return exc # 2. Handle domain-specific errors if isinstance(exc, AgentError): return HTTPException(status_code=status.HTTP_409_CONFLICT, detail=str(exc)) - # 3. Fallback for unexpected failures - elif isinstance(exc, Exception): - return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail="Internal Server Error") - else: - return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail="Unknown Error") + # 3. Fallback for unexpected failures + return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail="Internal Server Error")🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@fix_1525.py` around lines 6 - 17, Update map_error_to_http_exception to keep the HTTPException passthrough and AgentError mapping, then replace the redundant Exception check and unreachable else branch with an unconditional 500 Internal Server Error fallback for all remaining exceptions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@fix_1525.py`:
- Around line 6-17: Update map_error_to_http_exception to keep the HTTPException
passthrough and AgentError mapping, then replace the redundant Exception check
and unreachable else branch with an unconditional 500 Internal Server Error
fallback for all remaining exceptions.
|
Thanks for your contributions! We're closing this PR as this is a duplicate. |
Resolves #1525
Built autonomously by Cloud Agent.
Bounty payout address: Gq46qirFLJY3qptAWkAmAeDfGVAE4MYYGTcRmpKjsyR
Summary by CodeRabbit
New Features
Bug Fixes