{"record":{"id":"b35df11b39c24382","repo":"jackwener/OpenCLI","slug":"weixin-drafts","errorCode":null,"errorMessage":"weixin drafts","messagePattern":"weixin drafts","errorType":"exception","errorClass":"EmptyResultError","httpStatus":null,"severity":"warning","filePath":"clis/weixin/drafts.js","lineNumber":61,"sourceCode":"                if (title) results.push({ Index: ++idx, Title: title, Time: time });\n            }\n            if (results.length > 0) return results;\n\n            var rows = document.querySelectorAll('tr, [class*=appmsg_item], [class*=list_item]');\n            rows.forEach(function(row) {\n                var titleEl = row.querySelector('[class*=title] a, [class*=title], h4');\n                var timeEl = row.querySelector('[class*=time], td:nth-child(2)');\n                var title = titleEl ? titleEl.textContent.trim() : '';\n                var time = timeEl ? timeEl.textContent.trim() : '';\n                if (title && title !== '内容' && title.length < 80) {\n                    results.push({ Index: ++idx, Title: title, Time: time });\n                }\n            });\n            return results;\n        })()`);\n\n        if (!drafts || drafts.length === 0) {\n            throw new EmptyResultError('weixin drafts', 'No structured drafts found in the current Weixin Official Account backend');\n        }\n\n        return drafts.slice(0, kwargs.limit);\n    },\n});\n","sourceCodeStart":43,"sourceCodeEnd":67,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/weixin/drafts.js#L43-L67","documentation":"The `weixin drafts` command throws EmptyResultError (code EMPTY_RESULT, exit code 66) when its page-evaluate extraction returns an empty or falsy drafts array. This means the command authenticated successfully and reached the draft list, but the DOM scraper found no structured draft items. The constructor formats the message as '<command> returned no data'.","triggerScenarios":"Running `opencli weixin drafts` when the WeChat Official Account has zero drafts in the draft box, or the drafts list page loaded but the DOM structure the evaluate script expects produced no items (e.g. page markup changed, or the appmsg list_card endpoint returned an empty/alternate layout).","commonSituations":"Brand-new Official Account with no saved drafts; all drafts previously deleted; WeChat changed the drafts page HTML so the scraper selectors stop matching; the page rendered an error or empty-state template instead of the list.","solutions":["Confirm in a browser at mp.weixin.qq.com that the draft box actually contains drafts","If drafts exist but the error persists, the page structure likely changed — update or report the weixin drafts adapter selectors","If the account genuinely has no drafts, create a draft (e.g. via `weixin create-draft`) or treat the empty result as expected (exit code 66 = EX_NOINPUT)"],"exampleFix":"// before\ntry {\n  const drafts = await run('weixin', 'drafts');\n} catch (e) {\n  if (e instanceof EmptyResultError) drafts = []; // no drafts is fine\n}\n// after\nconst drafts = await runSafe('weixin', 'drafts') ?? [];\nif (drafts.length === 0) console.log('No drafts in the WeChat draft box');","handlingStrategy":"fallback","validationCode":null,"typeGuard":"function isEmptyResult(e) { return e instanceof CliError && e.code === 'EMPTY_RESULT' && e.exitCode === 66; }","tryCatchPattern":"let drafts = [];\ntry {\n  drafts = await run(['weixin', 'drafts']);\n} catch (e) {\n  if (e instanceof CliError && e.code === 'EMPTY_RESULT') {\n    // treat as no data, not a failure\n  } else throw e;\n}","preventionTips":["Check the draft box in a browser to confirm drafts exist before scraping","Distinguish exit code 66 (no data) from real failures in automation scripts","If drafts exist but the command still returns empty, update/report the adapter (page markup likely changed)","Handle the empty case in downstream code instead of assuming non-empty lists"],"tags":["empty-result","weixin","scraping"],"backgroundTag":"empty-result-no-data","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}