Skip to content

Fix: ticktick tasks update fails with Cannot read properties of undefined (reading 'id')#13

Open
leo-ashton wants to merge 3 commits into
kvanland:mainfrom
leo-ashton:main
Open

Fix: ticktick tasks update fails with Cannot read properties of undefined (reading 'id')#13
leo-ashton wants to merge 3 commits into
kvanland:mainfrom
leo-ashton:main

Conversation

@leo-ashton

Copy link
Copy Markdown

Closes #5

Root Cause

Three issues:

  1. update command lacked --project option — unlike complete and delete which take <projectId> <taskId>, the update CLI handler only accepted <taskId> and never passed a project ID to the library function.

  2. resolveTaskId called with null projectId — without a project ID, resolveTaskId fell back to iterating all user projects. If any project returned a response with null/undefined task entries, t.id would throw.

  3. 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 caused task.id to crash even when resolveTaskId worked correctly.

Changes

File Change
lib/tasks.js:134 update() extracts projectId from options and passes it to resolveTaskId instead of null
lib/tasks.js:469,484 resolveTaskId adds null guards: (data && data.tasks || []).find((t) => t && t.id && t.id.startsWith(taskId))
lib/tasks.js:486 resolveTaskId guards against null projects array from API
lib/tasks.js:148-159 update() handles 204 No Content — returns minimal task info when API response is empty
bin/ticktick.js:202 CLI passes --project option through to tasks.update()
test/tasks.test.js Fix tasks.due test calls — due(days, options, deps) signature was receiving mock deps as options, causing real API calls

Usage

# Without --project (works, searches all projects)
ticktick tasks update TASK_ID --title "New Title"

# With --project (faster, searches only that project)
ticktick tasks update TASK_ID --project PROJECT_ID --title "New Title"

The --project option is optional. When provided, resolveTaskId searches only that project (fast path). When omitted, it falls back to the full-project search with null guards.

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

Bug: ticktick tasks update fails with Cannot read properties of undefined (reading 'id')

1 participant