jackwener/OpenCLI · error · CommandExecutionError
${context} returned a malformed message.
Error message
${context} returned a malformed message. What it means
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.
Source
Thrown at clis/twitter/post.js:50
throw new CommandExecutionError(`Not a valid file: ${absPath}`);
}
return absPath;
});
}
function isUnsupportedInsertTextError(err) {
const msg = err instanceof Error ? err.message : String(err);
const lower = msg.toLowerCase();
return lower.includes('unknown action') || lower.includes('not supported') || lower.includes('inserttext returned no inserted flag');
}
function requirePostActionResult(value, context) {
const result = unwrapBrowserResult(value);
if (!result || typeof result !== 'object' || Array.isArray(result) || typeof result.ok !== 'boolean') {
throw new CommandExecutionError(`${context} returned a malformed result.`);
}
if (Object.prototype.hasOwnProperty.call(result, 'message') && result.message != null && typeof result.message !== 'string') {
throw new CommandExecutionError(`${context} returned a malformed message.`);
}
if (Object.prototype.hasOwnProperty.call(result, 'error') && result.error != null && typeof result.error !== 'string') {
throw new CommandExecutionError(`${context} returned a malformed error.`);
}
return result;
}
function validateSubmitStatusPair(result) {
if ((result.id && !result.url) || (!result.id && result.url)) {
throw new CommandExecutionError('Twitter post completion returned only one of id/url.');
}
if (!result.id && !result.url) return;
if (typeof result.id !== 'string' || !/^\d+$/.test(result.id)) {
throw new CommandExecutionError('Twitter post completion returned a malformed status id.');
}
if (typeof result.url !== 'string') {
throw new CommandExecutionError('Twitter post completion returned a malformed status url.');
}View on GitHub (pinned to 49907e53dc)
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
Example fix
// before (in-page script)
return { ok: false, message: { code: 7, text: 'composer not found' } };
// after
return { ok: false, message: 'composer not found (code 7)' }; Defensive patterns
Strategy: validation
Validate before calling
function hasValidMessage(r) { return !('message' in (r || {})) || r.message == null || typeof r.message === 'string'; }
if (raw && !hasValidMessage(raw)) throw new Error('message must be a string'); Type guard
function hasStringMessage(v) { return v == null || typeof v !== 'object' || !('message' in v) || v.message == null || typeof v.message === 'string'; } Try / catch
try {
return requirePostActionResult(await page.evaluate(script), context);
} catch (e) {
if (String(e.message).endsWith('returned a malformed message.')) console.warn('in-page script message field not a string; check script return');
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- ${context} returned a malformed result.
- ${context} returned a malformed error.
- Twitter post completion returned only one of id/url.
- Twitter post completion returned a malformed status id.
- Twitter post completion returned a malformed status url.
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/34904288570e819d.
Report an issue: GitHub.