{"record":{"id":"8ab4f69cb3b5223f","repo":"jackwener/OpenCLI","slug":"wechat-create-draft-failed-message","errorCode":null,"errorMessage":"WeChat create-draft failed: ${message}","messagePattern":"WeChat create-draft failed: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/weixin/create-draft.js","lineNumber":327,"sourceCode":"                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);\n            return [{\n                status: 'draft saved',\n                detail: `\"${kwargs.title}\"${kwargs.author ? ` by ${kwargs.author}` : ''}${coverImage ? ' (with cover)' : ''}`,\n            }];\n        } catch (error) {\n            if (error instanceof CliError) throw error;\n            const message = error instanceof Error ? error.message : String(error);\n            throw new CommandExecutionError(`WeChat create-draft failed: ${message}`);\n        }\n    },\n});\n","sourceCodeStart":309,"sourceCodeEnd":331,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/weixin/create-draft.js#L309-L331","documentation":"This error wraps any unexpected failure in the `weixin create-draft` command into a CommandExecutionError (code COMMAND_EXEC, exit code 1). The command automates mp.weixin.qq.com to create a draft article; any thrown non-CliError value (browser page errors, navigation failures, timeouts, upload failures) is caught, its message extracted, and re-thrown with the 'WeChat create-draft failed:' prefix. CliError subclasses (like ArgumentError or AuthRequiredError) are re-thrown untouched to preserve their codes and hints.","triggerScenarios":"Calling `opencli weixin create-draft` when the underlying browser automation throws: the mp.weixin.qq.com draft page fails to load, the title/author/cover submission step times out, an element the automation clicks cannot be found, or any non-CliError exception escapes the try block.","commonSituations":"WeChat mp.weixin.qq.com UI changed so selectors no longer match; expired or unlogged-in WeChat session causing a login wall mid-flow; network flakiness or slow page loads causing page.wait timeouts; invalid cover image path or upload rejection; unexpected popup/dialog in the page.","solutions":["Read the wrapped inner message after 'WeChat create-draft failed:' — it identifies the actual failing step","Re-authenticate: open Chrome/Chromium, log in to mp.weixin.qq.com, then retry the command","Retry the command — transient network or browser timing issues often resolve on a second run","If the error persists, check for WeChat backend UI changes and report the issue; update the opencli weixin adapter if a fix is released"],"exampleFix":"// before\nawait cli.run(['weixin', 'create-draft', '--title', 'Hello']);\n// after\ntry {\n  await cli.run(['weixin', 'create-draft', '--title', 'Hello']);\n} catch (e) {\n  if (e instanceof CliError && e.code === 'COMMAND_EXEC') {\n    console.error('Create-draft failed:', e.message, 'hint:', e.hint);\n    // e.g. re-login to mp.weixin.qq.com, then retry\n  }\n}","handlingStrategy":"try-catch","validationCode":"// verify session before running create-draft\nconst url = await page.url?.() ?? '';\n// or simply pre-check by running: opencli weixin drafts\n// if it throws AUTH_REQUIRED, re-login first.","typeGuard":"function isCliError(e) { return e instanceof Error && 'code' in e && 'exitCode' in e; }","tryCatchPattern":"try {\n  await run(['weixin', 'create-draft', '--title', t]);\n} catch (e) {\n  if (e instanceof CliError && e.code === 'AUTH_REQUIRED') { /* re-login */ }\n  else if (e instanceof CliError && e.code === 'COMMAND_EXEC') { /* inspect e.message inner cause, retry once */ }\n  else throw e;\n}","preventionTips":["Ensure an active mp.weixin.qq.com login before creating drafts (run a read command like `weixin drafts` as a probe)","Keep arguments stable: valid title/author/cover path to reduce mid-flow failures","Retry once on transient failures before surfacing the error","Keep the opencli weixin adapter updated for WeChat UI changes"],"tags":["browser-automation","weixin","command-execution"],"backgroundTag":"browser-automation-command-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}