Skip to content

Add edit command to notes CLI - #175

Open
mikas4444 wants to merge 8 commits into
mate-academy:mainfrom
mikas4444:review-me
Open

Add edit command to notes CLI#175
mikas4444 wants to merge 8 commits into
mate-academy:mainfrom
mikas4444:review-me

Conversation

@mikas4444

Copy link
Copy Markdown

Summary

  • Adds an edit <id> <text> command to notes.js and a corresponding edit() function in lib/store.js
  • Updates README lesson instructions

🤖 Generated with Claude Code

https://claude.ai/code/session_018e1KkK9zigKisgTfjehiLf

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

This solution has critical bugs that cause runtime crashes when editing non-existent notes. In lib/store.js, the edit function (around line 50) doesn't validate that data.notes.find() returns an actual note before attempting to set note.text, which will throw TypeError: Cannot set property 'text' of undefined when the note ID doesn't exist. Additionally, in notes.js, the edit case always prints success ("Updated note #X") without checking if the operation succeeded, unlike the delete command which properly validates and reports "No note #X found" when appropriate. To fix these issues: (1) Add a check in store.edit() to return false or throw a handled error when the note isn't found, and (2) Update notes.js to check the result of store.edit() and display an appropriate error message when the note doesn't exist.


✨ 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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment thread lib/store.js
Comment on lines +48 to +50
function edit(id, text) {
const data = load();
const note = data.notes.find((n) => n.id === id);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If data.notes.find() returns undefined (note doesn't exist), this line will throw "Cannot set property 'text' of undefined". Consider adding a check or returning a value to indicate success/failure.

Comment thread lib/store.js
Comment on lines +39 to +41
// Returns the notes whose text contains `term`.
function matches(notes, term) {
return notes.filter((note) => note.text.includes(term));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider whether search should be case-insensitive. Currently, searching for "milk" won't match "Buy MILK" due to case sensitivity.

Comment thread notes.js
Comment on lines +42 to +47
case "edit": {
const id = Number(rest[0]);
const text = rest.slice(1).join(" ").trim();
store.edit(id, text);
console.log(`Updated note #${id}`);
break;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unlike delete which validates the result with const ok = store.remove(id) and prints an error message if not found, the edit case always prints success. If store.edit() fails or the note doesn't exist, the user still sees 'Updated note #${id}'. Consider checking the result or adding validation.

@mikas4444

Copy link
Copy Markdown
Author

Claude successfully caught the planted bug in edit() — it crashes when the note ID does not exist.

Mikas4444 and others added 2 commits September 3, 2026 18:05
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018e1KkK9zigKisgTfjehiLf
store.edit() now returns false instead of throwing when the id
doesn't match a note, and the CLI reports "No note #id found"
instead of crashing.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018e1KkK9zigKisgTfjehiLf

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

I am approving this submission. The implementation meets the task requirements: the edit flow now correctly validates note existence in lib/store.js (returning false when not found) and notes.js handles that return value to display appropriate errors, matching the behavior of delete. Commands for add/list/search/delete/edit function coherently and the tests cover the important paths.

Minor improvement (non-blocking): consider normalizing id types inside lib/store.js methods like remove and edit by casting id = Number(id) at the start to prevent subtle mismatches if a string id is passed. This increases resilience even though notes.js already converts ids to numbers.

Nice work tightening up the edge cases and keeping the storage API clear and consistent. Keep it up!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

Comment thread lib/store.js
Comment on lines +48 to +50
function edit(id, text) {
const data = load();
const note = data.notes.find((n) => n.id === id);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider normalizing id types in edit as well to avoid subtle mismatches when callers supply string ids. Currently callers in notes.js already convert to Number, so this is optional but increases resilience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants