{"record":{"id":"835ad0784507b287","repo":"jackwener/OpenCLI","slug":"failed-to-fill-author","errorCode":null,"errorMessage":"Failed to fill author","messagePattern":"Failed to fill author","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/weixin/create-draft.js","lineNumber":301,"sourceCode":"        { name: 'title', required: true, help: '文章标题 (最长64字)' },\n        { name: 'content', required: true, positional: true, help: '文章正文' },\n        { name: 'author', help: '作者名 (最长8字)' },\n        { name: 'cover-image', help: '封面图片路径 (会先上传到正文再设为封面)' },\n        { name: 'summary', help: '文章摘要' },\n        { name: 'timeout', type: 'int', required: false, default: 180, help: 'Max seconds for the overall command (default: 180)' },\n    ],\n    columns: ['status', 'detail'],\n\n    func: async (page, kwargs) => {\n        try {\n            const coverImage = kwargs['cover-image'] ? resolveCoverImage(kwargs['cover-image']) : null;\n            await navigateToEditor(page);\n\n            const titleResult = await fillField(page, 'textarea#title', kwargs.title);\n            if (!titleResult?.ok) throw new CommandExecutionError('Failed to fill title');\n            if (kwargs.author) {\n                const authorResult = await fillField(page, 'input#author', kwargs.author);\n                if (!authorResult?.ok) throw new CommandExecutionError('Failed to fill author');\n            }\n            const contentResult = await fillContent(page, kwargs.content);\n            if (!contentResult?.ok) throw new CommandExecutionError('Failed to fill content');\n\n            if (coverImage) {\n                await uploadContentImage(page, coverImage);\n                const coverSet = await selectCoverFromContent(page);\n                if (coverSet !== true) {\n                    throw new CommandExecutionError('WeChat uploaded the image but did not confirm it as the draft cover.');\n                }\n            }\n\n            if (kwargs.summary) {\n                const summaryResult = await fillField(page, 'textarea#js_description', kwargs.summary);\n                if (!summaryResult?.ok) throw new CommandExecutionError('Failed to fill summary');\n            }\n\n            await saveDraft(page);","sourceCodeStart":283,"sourceCodeEnd":319,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/weixin/create-draft.js#L283-L319","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Retry the command — transient rendering delay past the fixed wait is the most frequent cause.","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.","Add an explicit wait for input#author (or make the author field optional/tolerant) before calling fillField.","Refresh the WeChat session; a stale session can serve a reduced page without the author field."],"exampleFix":"// before\nconst authorResult = await fillField(page, 'input#author', kwargs.author);\nif (!authorResult?.ok) throw new CommandExecutionError('Failed to fill author');\n// after\nconst authorResult = await fillField(page, 'input#author', kwargs.author);\nif (!authorResult?.ok) throw new CommandExecutionError('Failed to fill author: ' + (authorResult?.reason ?? 'unknown') + ' (selector input#author may be outdated)');","handlingStrategy":"fallback","validationCode":"const hasAuthor = await page.evaluate('!!document.querySelector(\"input#author\")');\nif (kwargs.author && hasAuthor !== true) console.warn('Author field missing; draft will be created without an author.');","typeGuard":null,"tryCatchPattern":"try {\n  await createDraft({ title, author, content });\n} catch (e) {\n  if (e instanceof CommandExecutionError && /Failed to fill author/.test(e.message)) {\n    // degrade gracefully: retry without author, or log and continue manually\n  } else throw e;\n}","preventionTips":["Treat author as optional: omit --author when the field is known to be missing after a WeChat UI change.","Confirm the current author input id in the live editor after any WeChat update.","Retry once before giving up; the field often renders just after the fixed wait.","Maintain a selector smoke test against the real editor page."],"tags":["puppeteer","dom-selector","wechat","automation"],"backgroundTag":"dom-element-not-found","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}