{"record":{"id":"5f3e664eab7bfd86","repo":"jackwener/OpenCLI","slug":"mubu-path-code-data-code-data-message","errorCode":null,"errorMessage":"mubu: ${path}: code=${data.code} ${data.message ?? ''}","messagePattern":"mubu: (.+?): code=(.+?) (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/mubu/utils.js","lineNumber":53,"sourceCode":"        xhr.onerror = () => resolve({ ok: false, status: 0, data: null, error: 'network error' });\n        xhr.send(${JSON.stringify(JSON.stringify(body))});\n      });\n    })()\n  `);\n\n  if (!result || result.error === 'no token') {\n    throw new AuthRequiredError(MUBU_DOMAIN, AUTH_HINT);\n  }\n  if (!result.ok || !result.data) {\n    throw new CommandExecutionError(`mubu: ${path}: HTTP ${result.status} ${result.error ?? ''}`);\n  }\n\n  const { data } = result;\n  if (data.code !== 0) {\n    if (isAuthFailure(data.code, data.message)) {\n      throw new AuthRequiredError(MUBU_DOMAIN, AUTH_HINT);\n    }\n    throw new CommandExecutionError(`mubu: ${path}: code=${data.code} ${data.message ?? ''}`);\n  }\n\n  return data.data;\n}\n\nexport function formatDate(ts) {\n  if (!ts) return '';\n  const d = new Date(ts);\n  const pad = (n) => String(n).padStart(2, '0');\n  return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`;\n}\n\nconst NAMED_ENTITIES = { amp: '&', lt: '<', gt: '>', quot: '\"', apos: \"'\", nbsp: ' ' };\n\nfunction decodeHtmlEntities(s) {\n  return s\n    .replace(/&#x([0-9a-f]+);/gi, (_, h) => String.fromCodePoint(parseInt(h, 16)))\n    .replace(/&#(\\d+);/g, (_, n) => String.fromCodePoint(parseInt(n, 10)))","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/mubu/utils.js#L35-L71","documentation":"mubuPost throws this CommandExecutionError when the Mubu HTTP API responds successfully at the transport level but reports a business-logic failure in its JSON envelope (data.code !== 0), and the code is not recognized as an auth failure (AuthRequiredError is thrown for that case instead). The message embeds the API endpoint path, the numeric error code, and the API's message so you can see which Mubu operation was rejected and why. It indicates the command you asked Mubu to execute failed server-side.","triggerScenarios":"Calling any Mubu command via mubuPost (e.g. creating or updating a document) where result.data.code is non-zero and isAuthFailure(data.code, data.message) is false; e.g. invalid document ID, permission denial, rate limit, or malformed parameters rejected by the Mubu API.","commonSituations":"Referencing a deleted or foreign-outline document ID; operating on a document the authenticated account cannot edit; passing bad parameters (wrong parentId, invalid content shape); Mubu API version drift introducing new error codes not covered by isAuthFailure; transient Mubu server errors surfaced as non-zero codes.","solutions":["Read data.code and data.message in the error text and check them against the Mubu API response for the given path to identify the actual failure.","Verify the document/outline ID passed to the command exists and is accessible to the authenticated account.","If the code is auth-related (e.g. token expired), re-authenticate; consider extending isAuthFailure to cover the code you hit.","Retry the request if the code indicates a transient server-side problem, after confirming parameters are correct."],"exampleFix":"// before\ntext = 'my outline';\nmubuPost('/api/xxx', { text });\n// after\n// confirm the target outline id is valid and owned by the account\nconst doc = await getOutline(knownValidId);\nmubuPost('/api/xxx', { id: doc.id, text });","handlingStrategy":"try-catch","validationCode":"if (!outlineId) throw new Error('refusing to call mubu: outlineId is empty');","typeGuard":"function isMubuEnvelope(d) { return d && typeof d === 'object' && typeof d.code === 'number'; }","tryCatchPattern":"try {\n  const out = await mubuPost(path, payload);\n} catch (e) {\n  if (e instanceof AuthRequiredError) { await reauth(); }\n  else if (/code=\\d+/.test(e.message)) {\n    const code = Number(e.message.match(/code=(\\d+)/)[1]);\n    if (TRANSIENT_CODES.has(code)) await retry();\n    else console.error('Mubu rejected command:', e.message);\n  } else throw e;\n}","preventionTips":["Validate document IDs and parameters before calling mubuPost.","Check the account still has access to the target outline.","Log data.code/message patterns and extend isAuthFailure for auth-like codes.","Wrap mubuPost calls with a helper that maps known codes to actionable messages."],"tags":["mubu","api-error","command-execution","http"],"backgroundTag":"api-business-error-code","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}