Add edit command to notes CLI - #160
Conversation
ktroch
left a comment
There was a problem hiding this comment.
Revisión automática (Claude Code) — bugs, edge cases y riesgos:
- Bug (lib/store.js:50):
edit()busca la nota con.find()pero nunca comprueba si existe antes de escribirnote.text = text. Editar un id inexistente (o inválido, ej.notes edit abc hi→Number("abc")es NaN) lanza unTypeError: Cannot set properties of undefinedy crashea el CLI. A diferencia deremove(), que maneja el caso "no encontrado" con gracia devolviendofalse. - Edge case (notes.js:44): el comando
editno valida texto vacío antes de llamar astore.edit, a diferencia deadd.notes edit 3(sin texto) sobreescribe la nota #3 con""sin aviso. - Cobertura de tests:
tests/notes.test.jssolo cubrematches; no hay ningún test parastore.edit, así quenpm test/CI no detecta el crash del punto 1. - Riesgo de mantenimiento:
edit()duplica el patrón load/find/save deremove()pero sin su misma convención de manejo de "no encontrado", lo que facilita que el próximo comando mutador repita el mismo bug.
|
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
left a comment
There was a problem hiding this comment.
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
| 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.
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.
| } | ||
| case "delete": { | ||
| const id = Number(rest[0]); |
There was a problem hiding this comment.
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.
Practice PR for Lesson 4 — review this branch for bugs, edge cases, and anything risky.