jackwener/OpenCLI · warning

WeRead private API auth expired; showing cached shelf data f

Error message

WeRead private API auth expired; showing cached shelf data from localStorage. Results may be stale, and detail commands may still require re-login.

What it means

The WeRead shelf fetch via the private API failed (e.g., auth expired), but a cached shelf snapshot was found in the page's localStorage. The command returns the normalized cached rows and logs this warning so users know the data may be stale and detail commands may need re-login.

Source

Thrown at clis/weread/shelf.js:62

    func: async (page, args) => {
        const limit = normalizeShelfLimit(Number(args.limit));
        if (limit <= 0)
            return [];
        try {
            const data = await fetchPrivateApi(page, '/shelf/sync', { synckey: '0', lectureSynckey: '0' });
            return normalizePrivateApiRows(data, limit);
        }
        catch (error) {
            if (!(error instanceof CliError) || error.code !== 'AUTH_REQUIRED') {
                throw error;
            }
            const snapshot = await loadWebShelfSnapshot(page);
            if (!snapshot.cacheFound) {
                throw error;
            }
            // Make the fallback explicit so users do not mistake cached shelf data
            // for a valid private API session.
            log.warn('WeRead private API auth expired; showing cached shelf data from localStorage. Results may be stale, and detail commands may still require re-login.');
            return normalizeWebShelfRows(snapshot, limit);
        }
    },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Re-login to WeRead in the automation browser profile to restore the private API session
  2. Treat the returned shelf as potentially stale — verify before relying on it
  3. Clear localStorage/re-sync if the cached shelf looks wrong
  4. Expect detail commands (book detail/notes) to fail until re-authenticated

Example fix

// before: shelf served from stale localStorage
// $ opencli weread shelf
// warn: WeRead private API auth expired...
// after: refresh session
# re-login in the automation browser, then rerun
opencli weread shelf
Defensive patterns

Strategy: fallback

Validate before calling

// Probe session health before trusting shelf output
const fresh = await fetchPrivateShelf(page);
const usingCache = !fresh || fresh.expired;

Try / catch

try {
  const shelf = await getWereadShelf(limit);
  if (stderrIncludes('auth expired')) { markShelfAsStale(shelf); }
} catch (err) {
  // full failure (no cache): prompt re-login
}

Prevention

When it happens

Trigger: loadWebShelfSnapshot throws (private API call rejected/401/expired session) during the shelf fallback handler, and snapshot.cacheFound is true — cached localStorage data exists and is returned instead of rethrowing.

Common situations: WeRead session cookie expired, user logged out in the browser profile, WeRead rotating private API tokens, running after a long idle period with stale localStorage cache.

Related errors


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