{"record":{"id":"d1770d5d22615206","repo":"jackwener/OpenCLI","slug":"twitter-post-completion-returned-a-malformed-statu","errorCode":null,"errorMessage":"Twitter post completion returned a malformed status id.","messagePattern":"Twitter post completion returned a malformed status id\\.","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/twitter/post.js","lineNumber":64,"sourceCode":"    if (!result || typeof result !== 'object' || Array.isArray(result) || typeof result.ok !== 'boolean') {\n        throw new CommandExecutionError(`${context} returned a malformed result.`);\n    }\n    if (Object.prototype.hasOwnProperty.call(result, 'message') && result.message != null && typeof result.message !== 'string') {\n        throw new CommandExecutionError(`${context} returned a malformed message.`);\n    }\n    if (Object.prototype.hasOwnProperty.call(result, 'error') && result.error != null && typeof result.error !== 'string') {\n        throw new CommandExecutionError(`${context} returned a malformed error.`);\n    }\n    return result;\n}\n\nfunction validateSubmitStatusPair(result) {\n    if ((result.id && !result.url) || (!result.id && result.url)) {\n        throw new CommandExecutionError('Twitter post completion returned only one of id/url.');\n    }\n    if (!result.id && !result.url) return;\n    if (typeof result.id !== 'string' || !/^\\d+$/.test(result.id)) {\n        throw new CommandExecutionError('Twitter post completion returned a malformed status id.');\n    }\n    if (typeof result.url !== 'string') {\n        throw new CommandExecutionError('Twitter post completion returned a malformed status url.');\n    }\n    let url;\n    try {\n        url = new URL(result.url);\n    } catch {\n        throw new CommandExecutionError('Twitter post completion returned a malformed status url.');\n    }\n    const hostname = url.hostname.toLowerCase().replace(/^www\\./, '');\n    const match = url.pathname.match(/^\\/([^/]+)\\/status\\/(\\d+)\\/?$/);\n    if (!['x.com', 'twitter.com', 'mobile.twitter.com'].includes(hostname) || !match || match[2] !== result.id) {\n        throw new CommandExecutionError('Twitter post completion returned a malformed status url.');\n    }\n}\n\nasync function focusComposer(page) {","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/twitter/post.js#L46-L82","documentation":"When both id and url are present, validateSubmitStatusPair requires id to be a string of digits (regex /^\\d+$/). Anything else — a number, undefined-coerced value, or string with non-numeric characters — throws this error. This guarantees the reported tweet id is a valid numeric Twitter status id suitable for constructing links.","triggerScenarios":"submitTweet's clickResult script returns an id that is a JavaScript number instead of a string, or a string like 'status_123', a URL-encoded id, or a tweet draft/placeholder id that contains letters.","commonSituations":"In-page scripts doing `id: Number(statusId)` or reading id from an attribute containing extra characters; future X snowflake-like ids or local draft ids leaked into the completion result; locale formatting adding separators to the id.","solutions":["Make the in-page script return the id as a raw digit string (e.g. from match[1] of /status\\/(\\d+)/)","Strip any surrounding characters/whitespace from the id before returning it (id.trim().replace(/\\D/g, ''))","Verify the script isn't capturing a draft or client-side id rather than the server status id"],"exampleFix":"// before (in-page script)\nreturn { ok: true, id: 1730000000000000000, url };\n// after\nreturn { ok: true, id: String(statusIdFromUrl), url };","handlingStrategy":"type-guard","validationCode":"if (typeof id !== 'string' || !/^\\d+$/.test(id)) throw new Error('status id must be a digit string');","typeGuard":"function isNumericIdString(v) { return typeof v === 'string' && /^\\d+$/.test(v); }","tryCatchPattern":"try {\n  await cli.run('twitter post', { text });\n} catch (e) {\n  if (String(e.message).includes('malformed status id')) { /* check captured id source in page script */ }\n  throw e;\n}","preventionTips":["Never coerce the status id to Number (precision loss and type mismatch)","Extract the id from the URL regex match, which yields digit strings","Trim and strip non-digits from scraped ids before returning"],"tags":["browser-automation","data-integrity","x-twitter"],"backgroundTag":"incomplete-post-result","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}