jackwener/OpenCLI · critical · AuthRequiredError

AUTH_HINT

Error message

AUTH_HINT

What it means

unwrapApiData in clis/quark/utils.js raises AuthRequiredError with the placeholder message AUTH_HINT whenever isAuthFailure(resp.message, resp.status) detects the Quark API response indicates an authentication problem (e.g. not-logged-in / credential-expired messages or status codes). Called by apiGet, apiPost, getToken, and files, this is the central auth gate for the Quark CLI, signaling that the user must re-authenticate in the browser session before requests can succeed.

Source

Thrown at clis/quark/utils.js:22

export const TASK_API = 'https://drive-pc.quark.cn/1/clouddrive/task';
const QUARK_DOMAIN = 'pan.quark.cn';
const AUTH_HINT = 'Quark Drive requires a logged-in browser session';
function isAuthFailure(message, status) {
    if (status === 401 || status === 403)
        return true;
    return /not logged in|login required|please log in|authentication required|unauthorized|forbidden|未登录|请先登录|需要登录|登录/.test(message.toLowerCase());
}
function getErrorStatus(error) {
    if (!error || typeof error !== 'object' || !('status' in error))
        return undefined;
    const status = error.status;
    return typeof status === 'number' ? status : undefined;
}
function unwrapApiData(resp, action) {
    if (resp.status === 200)
        return resp.data;
    if (isAuthFailure(resp.message, resp.status)) {
        throw new AuthRequiredError(QUARK_DOMAIN, AUTH_HINT);
    }
    throw new CommandExecutionError(`quark: ${action}: ${resp.message}`);
}
export function extractPwdId(url) {
    const m = url.match(/\/s\/([a-zA-Z0-9]+)/);
    if (m)
        return m[1];
    if (/^[a-zA-Z0-9]+$/.test(url))
        return url;
    throw new ArgumentError(`Invalid Quark share URL: ${url}`);
}
export async function fetchJson(page, url, options) {
    const method = options?.method || 'GET';
    const body = options?.body ? JSON.stringify(options.body) : undefined;
    const js = `fetch(${JSON.stringify(url)}, {
    method: ${JSON.stringify(method)},
    headers: { 'Content-Type': 'application/json' },
    credentials: 'include',

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Re-authenticate: open the Quark drive in the CLI-controlled browser page and log in again, then retry the command.
  2. Clear stale session state/cookies for QUARK_DOMAIN and log in fresh.
  3. Verify the account is still logged in on quark.cn in a normal browser; re-login there if needed.
  4. Check whether Quark changed its auth-failure message/status codes, which would require updating isAuthFailure detection.
  5. Run a lightweight listing command (files) first to validate the session before long operations.

Example fix

// before (response surfaced as generic CommandExecutionError)
throw new CommandExecutionError(`quark: ${action}: ${resp.message}`);
// after (already handled by the library)
if (isAuthFailure(resp.message, resp.status)) {
  throw new AuthRequiredError(QUARK_DOMAIN, AUTH_HINT);
}
Defensive patterns

Strategy: try-catch

Validate before calling

// session probe before heavy operations
try {
  await files(page, { fid: '0' });
} catch (e) {
  if (e instanceof AuthRequiredError) {
    await reloginInBrowser(page, QUARK_DOMAIN);
  }
}

Type guard

function isAuthRequiredError(e) {
  return e instanceof AuthRequiredError ||
    (e && typeof e.message === 'string' && e.message.includes('login'));
}

Try / catch

try {
  await apiCall(page, ...);
} catch (e) {
  if (isAuthRequiredError(e)) {
    await reloginInBrowser(page, QUARK_DOMAIN);
    return apiCall(page, ...); // retry once after re-auth
  }
  throw e;
}

Prevention

When it happens

Trigger: Any apiGet/apiPost (rename, delete, save, mv, listing) where Quark responds with an auth-failure message or status — typically an expired login session cookie in the controlled browser page; getToken hitting the share token endpoint while logged out.

Common situations: Browser session cookies expired after inactivity; Quark logged out the session elsewhere; running the CLI after a long gap; account security logout; using a page that was never logged in.

Related errors


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