Add edit command - #167
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Your implementation has a critical bug in lib/store.js at line 51. When data.notes.find() doesn't locate a note with the given ID, it returns undefined, and then note.text = text throws a TypeError that crashes the app. You need to add a null check before modifying the note—either check if note exists before setting note.text, or return a boolean indicating success/failure. Additionally, notes.js doesn't validate that the edit command receives an ID argument; if a user runs node notes.js edit without an ID, rest[0] will be undefined and Number(undefined) will be NaN, triggering the same crash. The delete command handles missing notes gracefully with "No note #X found"—your edit command should do the same instead of crashing.
✨ 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: If no note has the given id, find() returns undefined, and note.text = text throws TypeError: Cannot set property 'text' of undefined. Add a null check before modifying the note.
store.edit() now returns false instead of throwing when no note matches the id, and notes.js reports "No note #<id> found" like delete already does. edit also now requires non-empty text, matching the validation add already has.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Your solution is approved. The critical bug in lib/store.js has been successfully fixed—the edit function now properly checks if a note exists before attempting to modify it, returning false gracefully instead of crashing with a TypeError. Similarly, notes.js now displays the appropriate "No note #X found" message when the edit fails, matching the behavior of the delete command. All required features are implemented and working correctly, including the new edit command with proper edge case handling. Great work addressing the previous review feedback.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
PR for Lesson 4 review exercise (from my fork). Adds a notes edit command.