Add note edit command - #150
Conversation
ReviewBug: Edge case: Test gap: no test covers Risk: low blast radius, but the crash makes |
|
Claude caught the planted bug: edit() crashes with an uncaught TypeError when the note id doesn't exist, since it never checks that find() returned a note before writing note.text. |
# Conflicts: # lib/store.js
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
I am requesting changes because there is a critical blocker that will cause a runtime error when editing a non-existent note. In lib/store.js, within edit(id, text), if data.notes.find(...) returns undefined, the next line note.text = text will throw a TypeError (e.g., on line where note.text is assigned). This violates the requirement for robust CLI behavior and will break functionality when a user attempts to edit an invalid id. Please add a guard: check if (!note) and return a boolean (e.g., false) or throw a clear Error('No note found for id ...'), and update notes.js to handle that return value and print a friendly message instead of always claiming success.
Critical issues to fix:
- In
lib/store.jsedit: guard against missing note before dereferencingnote.textand return status or throw a clear error; ensurenotes.jschecks that status and reports failure appropriately.
Minor improvements (optional):
- Make search/matches case-insensitive by lowercasing both the note text and search term.
- Consider validating edit input in
notes.js(finite id, non-empty text) and ensure consistent id type comparisons.
You’ve implemented most commands well; addressing the edit guard and feedback will make the CLI reliable. Keep up the good work!
✨ 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.
In edit, the code finds a note by id but does not handle the case where no note is found. If note is undefined the next line (note.text = text) will throw. The app calls store.edit from notes.js without validating the id exists, so this should be handled here (or edit should return a value indicating success/failure). Consider checking for note and returning a boolean (or throwing a clear error) when not found.
| case "delete": { | ||
| const id = Number(rest[0]); | ||
| const ok = store.remove(id); |
There was a problem hiding this comment.
In edit(), data.notes.find(...) can return undefined when the id isn't found. The next line note.text = text will throw a TypeError. Add a guard (e.g., if (!note) return false or throw a clear Error) and return a status so callers can report whether the edit succeeded.
| break; | ||
| } |
There was a problem hiding this comment.
Consider making search/matches case-insensitive so notes search foo finds Foo as well — for example compare note.text.toLowerCase().includes(term.toLowerCase()). Not strictly required by the checklist but improves UX.
edit(id, text) dereferenced note.text without checking that find() actually returned a note, so editing a nonexistent (or non-numeric) id crashed the CLI with an uncaught TypeError. edit() now returns a boolean and notes.js reports "No note #<id> found" instead of claiming success unconditionally, mirroring how remove() already behaves. Also validates the id/text before calling store.edit, and makes search/matches case-insensitive so "milk" matches "Milk".
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Here is my approval: You’ve resolved the critical issue correctly. In lib/store.js lines 49-57, the edit function now guards against missing notes with if (!note) { return false; } (line 51) before assigning note.text, preventing the previous TypeError. The matches function (lines 39-42) handles case-insensitive search as expected. In notes.js, you correctly check the boolean return from edit and display a clear message (No note #${id} found) on failure, which aligns with the task requirements. Functionality is intact and meets the core requirements with no blockers. Nice work keeping the implementation clean and user-friendly.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
What changed
Adds a
notes edit <id> <text>command backed by a newstore.edit(id, text)function, alongside supporting config/test/CI scaffolding.Why
Previously the only way to change a note was to delete and re-add it.
editlets you update a note's text in place.