fix: On adding notes server error message#1498
Conversation
|
""" WalkthroughThe changes introduce improved error handling in the Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant NotesManager
participant ZeroDB
participant Database
Client->>NotesManager: createNote(payload, userId)
NotesManager->>ZeroDB: createNote(payload, userId)
ZeroDB->>Database: INSERT note (with .returning())
Database-->>ZeroDB: Inserted note record(s)
ZeroDB-->>NotesManager: Inserted note record(s)
NotesManager-->>Client: Created note or error (with logging)
Possibly related PRs
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
apps/server/src/lib/notes-manager.ts(1 hunks)apps/server/src/main.ts(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
apps/server/src/lib/notes-manager.ts (1)
apps/server/src/lib/server-utils.ts (1)
getZeroDB(7-11)
🔇 Additional comments (1)
apps/server/src/main.ts (1)
234-234: LGTM! Core fix for the server error issue.Adding
.returning()to the insert operation ensures that the inserted note record is returned, addressing the root cause where Drizzle ORM's default behavior of not returning data was causing false server errors.
Description
While adding notes, a server error message appears even though the note is successfully inserted into the database.
The root cause is related to Drizzle ORM by default, it does not return any data after an insert operation unless the .returning() method is explicitly used.
Without .returning(), the insert query executes correctly, but returns undefined or an empty array. This causes the backend logic (which expects a returned value for validation or response) to throw an error, leading to a false server error message.
Adding .returning() to the insert statement resolves the issue by returning the inserted record’s metadata, which can then be used to confirm successful insertion and send a proper response.
Type of Change
Please delete options that are not relevant.
Areas Affected
Please check all that apply:
Testing Done
Describe the tests you've done:
Security Considerations
For changes involving data or authentication:
Checklist
Additional Notes
Add any other context about the pull request here.
Screenshots/Recordings
Add screenshots or recordings here if applicable.
By submitting this pull request, I confirm that my contribution is made under the terms of the project's license.
Summary by CodeRabbit
Bug Fixes
New Features