Fix: ticktick tasks update fails with Cannot read properties of undefined (reading 'id')#13
Open
leo-ashton wants to merge 3 commits into
Open
Fix: ticktick tasks update fails with Cannot read properties of undefined (reading 'id')#13leo-ashton wants to merge 3 commits into
ticktick tasks update fails with Cannot read properties of undefined (reading 'id')#13leo-ashton wants to merge 3 commits into
Conversation
- Add projectId extraction from options in tasks.update() - Pass --project option from CLI to tasks.update() - Add null guards in resolveTaskId for data.tasks and array elements
due() signature is (days, options, deps). Tests were passing mock deps as the options argument, causing real API calls.
- Add data && data.tasks null guards in resolveTaskId - Add projects || [] guard for API response - Handle 204 empty response in update() - API returns no body on success
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #5
Root Cause
Three issues:
updatecommand lacked--projectoption — unlikecompleteanddeletewhich take<projectId> <taskId>, theupdateCLI handler only accepted<taskId>and never passed a project ID to the library function.resolveTaskIdcalled withnullprojectId — without a project ID,resolveTaskIdfell back to iterating all user projects. If any project returned a response with null/undefined task entries,t.idwould throw.TickTick update API returns 204 No Content — the
update()function assumed the API would return the updated task object, but the TickTick API returns 204 with empty body on success. This causedtask.idto crash even whenresolveTaskIdworked correctly.Changes
lib/tasks.js:134update()extractsprojectIdfromoptionsand passes it toresolveTaskIdinstead ofnulllib/tasks.js:469,484resolveTaskIdadds null guards:(data && data.tasks || []).find((t) => t && t.id && t.id.startsWith(taskId))lib/tasks.js:486resolveTaskIdguards against nullprojectsarray from APIlib/tasks.js:148-159update()handles 204 No Content — returns minimal task info when API response is emptybin/ticktick.js:202--projectoption through totasks.update()test/tasks.test.jstasks.duetest calls —due(days, options, deps)signature was receiving mock deps asoptions, causing real API callsUsage
The
--projectoption is optional. When provided,resolveTaskIdsearches only that project (fast path). When omitted, it falls back to the full-project search with null guards.