#2540·OpenCLI

[Bug]: AuthRequiredError silently discards a recovery hint — every sibling error class accepts one

Author: omnisurgeCreated Sep 25, 2026Updated Sep 25, 2026

Summary

AuthRequiredError silently discards a recovery hint. It is the only error class in src/errors.ts that does not accept hint, even though its parent CliError does (constructor(code, message, hint?, exitCode?)). Writing new AuthRequiredError(domain, message, hint) is therefore the natural thing to do — and in a plain-JavaScript adapter there is no compiler to stop it. The third argument is dropped and the user always sees the hardcoded browser line.

Evidence

src/errors.ts on main (v1.8.8): 11 exported error classes, 9 of their constructors take hint?: string. AuthRequiredError is the outlier, and it hardcodes a hint of its own:

typescript
export class AuthRequiredError extends CliError {
  readonly domain: string;
  constructor(domain: string, message?: string) {
    super(
      'AUTH_REQUIRED',
      message ?? `Not logged in to ${domain}`,
      `Please open Chrome or Chromium and log in to https://${domain}`,
      EXIT_CODES.NOPERM,
    );
    this.domain = domain;
  }
}

For contrast, LoginWallError in the same file already does exactly the right thing — hint last, with the current text as a fallback:

typescript
constructor(message: string, status: number, url: string, bodyPreview: string, hint?: string) {
  super(
    'LOGIN_WALL',
    message,
    hint ?? 'The server returned an HTML page instead of JSON — likely a login wall, ...',
    // ... (excerpt; see src/errors.ts for the full class)

Repro

A plain-JS adapter (no type checking, so this is not caught at build time):

javascript
import { AuthRequiredError } from '@jackwener/opencli/errors';

throw new AuthRequiredError(
  'example.com',
  'Session expired',
  'Refresh with: example-cli login-api   (no browser needed)',
);

Observed — the third argument is gone, only the hardcoded line survives:

error:
  code: AUTH_REQUIRED
  message: Session expired
  help: Please open Chrome or Chromium and log in to https://example.com
  exitCode: 77

Impact

An adapter's own recovery command never reaches the user or the agent. In our site adapter the zero-interaction recovery path (refresh the session from locally stored credentials — no browser, no prompt) had been wired into every auth-failure site and was never displayed once. The only visible instruction was Please open Chrome or Chromium, so both humans and agents were routed to a browser window — or concluded "the environment is blocked" — while a single browser-free command would have fixed it in one step.

This also matters for #1883: its requirement "align with existing AuthRequiredError recovery-command style" assumes such a style exists. It currently cannot — there is no way to attach a recovery command to this error.

Workaround we use today: concatenate the recovery text into the message argument, because that is the only field that survives. It works, but it muddies the message and every adapter must rediscover it.

Suggested fix

Follow the LoginWallError precedent — add the hint as the 3rd optional parameter and keep the current text as the default, so existing 2-argument call sites are unaffected:

typescript
constructor(domain: string, message?: string, hint?: string) {
  super(
    'AUTH_REQUIRED',
    message ?? `Not logged in to ${domain}`,
    hint ?? `Please open Chrome or Chromium and log in to https://${domain}`,
    EXIT_CODES.NOPERM,
  );
    this.domain = domain;
  }
}

For JS adapters that already pass a third argument believing it works, this fix is what makes those hints start appearing. TypeScript callers are unaffected (optional, last parameter).

Optionally, a small test asserting that every *Error constructor in src/errors.ts exposes hint?: string would stop this divergence from returning.

Environment

  • @jackwener/opencli 1.8.7 installed locally; main (1.8.8) verified to still carry the 2-parameter signature.
  • Node 26.1.0, macOS arm64.