{"record":{"id":"eed0180d8b4cfd19","repo":"jackwener/OpenCLI","slug":"slock-commandname-returned-task-id-taskid-e","errorCode":null,"errorMessage":"Slock ${commandName} returned task id ${taskId}, expected ${expectedId}.","messagePattern":"Slock (.+?) returned task id (.+?), expected (.+?)\\.","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/slock/task-identity.js","lineNumber":9,"sourceCode":"import { CommandExecutionError } from '@jackwener/opencli/errors';\n\nexport function assertTaskIdentity(t, expectedId, commandName) {\n  const taskId = t?.id;\n  if (!taskId) {\n    throw new CommandExecutionError(`Slock ${commandName} succeeded without returning task id ${expectedId}; refusing to report a task row.`);\n  }\n  if (taskId !== expectedId) {\n    throw new CommandExecutionError(`Slock ${commandName} returned task id ${taskId}, expected ${expectedId}.`);\n  }\n  return taskId;\n}\n","sourceCodeStart":1,"sourceCodeEnd":13,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/slock/task-identity.js#L1-L13","documentation":"assertTaskIdentity also enforces that the id on the returned task row strictly equals the id the caller asked to operate on. A mismatch means the server returned a different task than requested — e.g. the lookup by number/channel resolved to another row. Throwing here prevents reading, updating, or deleting the wrong task.","triggerScenarios":"A command resolves a task by number or channel and then asserts identity with the expected id, but the fetched row's `id` differs from expectedId: duplicate taskNumbers in a channel, channel resolution picking a different channel than intended, or stale cached expectedId.","commonSituations":"Two tasks share the same taskNumber after a channel rename/re-import; the user passed a number from one channel while the CLI resolved another; server-side reindexing changed ids; tests asserting against hardcoded ids after data changed.","solutions":["Print the returned taskId from the error and check which task it actually points to","Look the task up by its exact id rather than by number to avoid ambiguous resolution","Verify the --channel/--server flags resolve to the channel you expect before fetching by number","If taskNumbers collided, renumber or deduplicate the tasks server-side"],"exampleFix":"// before (resolving by ambiguous number)\nconst row = await fetchTaskByNumber(channel, 12);\nassertTaskIdentity(row, expectedId, 'task-get');\n// after\nconst row = await fetchTaskById(expectedId);\nassertTaskIdentity(row, expectedId, 'task-get');","handlingStrategy":"validation","validationCode":"if (row && row.id && row.id !== expectedId) {\n  console.warn(`Server returned ${row.id}, expected ${expectedId}; aborting.`);\n}","typeGuard":"const isSameTask = (t, expectedId) => t != null && t.id === expectedId;","tryCatchPattern":"try {\n  assertTaskIdentity(row, expectedId, commandName);\n} catch (e) {\n  if (/returned task id/.test(e.message)) {\n    // refetch by exact id instead of ambiguous number/channel lookup\n  }\n  throw e;\n}","preventionTips":["Prefer lookups by exact id over by number/channel to avoid ambiguous resolution","Verify --channel/--server flags resolve to the intended channel before number-based fetches","Deduplicate/renumber taskNumbers if collisions exist server-side"],"tags":["identity-mismatch","data-integrity","defensive-check"],"backgroundTag":"resource-identity-mismatch","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}