jackwener/OpenCLI · warning · EmptyResultError

weixin drafts

Error message

weixin drafts

What it means

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'.

Source

Thrown at clis/weixin/drafts.js:61

                if (title) results.push({ Index: ++idx, Title: title, Time: time });
            }
            if (results.length > 0) return results;

            var rows = document.querySelectorAll('tr, [class*=appmsg_item], [class*=list_item]');
            rows.forEach(function(row) {
                var titleEl = row.querySelector('[class*=title] a, [class*=title], h4');
                var timeEl = row.querySelector('[class*=time], td:nth-child(2)');
                var title = titleEl ? titleEl.textContent.trim() : '';
                var time = timeEl ? timeEl.textContent.trim() : '';
                if (title && title !== '内容' && title.length < 80) {
                    results.push({ Index: ++idx, Title: title, Time: time });
                }
            });
            return results;
        })()`);

        if (!drafts || drafts.length === 0) {
            throw new EmptyResultError('weixin drafts', 'No structured drafts found in the current Weixin Official Account backend');
        }

        return drafts.slice(0, kwargs.limit);
    },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Confirm in a browser at mp.weixin.qq.com that the draft box actually contains drafts
  2. If drafts exist but the error persists, the page structure likely changed — update or report the weixin drafts adapter selectors
  3. 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)

Example fix

// before
try {
  const drafts = await run('weixin', 'drafts');
} catch (e) {
  if (e instanceof EmptyResultError) drafts = []; // no drafts is fine
}
// after
const drafts = await runSafe('weixin', 'drafts') ?? [];
if (drafts.length === 0) console.log('No drafts in the WeChat draft box');
Defensive patterns

Strategy: fallback

Type guard

function isEmptyResult(e) { return e instanceof CliError && e.code === 'EMPTY_RESULT' && e.exitCode === 66; }

Try / catch

let drafts = [];
try {
  drafts = await run(['weixin', 'drafts']);
} catch (e) {
  if (e instanceof CliError && e.code === 'EMPTY_RESULT') {
    // treat as no data, not a failure
  } else throw e;
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


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