jackwener/OpenCLI · error · CommandExecutionError
${context} returned a malformed error.
Error message
${context} returned a malformed error. What it means
requirePostActionResult validates the optional `error` field the same way it validates `message`: if `error` is present and non-null it must be a string, otherwise this CommandExecutionError is thrown with the failing context. This keeps failure diagnostics printable and consistent for the CLI's message/error columns.
Source
Thrown at clis/twitter/post.js:53
});
}
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.');
}
let url;
try {
url = new URL(result.url);View on GitHub (pinned to 49907e53dc)
Solutions
- Change the in-page script's catch block to return `error: e && e.message ? e.message : String(e)`
- Locate the context named in the error message and verify what its evaluate script assigns to `error`
- If the page is erroring out, fix the underlying DOM failure so the error path is not hit at all
Example fix
// before (in-page script)
try { ... } catch (e) { return { ok: false, error: e }; }
// after
try { ... } catch (e) { return { ok: false, error: (e && e.message) ? e.message : String(e) }; } Defensive patterns
Strategy: validation
Validate before calling
function hasValidError(r) { return !('error' in (r || {})) || r.error == null || typeof r.error === 'string'; }
if (raw && !hasValidError(raw)) throw new Error('error field must be a string'); Type guard
function hasStringError(v) { return v == null || typeof v !== 'object' || !('error' in v) || v.error == null || typeof v.error === 'string'; } Try / catch
try {
return requirePostActionResult(await page.evaluate(script), context);
} catch (e) {
if (String(e.message).endsWith('returned a malformed error.')) console.warn('in-page catch returned non-string error; use e.message');
throw e;
} Prevention
- In catch blocks return error: e.message || String(e), never the raw exception
- Keep error payloads flat strings for CLI column output
- Test error paths of in-page scripts, not just success paths
When it happens
Trigger: A browser-side script from focusComposer, verifyComposerText, insertComposerText, waitForImageUpload, upload, or clickResult returns { ok: false, error: <non-string> } — for example error set to a caught Error object, a thrown DOMException, or a nested object instead of a string.
Common situations: In-page catch blocks doing `catch (e) { return { ok: false, error: e } }` instead of `error: e.message`; bundled/minified page changes turning error payloads into objects; forks that attach structured error codes into the error field.
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 message.
- 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/6fc5c76ec7d735ef.
Report an issue: GitHub.