Review Me: Added edit command - #165
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Your implementation contains a critical bug in lib/store.js (lines 48-52). The edit function doesn't handle the case when a note with the given ID doesn't exist. When data.notes.find() returns undefined, the subsequent line note.text = text throws a TypeError: Cannot set property 'text' of undefined, crashing the application. Unlike your remove() function which properly validates before modifying data, edit has no guard clause. Add a null check after the find: if (!note) return false; before attempting to set note.text. This is a blocker that must be fixed before approval.
✨ 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
| } | ||
| case "delete": { | ||
| const id = Number(rest[0]); | ||
| const ok = store.remove(id); |
There was a problem hiding this comment.
Bug: No null check before accessing note.text. If find() returns undefined (note with given ID doesn't exist), this throws TypeError: Cannot set property 'text' of undefined. Add a null check: if (!note) return false; after the find, or check in notes.js before calling edit.
| 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.
If find() doesn't match any note, note is undefined. Setting note.text will throw a TypeError. Consider adding a check: if note doesn't exist, handle gracefully (return false, throw, or create the note).
This PR adds the ability to edit existing notes. I have reviewed the code and identified a potential crash when the note ID is not found.