jackwener/OpenCLI · error · AuthRequiredError

发布闲鱼需要先登录,请在 Chrome 中打开 goofish.com 并完成登录

Error message

发布闲鱼需要先登录,请在 Chrome 中打开 goofish.com 并完成登录

What it means

The publish flow opens goofish.com's publish page, extracts page state, and throws AuthRequiredError when the state reports requiresAuth — the browser session is not logged into Xianyu/goofish. The library cannot publish without an authenticated Chrome profile, so it stops with a login instruction.

Source

Thrown at clis/xianyu/publish.js:396

        { name: 'description', required: true, positional: true, help: '商品描述/详情' },
        { name: 'price', required: true, positional: true, type: 'float', help: '出售价格(元)' },
        { name: 'condition', required: true, positional: true, help: '成色:全新 / 几乎全新 / 轻微使用 / 明显使用 / 老旧' },
        { name: 'category', required: true, positional: true, help: '商品分类关键词(如:手机、衣服、图书)' },
        { name: 'original_price', type: 'float', help: '原价(选填,用于显示折扣)' },
        { name: 'location', help: '所在地区(选填,如:杭州)' },
        { name: 'images', help: '本地图片路径,多张用逗号分隔(选填,如:/tmp/a.jpg,/tmp/b.jpg)' },
    ],
    columns: ['status', 'item_id', 'title', 'price', 'condition', 'url', 'message'],
    func: async (page, kwargs) => {
        const data = normalizePublishArgs(kwargs);
        // 1. 导航到发布页
        await page.goto(buildPublishUrl());
        await page.wait(3);

        // 2. 检查登录状态
        const initState = await page.evaluate(buildExtractPageStateEvaluate());
        if (initState?.requiresAuth) {
            throw new AuthRequiredError('www.goofish.com', '发布闲鱼需要先登录,请在 Chrome 中打开 goofish.com 并完成登录');
        }
        if (!initState?.hasPublishForm) {
            throw new CommandExecutionError('Xianyu publish form was not detected', 'Confirm goofish.com is logged in and the publish page finished loading.');
        }

        // 3. 选择分类(先于其他字段,因为分类可能影响表单结构)
        const categoryResult = await page.evaluate(buildSelectCategoryEvaluate(data.category));
        if (!categoryResult?.ok) {
            throw new CommandExecutionError(`Xianyu category selection failed: ${categoryResult?.reason || 'unknown-reason'}`);
        }
        await page.wait(1.5);

        // 4. 填充表单
        const fillResult = await page.evaluate(buildFillFormEvaluate(data));
        if (!fillResult?.ok) {
            const missing = Array.isArray(fillResult?.missing) ? fillResult.missing.join(', ') : 'unknown';
            throw new CommandExecutionError(`Xianyu publish form fill failed; missing fields: ${missing}`);
        }

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Open goofish.com in the Chrome profile used by the CLI and complete login (including QR scan), then rerun publish
  2. Point the CLI at the Chrome user-data-dir/profile where you are already logged in
  3. Re-login and verify goofish.com shows your account before retrying

Example fix

// before (no login)
await publish(data); // AuthRequiredError
// after: log in to goofish.com in the target Chrome profile, then
await publish(data); // proceeds
Defensive patterns

Strategy: try-catch

Validate before calling

const state = await page.evaluate(buildExtractPageStateEvaluate());
if (state?.requiresAuth) {
  throw new Error('Not logged into goofish.com — complete login in Chrome first');
}

Type guard

function isLoggedIn(state) {
  return Boolean(state && !state.requiresAuth);
}

Try / catch

try {
  await publish(data);
} catch (e) {
  if (e instanceof AuthRequiredError) {
    console.error(`Login required for goofish.com: open the site in Chrome and log in, then retry`);
  } else throw e;
}

Prevention

When it happens

Trigger: Running xianyu publish while the attached Chrome profile has no valid goofish.com session: initState.requiresAuth is true after page.goto(buildPublishUrl()).

Common situations: Fresh automation profile that never logged in, expired session cookies, manual logout, cookies cleared by browser cleanup, or pointing at the wrong Chrome profile directory.

Related errors


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