{"record":{"id":"4ef552d141bcb28a","repo":"affaan-m/ECC","slug":"result-error-request-failed","errorCode":null,"errorMessage":"${result.error || 'request failed'}","messagePattern":"\\$\\{result\\.error \\|\\| 'request failed'\\}","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/lib/control-pane/ui.js","lineNumber":664,"sourceCode":"    }\n\n    $('#query-form').addEventListener('submit', event => {\n      event.preventDefault();\n      state.query = $('#query').value.trim();\n      load().catch(error => showError('#app', error));\n    });\n    $('#refresh').addEventListener('click', () => {\n      load().catch(error => showError('#app', error));\n    });\n\n    async function postWorkItem(pathSuffix, payload) {\n      const response = await fetch('/api/work-items/' + pathSuffix, {\n        method: 'POST',\n        headers: { 'content-type': 'application/json' },\n        body: JSON.stringify(payload || {})\n      });\n      const result = await readJsonResponse(response);\n      if (!result.ok) throw new Error(result.error || 'request failed');\n      await load();\n    }\n\n    window.eccClaimItem = function (id) {\n      if (!state.allowActions) return;\n      const owner = window.prompt('Claim \"' + id + '\" as (owner name):');\n      if (!owner) return;\n      const as = (window.prompt(\"Owner kind: 'agent' or 'human'\", 'human') || '').trim().toLowerCase();\n      postWorkItem(encodeURIComponent(id) + '/claim', { owner: owner.trim(), as: as === 'agent' ? 'agent' : 'human' })\n        .catch(error => showError('#app', error));\n    };\n    window.eccMoveItem = function (id, lane) {\n      if (!state.allowActions) return;\n      postWorkItem(encodeURIComponent(id) + '/move', { lane })\n        .catch(error => showError('#app', error));\n    };\n\n    // Live board: refresh on a gentle interval; pause while a prompt/tab is hidden.","sourceCodeStart":646,"sourceCodeEnd":682,"githubUrl":"https://github.com/affaan-m/ECC/blob/d8409a4b0813771235555e32e3d8046a73988bfa/scripts/lib/control-pane/ui.js#L646-L682","documentation":"Thrown by postWorkItem in the control pane UI after the server replies with a JSON body whose ok field is false (HTTP status was 200; readJsonResponse already handled non-2xx). The message is whatever the server put in result.error — typically one of the work-item mutation rejections: work item not found, invalid lane, claim requires an owner, or item already done.","triggerScenarios":"Clicking Claim or Move on a card in a stale board where the item was deleted or already completed by someone else; submitting a claim with an empty owner; posting to /api/work-items/<id>/claim or /move with a payload the mutation layer rejects.","commonSituations":"Two agents, or a human plus an agent, using the control pane concurrently against the same DB; a UI tab left open while the underlying work-items DB changed; canceling or blanking the browser prompt dialogs.","solutions":["Read the surfaced message — it names the exact server-side rejection (e.g. 'Work item not found: X' or 'Invalid lane'), then fix that condition","Click Refresh to reload current board state before retrying the action","When claiming, make sure the owner prompt is answered with a non-empty name","If the item was finished by another worker, pick a different item — the refusal is correct behavior"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (!id) return;\nconst fresh = state.items.find(i => i.id === id);\nif (!fresh) { await load(); return; } // stale card; reload instead of posting","typeGuard":null,"tryCatchPattern":"try {\n  await postWorkItem(`${encodeURIComponent(id)}/claim`, { owner });\n} catch (error) {\n  showError('#app', error);\n  if (/not found|already done/.test(error.message)) {\n    await load(); // stale state — refresh the board, don't alarm the user\n  }\n}","preventionTips":["Refresh the board before acting on items rendered long ago","Always supply a non-empty owner when claiming","Treat ok:false bodies as authoritative server state, not as bugs to retry blindly"],"tags":["ui","api","work-items","control-pane"],"backgroundTag":"api-request-failed","analyzedSha":"d8409a4b0813771235555e32e3d8046a73988bfa","analyzedAt":"2026-08-26T12:15:34.022Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}