jackwener/OpenCLI · error · CommandExecutionError

Failed to fill author

Error message

Failed to fill author

What it means

This CommandExecutionError is thrown when fillField() cannot set the optional author field (input#author) in the WeChat article editor. fillField returns {ok:false, reason:'field not found'} when document.querySelector('input#author') is null, and the command converts any non-ok result into this error. It only runs when kwargs.author was supplied, so the author input existed in the expected layout but was not present on the actual page.

Source

Thrown at clis/weixin/create-draft.js:301

        { 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');
            }

            await saveDraft(page);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Retry the command — transient rendering delay past the fixed wait is the most frequent cause.
  2. Open the editor manually and verify the author input's id; if WeChat changed it, update the 'input#author' selector in clis/weixin/create-draft.js.
  3. Add an explicit wait for input#author (or make the author field optional/tolerant) before calling fillField.
  4. Refresh the WeChat session; a stale session can serve a reduced page without the author field.

Example fix

// before
const authorResult = await fillField(page, 'input#author', kwargs.author);
if (!authorResult?.ok) throw new CommandExecutionError('Failed to fill author');
// after
const authorResult = await fillField(page, 'input#author', kwargs.author);
if (!authorResult?.ok) throw new CommandExecutionError('Failed to fill author: ' + (authorResult?.reason ?? 'unknown') + ' (selector input#author may be outdated)');
Defensive patterns

Strategy: fallback

Validate before calling

const hasAuthor = await page.evaluate('!!document.querySelector("input#author")');
if (kwargs.author && hasAuthor !== true) console.warn('Author field missing; draft will be created without an author.');

Try / catch

try {
  await createDraft({ title, author, content });
} catch (e) {
  if (e instanceof CommandExecutionError && /Failed to fill author/.test(e.message)) {
    // degrade gracefully: retry without author, or log and continue manually
  } else throw e;
}

Prevention

When it happens

Trigger: Running create-draft with an --author value while input#author is missing from the rendered editor page: WeChat DOM/selector change, editor still loading past the fixed 4-second wait in navigateToEditor, or a variant editor layout that omits or renames the author input.

Common situations: WeChat redesigns the editor so the author input id changes (e.g., moved into a component with a different id); slow page load on a large account; regional/AB-tested editor variants; or the field only renders after the title is committed and timing races the script.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/835ad0784507b287. Report an issue: GitHub.