Skip to content

Add edit command to notes CLI - #160

Open
ktroch wants to merge 7 commits into
mate-academy:mainfrom
ktroch:review-me
Open

Add edit command to notes CLI#160
ktroch wants to merge 7 commits into
mate-academy:mainfrom
ktroch:review-me

Conversation

@ktroch

@ktroch ktroch commented Aug 30, 2026

Copy link
Copy Markdown

Practice PR for Lesson 4 — review this branch for bugs, edge cases, and anything risky.

@ktroch ktroch left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Revisión automática (Claude Code) — bugs, edge cases y riesgos:

  1. Bug (lib/store.js:50): edit() busca la nota con .find() pero nunca comprueba si existe antes de escribir note.text = text. Editar un id inexistente (o inválido, ej. notes edit abc hiNumber("abc") es NaN) lanza un TypeError: Cannot set properties of undefined y crashea el CLI. A diferencia de remove(), que maneja el caso "no encontrado" con gracia devolviendo false.
  2. Edge case (notes.js:44): el comando edit no valida texto vacío antes de llamar a store.edit, a diferencia de add. notes edit 3 (sin texto) sobreescribe la nota #3 con "" sin aviso.
  3. Cobertura de tests: tests/notes.test.js solo cubre matches; no hay ningún test para store.edit, así que npm test/CI no detecta el crash del punto 1.
  4. Riesgo de mantenimiento: edit() duplica el patrón load/find/save de remove() pero sin su misma convención de manejo de "no encontrado", lo que facilita que el próximo comando mutador repita el mismo bug.

@ktroch

ktroch commented Aug 30, 2026

Copy link
Copy Markdown
Author

Claude sí detectó el bug plantado: en lib/store.js, edit() no valida si la nota existe antes de escribirle (note.text = text), por lo que editar un id inexistente o inválido lanza un TypeError sin manejar y crashea el CLI, a diferencia de remove() que sí lo maneja con gracia.

@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 notes CLI tool implements all required functionality correctly - add, list, search, and delete commands all work as specified. The bug in the edit function (accessing properties on undefined when a note isn't found) is a legitimate runtime error, but since edit is not part of the required checklist items, it doesn't block approval. The core requirements are met. For improvement: consider adding a null check in store.edit() before accessing note.text, and validating the id is a number before calling the edit function. The search being case-sensitive is a minor UX consideration but not a blocker.


✨ 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 +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.

Bug here: If data.notes.find() returns undefined (no note with this id exists), then note.text = text will throw a TypeError. Need to check if note exists before trying to modify it.

Comment thread notes.js
Comment on lines +48 to 50
}
case "delete": {
const id = Number(rest[0]);

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() doesn't find a note with the given id, note will be undefined. Trying to set note.text = text on the next line will throw a TypeError: 'Cannot set property 'text' of undefined'. Add a null check or early return when the note isn't found.

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