Skip to content

Add note edit command - #150

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

Add note edit command#150
kl1874 wants to merge 8 commits into
mate-academy:mainfrom
kl1874:review-me

Conversation

@kl1874

@kl1874 kl1874 commented Aug 27, 2026

Copy link
Copy Markdown

What changed

Adds a notes edit <id> <text> command backed by a new store.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. edit lets you update a note's text in place.

@kl1874

kl1874 commented Aug 27, 2026

Copy link
Copy Markdown
Author

Review

Bug: lib/store.js:50-51edit(id, text) does data.notes.find(...) then note.text = text with no check that find actually returned a note. Any id that doesn't exist (or a non-numeric id, since Number("abc") is NaN and never matches) crashes the process with an uncaught TypeError, unlike remove(), which returns false on a miss instead of throwing. Repro: notes edit 99 hello on an empty/short note list.

Edge case: edit has no guard for empty text (unlike add, which checks if (!text)), so notes edit 1 silently blanks a note.

Test gap: no test covers edit, so this crash wouldn't be caught by CI.

Risk: low blast radius, but the crash makes edit one typo away from an unhandled exception for any user — worth fixing before merge (e.g. return false/no-op when the note isn't found, mirroring remove).

@kl1874

kl1874 commented Aug 27, 2026

Copy link
Copy Markdown
Author

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.

@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 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.js edit: guard against missing note before dereferencing note.text and return status or throw a clear error; ensure notes.js checks 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

  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 +51
function edit(id, text) {
const data = load();
const note = data.notes.find((n) => n.id === id);
note.text = text;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment thread notes.js
Comment on lines 49 to 51
case "delete": {
const id = Number(rest[0]);
const ok = store.remove(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.

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.

Comment thread notes.js
Comment on lines 40 to 41
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.

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 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

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! ✨

Footnotes

  1. Rate AI review example

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.

4 participants