decolua/9router · error · Error

Failed to get device code: ${error}

Error message

Failed to get device code: ${error}

What it means

GitHubService.getDeviceCode() POSTs to GitHub's device-flow endpoint (https://github.com/login/device/code) requesting a device code. If GitHub responds with a non-OK status, the raw response body is embedded into `Failed to get device code: ${error}` and thrown. This is the very first network step of GitHub device authentication, so it means GitHub rejected the device-code request itself.

Source

Thrown at src/lib/oauth/services/github.js:32

  /**
   * Get device code for GitHub authentication
   */
  async getDeviceCode() {
    const response = await fetch(`${GITHUB_CONFIG.deviceCodeUrl}`, {
      method: "POST",
      headers: {
        "Content-Type": "application/x-www-form-urlencoded",
        Accept: "application/json",
      },
      body: new URLSearchParams({
        client_id: GITHUB_CONFIG.clientId,
        scope: GITHUB_CONFIG.scopes,
      }),
    });

    if (!response.ok) {
      const error = await response.text();
      throw new Error(`Failed to get device code: ${error}`);
    }

    return await response.json();
  }

  /**
   * Poll for access token using device code
   */
  async pollAccessToken(deviceCode, verificationUri, userCode, interval = 5000) {
    const spinner = createSpinner("Waiting for GitHub authentication...").start();
    
    // Show user code and verification URL
    console.log(`\nPlease visit: ${verificationUri}`);
    console.log(`Enter code: ${userCode}\n`);
    
    // Open browser automatically
    try {
      const open = (await import("open")).default;

View on GitHub (pinned to 90b52e06ff)

Solutions

  1. Check internet/proxy connectivity to github.com (curl -i https://github.com/login/device/code) — fix VPN/proxy/DNS if unreachable.
  2. Verify GITHUB_CONFIG.clientId in src/lib/oauth/constants/oauth.js matches a still-valid GitHub OAuth app's client ID.
  3. Update the CLI/library version if the hardcoded client_id has been revoked by upstream.
  4. Retry later if GitHub is having an incident (githubstatus.com).

Example fix

// before
if (!response.ok) {
  const error = await response.text();
  throw new Error(`Failed to get device code: ${error}`);
}
// after
if (!response.ok) {
  const error = await response.text();
  throw new Error(`Failed to get device code (HTTP ${response.status}): ${error}`);
}
Defensive patterns

Strategy: retry

Validate before calling

async function assertGitHubReachable() {
  const res = await fetch('https://github.com', { method: 'HEAD' }).catch(() => null);
  if (!res) throw new Error('github.com unreachable — check network/VPN/proxy before starting device auth');
}

Type guard

function isDeviceCodeResponse(data) {
  return data !== null && typeof data === 'object' && typeof data.device_code === 'string' && typeof data.user_code === 'string';
}

Try / catch

try {
  const deviceResponse = await service.getDeviceCode();
} catch (err) {
  if (err.message.startsWith('Failed to get device code')) {
    console.error('GitHub device-code request failed — verify connectivity to github.com and that the OAuth app client_id is valid.');
  }
  throw err;
}

Prevention

When it happens

Trigger: The POST to GITHUB_CONFIG.deviceCodeUrl returns non-2xx — e.g. a bad/rotated client_id (GitHub returns 404 or 401), a network/proxy block on github.com, or an HTML error page from a captive portal or corporate proxy embedded in the message.

Common situations: GITHUB_CONFIG.clientId no longer matches a valid GitHub OAuth app (client revoked/rotated); corporate firewall or proxy intercepting github.com; offline machine or DNS failure so the fetch hits an error page.

Understand the failure class

Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.

Related errors


AI-assisted analysis of decolua/9router@90b52e06ff (2026-08-30). Data as JSON: /api/errors/b84ba4ead34dab68. Report an issue: GitHub.