jackwener/OpenCLI · error · AuthRequiredError

reddit.com

Error message

reddit.com

What it means

upvoted.js inspects the browser-side result; if result.error contains 'Not logged in', it throws AuthRequiredError('reddit.com', result.error). This is the upvoted listing's signal that the Reddit session in the attached browser is missing or expired. Like subscribed.js, it converts a browser sentinel into a typed, domain-tagged auth error.

Source

Thrown at clis/reddit/upvoted.js:45

        const limit = ${kwargs.limit};
        const res = await fetch('/user/' + username + '/upvoted.json?limit=' + limit + '&raw_json=1', {
          credentials: 'include'
        });
        const d = await res.json();
        return (d?.data?.children || []).map(c => ({
          title: c.data.title || '',
          subreddit: c.data.subreddit_name_prefixed || 'r/' + (c.data.subreddit || '?'),
          score: c.data.score || 0,
          comments: c.data.num_comments || 0,
          url: 'https://www.reddit.com' + (c.data.permalink || ''),
        }));
      } catch (e) {
        return { error: e.toString() };
      }
    })()`);
        if (result?.error) {
            if (String(result.error).includes('Not logged in'))
                throw new AuthRequiredError('reddit.com', result.error);
            throw new CommandExecutionError(result.error);
        }
        return (result || []).slice(0, kwargs.limit);
    }
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Open the attached Chrome profile, log in to reddit.com, then rerun the command.
  2. Confirm the CLI targets the profile that holds the Reddit session.
  3. Catch AuthRequiredError and prompt the user to log in rather than retrying blindly.
  4. Keep the session warm by periodically using reddit.com in that browser to avoid cookie expiry surprises.

Example fix

// before
await run(['reddit', 'upvoted']); // AuthRequiredError: reddit.com
// after
import { AuthRequiredError } from '@jackwener/opencli/errors';
try {
  await run(['reddit', 'upvoted']);
} catch (e) {
  if (e instanceof AuthRequiredError && e.domain === 'reddit.com') {
    openBrowserAndLogin('https://www.reddit.com/login');
    await run(['reddit', 'upvoted']);
  } else throw e;
}
Defensive patterns

Strategy: try-catch

Validate before calling

// preflight auth check
try { await run(['reddit', 'whoami']); } catch (e) { if (e instanceof AuthRequiredError) throw new Error('Log in to reddit.com in the attached browser'); }

Type guard

function isAuthRequiredError(e) { return e instanceof AuthRequiredError && e.domain === 'reddit.com'; }

Try / catch

try {
  const posts = await run(['reddit', 'upvoted']);
} catch (e) {
  if (e instanceof AuthRequiredError) {
    await promptUserToLogin('https://www.reddit.com/login');
    return await run(['reddit', 'upvoted']);
  }
  throw e;
}

Prevention

When it happens

Trigger: Running `reddit upvoted` while the attached Chrome profile has no valid Reddit session; the in-page /api/me.json or upvoted fetch reports 'Not logged in' and the CLI converts it at upvoted.js:45.

Common situations: Expired Reddit cookies; logged out in the automation browser; using a fresh profile; Reddit invalidating sessions after suspicious activity.

Related errors


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