Skip to content

Review Me: Added edit command - #165

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

Review Me: Added edit command#165
emay2026 wants to merge 8 commits into
mate-academy:mainfrom
emay2026:review-me

Conversation

@emay2026

Copy link
Copy Markdown

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.

@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

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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment thread notes.js
Comment on lines +48 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.

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.

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.

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

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