Add edit command to notes tool - #173
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
The edit function in lib/store.js has a critical bug that needs fixing. When data.notes.find() returns undefined (because the note ID doesn't exist), line 51 attempts to set note.text = text, which throws a TypeError: Cannot set property 'text' of undefined. This crashes the application instead of gracefully handling the error. Unlike remove() which returns a boolean for success/failure, edit() has no null check and returns nothing, making it impossible for callers to distinguish success from failure. To fix this, add a null check after the find() call: if the note isn't found, return false (or throw a descriptive error), and return true on successful edit. Then update the edit case in notes.js to check this return value before printing the success message, so users get proper feedback when trying to edit a non-existent note.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
| function edit(id, text) { | ||
| const data = load(); | ||
| const note = data.notes.find((n) => n.id === id); | ||
| note.text = text; |
There was a problem hiding this comment.
Bug here: If no note has the given id, find() returns undefined. Then line 51 tries to set undefined.text, throwing a TypeError. Consider returning a boolean (like remove() does) or throwing a descriptive error, and handle it in notes.js.
Adds an
edit <id> <text>command plus scaffolding (config, tests, CI, .gitignore). See review notes on the fork PR: Iter1993#1