fix: Handle EntityCreationError as conflict - #541
Conversation
Signed-off-by: phernandez <paul@basicmachines.co>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ba29d52036
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| @app.exception_handler(EntityCreationError) | ||
| async def entity_creation_error_handler(request, exc): # pragma: no cover | ||
| """Handle entity creation conflicts (e.g., file already exists). | ||
|
|
||
| This is expected behavior when users try to create notes that exist, | ||
| so log at INFO level instead of ERROR. | ||
| """ | ||
| logger.info( | ||
| "Entity already exists", | ||
| url=str(request.url), | ||
| method=request.method, | ||
| path=request.url.path, | ||
| error=str(exc), | ||
| ) | ||
| return await http_exception_handler( | ||
| request, | ||
| HTTPException( | ||
| status_code=409, | ||
| detail="Note already exists. Use edit_note to modify it, or delete it first.", | ||
| ), |
There was a problem hiding this comment.
Return 409 only for actual conflicts
This handler treats every EntityCreationError as an “already exists” conflict, but EntityCreationError is also raised for non-conflict failures (e.g., create_entity_from_markdown wraps any upsert_entity exception into EntityCreationError). In those cases clients will now receive a 409 with a misleading “Note already exists” message instead of a 500, and logs will be INFO, which can mask real storage or database failures. Consider narrowing this to only the file-exists case (e.g., a specific exception subtype) or preserving the original error status for unexpected creation failures.
Useful? React with 👍 / 👎.
Signed-off-by: phernandez <paul@basicmachines.co>
|
Claude finished @phernandez's task in 2m 12s —— View job Reviewing PR #541: Handle EntityCreationError as conflict Todo List
SummaryThis PR improves error handling for entity creation conflicts: Commit 1 (ba29d52):
Commit 2 (718ba6c):
Review Against Team Checklist✅ Code Quality & Standards
✅ Testing & Documentation
✅ Basic Memory Architecture
✅ Security & Performance
✅ Compatibility
Critical Issue: Codex Concern is Valid
|
Signed-off-by: phernandez <paul@basicmachines.co>

Summary\n- log EntityCreationError at INFO and return 409 conflict\n- include friendly detail message for existing notes\n- include formatting fix in tests\n\n## Testing\n- not run (not requested)