jackwener/OpenCLI · error · CommandExecutionError
Failed to fill title
Error message
Failed to fill title
What it means
This CommandExecutionError is thrown by the weixin create-draft command when fillField() fails to set the article title in the WeChat Official Account editor. fillField() runs an in-page script that queries textarea#title; if the element is absent it returns {ok:false, reason:'field not found'}, and any non-ok result triggers this throw. It effectively means the expected title field never appeared or was not interactable after navigateToEditor().
Source
Thrown at clis/weixin/create-draft.js:298
browser: true,
navigateBefore: false,
args: [
{ name: 'title', required: true, help: '文章标题 (最长64字)' },
{ name: 'content', required: true, positional: true, help: '文章正文' },
{ name: 'author', help: '作者名 (最长8字)' },
{ name: 'cover-image', help: '封面图片路径 (会先上传到正文再设为封面)' },
{ name: 'summary', help: '文章摘要' },
{ name: 'timeout', type: 'int', required: false, default: 180, help: 'Max seconds for the overall command (default: 180)' },
],
columns: ['status', 'detail'],
func: async (page, kwargs) => {
try {
const coverImage = kwargs['cover-image'] ? resolveCoverImage(kwargs['cover-image']) : null;
await navigateToEditor(page);
const titleResult = await fillField(page, 'textarea#title', kwargs.title);
if (!titleResult?.ok) throw new CommandExecutionError('Failed to fill title');
if (kwargs.author) {
const authorResult = await fillField(page, 'input#author', kwargs.author);
if (!authorResult?.ok) throw new CommandExecutionError('Failed to fill author');
}
const contentResult = await fillContent(page, kwargs.content);
if (!contentResult?.ok) throw new CommandExecutionError('Failed to fill content');
if (coverImage) {
await uploadContentImage(page, coverImage);
const coverSet = await selectCoverFromContent(page);
if (coverSet !== true) {
throw new CommandExecutionError('WeChat uploaded the image but did not confirm it as the draft cover.');
}
}
if (kwargs.summary) {
const summaryResult = await fillField(page, 'textarea#js_description', kwargs.summary);
if (!summaryResult?.ok) throw new CommandExecutionError('Failed to fill summary');View on GitHub (pinned to 49907e53dc)
Solutions
- Re-run the command once — transient slow rendering past the fixed 4-second wait is the most common cause; a retry usually finds the field.
- Verify login state is fully valid (re-authenticate the WeChat session); a degraded session can land on a non-standard page missing the editor.
- Inspect the live editor page and confirm textarea#title exists; if WeChat renamed it, update the selector in clis/weixin/create-draft.js (fillField call for the title).
- Increase the wait after navigating to the editor URL (navigateToEditor uses page.wait(4)) or add an explicit wait-for-selector for textarea#title before filling.
Example fix
// before
const titleResult = await fillField(page, 'textarea#title', kwargs.title);
if (!titleResult?.ok) throw new CommandExecutionError('Failed to fill title');
// after
await page.waitForSelector('textarea#title', { timeout: 15000 }); // or equivalent explicit wait
const titleResult = await fillField(page, 'textarea#title', kwargs.title);
if (!titleResult?.ok) throw new CommandExecutionError('Failed to fill title: ' + (titleResult?.reason ?? 'unknown')); Defensive patterns
Strategy: retry
Validate before calling
const hasTitle = await page.evaluate('!!document.querySelector("textarea#title")');
if (hasTitle !== true) throw new Error('WeChat editor title field not present; aborting before fill.'); Try / catch
try {
await createDraft({ title, author, content });
} catch (e) {
if (e instanceof CommandExecutionError && /Failed to fill title/.test(e.message)) {
// retry once after delay, or re-authenticate the WeChat session
} else throw e;
} Prevention
- Verify the WeChat session is freshly logged in before running create-draft.
- Keep selectors in the CLI updated after WeChat editor redesigns; smoke-test on one draft first.
- Wrap the command in a bounded retry (1-2 attempts with a few seconds delay) since fixed waits race slow editor loads.
- Check the editor manually in a browser if the error repeats — confirms whether textarea#title still exists.
When it happens
Trigger: Calling the create-draft command where document.querySelector('textarea#title') is null inside the page at fill time: the editor page did not render the title textarea (WeChat DOM changed, slow load exceeding the fixed 4s wait in navigateToEditor, or a different editor layout was served). fillField itself only returns ok:false for 'field not found' — it does not fail on invalid values.
Common situations: WeChat changes its editor markup so textarea#title no longer exists; the mp.weixin.qq.com editor loads slowly (network latency, heavy account media library) and the fixed page.wait(4) elapses before the field is attached; an A/B or regional variant of the editor renders different selectors; a partially logged-in or rate-limited session lands on a page that still has the token but not the standard editor.
Related errors
- Failed to fill author
- Failed to fill summary
- Failed to fill content
- Could not find ${fieldName} input. Debug screenshot: /tmp/xh
- Instagram reel upload failed
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/3fa9e8236f4c3621.
Report an issue: GitHub.