{"record":{"id":"45d78eb9f5e7919f","repo":"jackwener/OpenCLI","slug":"e-message-rethrown-as-argumenterror-45d78e","errorCode":null,"errorMessage":"${e.message} (rethrown as ArgumentError)","messagePattern":"(.+?) \\(rethrown as ArgumentError\\)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/slock/task-unclaim.js","lineNumber":32,"sourceCode":"\ncli({\n  site: SLOCK_SITE,\n  name: 'task-unclaim',\n  access: 'write',\n  description: 'Release ownership of a chat task (PATCH /tasks/:id/unclaim).',\n  domain: SLOCK_DOMAIN,\n  strategy: Strategy.COOKIE,\n  browser: true,\n  siteSession: 'persistent',\n  args: [\n    { name: 'taskId', positional: true, required: true, help: 'Full task UUID (= message id; short ids rejected)' },\n    { name: 'server', help: 'Override active server' },\n  ],\n  columns: ['taskId', 'taskStatus', 'assigneeId', 'taskNumber'],\n  func: async (page, kwargs) => {\n    let id;\n    try { id = assertMessageIdShape(String(kwargs.taskId ?? '')); }\n    catch (e) { throw new ArgumentError(e.message); }\n    await page.goto(SLOCK_HOME_URL);\n    const snippet = `\n      ${authHeadersFragment({ serverScoped: true, serverIdOverride: kwargs.server })}\n      const res = await fetch('${SLOCK_API_BASE}/tasks/' + encodeURIComponent(${JSON.stringify(id)}) + '/unclaim', { method:'PATCH', credentials:'include', headers });\n      if (res.status === 404) return { kind: 'http', status: 404, where: '/tasks/:id/unclaim (task not found)' };\n      if (res.status === 403) return { kind: 'http', status: 403, where: '/tasks/:id/unclaim (forbidden — not the assignee, terminal status, or channel archived)' };\n      // F6 — actionable hint for the most common reason this 409s (task already\n      // unclaimed, or terminal state). Bare \"HTTP 409\" was confusing.\n      if (res.status === 409) return { kind: 'http', status: 409, where: '/tasks/:id/unclaim (conflict — task is not claimed, or already in a terminal state (done/closed))' };\n      if (!res.ok) return { kind: res.status===401?'auth':'http', status: res.status, where:'/tasks/:id/unclaim' };\n      const data = await res.json().catch(() => ({}));\n      const t = (data && data.task) ? data.task : data;\n      return { kind: 'ok', rows: [t] };\n    `;\n    const result = await page.evaluate(`(async () => { ${snippet} })()`);\n    const rows = dispatchEvaluateResult(result);\n    return rows.map((t) => ({\n      taskId: assertTaskIdentity(t, id, 'task-unclaim'),","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/slock/task-unclaim.js#L14-L50","documentation":"The task-unclaim command validates the user-supplied taskId with assertMessageIdShape and rethrows any shape-validation failure as an ArgumentError, appending \"(rethrown as ArgumentError)\". It is a deliberate wrapper so callers can distinguish bad input shape (programmer error) from runtime/HTTP failures.","triggerScenarios":"Calling `slock task-unclaim` with a taskId that is empty, not a string-coercible id, or otherwise failing assertMessageIdShape's format rules (e.g. `--task-id \"\"`, whitespace, or a task number instead of a message-shaped id).","commonSituations":"Scripting the CLI with an unset shell variable; passing a numeric task number from task-list instead of the full taskId; trailing newline/quotes from copied ids.","solutions":["Print the taskId before the call and confirm it matches the id format assertMessageIdShape requires.","Copy the exact `taskId` column value from `task-list` rather than the task number.","Trim/normalize the id in your script before passing it.","Catch ArgumentError in your wrapper and print usage help."],"exampleFix":"// before\nconst id = process.env.TASK_ID; // may be undefined\nawait cli.run(['task-unclaim', '--task-id', id]);\n// after\nconst id = (process.env.TASK_ID ?? '').trim();\nif (!id) throw new Error('TASK_ID is required');\nawait cli.run(['task-unclaim', '--task-id', id]);","handlingStrategy":"validation","validationCode":"const id = String(kwargs.taskId ?? '').trim();\nif (!id) throw new Error('taskId is required and must match the message-id shape');","typeGuard":"function looksLikeMessageId(s) { return typeof s === 'string' && /^[A-Za-z0-9_-]{6,}$/.test(s.trim()); }","tryCatchPattern":"try {\n  await cli.run(['task-unclaim', '--task-id', id]);\n} catch (e) {\n  if (e.name === 'ArgumentError' || String(e.message).includes('rethrown as ArgumentError')) {\n    console.error(`bad taskId \"${id}\" — use the taskId column from task-list`);\n  } else throw e;\n}","preventionTips":["Trim and validate ids before CLI calls","Use taskId (not task number) from task-list","Guard against unset env vars in scripts"],"tags":["argument-validation","input-shape","cli"],"backgroundTag":"invalid-argument-format","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}