{"record":{"id":"34904288570e819d","repo":"jackwener/OpenCLI","slug":"context-returned-a-malformed-message","errorCode":null,"errorMessage":"${context} returned a malformed message.","messagePattern":"(.+?) returned a malformed message\\.","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/twitter/post.js","lineNumber":50,"sourceCode":"            throw new CommandExecutionError(`Not a valid file: ${absPath}`);\n        }\n        return absPath;\n    });\n}\n\nfunction isUnsupportedInsertTextError(err) {\n    const msg = err instanceof Error ? err.message : String(err);\n    const lower = msg.toLowerCase();\n    return lower.includes('unknown action') || lower.includes('not supported') || lower.includes('inserttext returned no inserted flag');\n}\n\nfunction requirePostActionResult(value, context) {\n    const result = unwrapBrowserResult(value);\n    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    }","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/twitter/post.js#L32-L68","documentation":"requirePostActionResult checks the optional `message` field of a browser result: if the key exists and the value is neither null nor a string, the helper throws this error naming the failing context. The library enforces that any message attached to a post-action result is a string so downstream column output never receives a non-string value.","triggerScenarios":"An in-page script (from focusComposer, verifyComposerText, insertComposerText, waitForImageUpload, upload, or clickResult) returns { ok: true, message: <non-string> } — e.g. message set to an object, number, boolean, or the result of JSON.parse of an object instead of a string.","commonSituations":"Custom-modified or forked browser scripts returning structured message payloads instead of strings; a page.evaluate returning a DOM error object placed into `message`; refactoring the in-page script so `message` becomes an Error instance rather than Error.message.","solutions":["Inspect the in-page evaluate script for the context named in the error and coerce its message to a string (String(msg) or err.message)","If using a modified/forked post.js, revert to returning message as a plain string","Clear browser extensions that might alter evaluate return values and retest"],"exampleFix":"// before (in-page script)\nreturn { ok: false, message: { code: 7, text: 'composer not found' } };\n// after\nreturn { ok: false, message: 'composer not found (code 7)' };","handlingStrategy":"validation","validationCode":"function hasValidMessage(r) { return !('message' in (r || {})) || r.message == null || typeof r.message === 'string'; }\nif (raw && !hasValidMessage(raw)) throw new Error('message must be a string');","typeGuard":"function hasStringMessage(v) { return v == null || typeof v !== 'object' || !('message' in v) || v.message == null || typeof v.message === 'string'; }","tryCatchPattern":"try {\n  return requirePostActionResult(await page.evaluate(script), context);\n} catch (e) {\n  if (String(e.message).endsWith('returned a malformed message.')) console.warn('in-page script message field not a string; check script return');\n  throw e;\n}","preventionTips":["Always return message as a plain string from in-page scripts","Use err.message, not the Error object, in catch blocks","Avoid structured payloads in the message field"],"tags":["browser-automation","type-validation","x-twitter"],"backgroundTag":"malformed-browser-evaluate-result","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}