mastra-ai/mastra · error

Invalid GitHub Enterprise URL/domain

Error message

Invalid GitHub Enterprise URL/domain

What it means

After prompting for an optional GitHub Enterprise URL, loginGitHubCopilot normalizes the input with normalizeDomain and validates it. If the user typed a non-empty value that does not normalize to a valid Enterprise domain/URL, the library throws this validation error instead of proceeding with a bogus endpoint.

Source

Thrown at mastracode/sdk/src/auth/providers/github-copilot.ts:397

  onAuth: (url: string, instructions?: string) => void;
  onPrompt: (prompt: { message: string; placeholder?: string; allowEmpty?: boolean }) => Promise<string>;
  onProgress?: (message: string) => void;
  signal?: AbortSignal;
}): Promise<GitHubCopilotCredentials> {
  const input = await options.onPrompt({
    message: 'GitHub Enterprise URL/domain (blank for github.com)',
    placeholder: 'company.ghe.com',
    allowEmpty: true,
  });

  if (options.signal?.aborted) {
    throw new Error('Login cancelled');
  }

  const trimmed = input.trim();
  const enterpriseDomain = normalizeDomain(input);
  if (trimmed && !enterpriseDomain) {
    throw new Error('Invalid GitHub Enterprise URL/domain');
  }
  let pending = await startGitHubCopilotDeviceLogin(enterpriseDomain ?? undefined, { signal: options.signal });
  options.onAuth(pending.url, pending.instructions);

  while (true) {
    if (options.signal?.aborted) {
      throw new Error('Login cancelled');
    }

    // Wait before polling (safety margin over the server interval), clamped to the deadline.
    const remainingMs = Math.max(pending.deadlineAt - Date.now(), 0);
    await abortableSleep(Math.min(copilotNextPollDelayMs(pending), remainingMs), options.signal);

    const result = await pollGitHubCopilotDeviceLogin(pending, {
      signal: options.signal,
      onProgress: options.onProgress,
    });
    if (result.status === 'complete') {

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Re-run login and enter a bare hostname such as 'company.ghe.com' (or leave blank for github.com)
  2. Strip protocol, port, and path from the value you enter — only the domain is expected
  3. Verify the enterprise domain with your GitHub Enterprise admin; data-residency tenants use *.ghe.com

Example fix

// before (at prompt)
GitHub Enterprise URL/domain (blank for github.com): https://company.ghe.com/login/oauth
// after
GitHub Enterprise URL/domain (blank for github.com): company.ghe.com
Defensive patterns

Strategy: validation

Validate before calling

function normalizeDomain(input) {
  const host = input.trim().replace(/^https?:\/\//, '').split(/[/:?#]/)[0];
  return /^[a-zA-Z0-9]([a-zA-Z0-9-]*\.)*[a-zA-Z]{2,}$/.test(host) ? host : null;
}
// Pre-validate what you feed scripted/automated prompts:
const domain = normalizeDomain(userInput); // null => prompt again before calling login

Type guard

function isPlausibleDomain(v: unknown): v is string {
  return typeof v === 'string' && /^[a-zA-Z0-9]([a-zA-Z0-9-]*\.)*[a-zA-Z]{2,}$/.test(v);
}

Try / catch

try {
  await login('github-copilot');
} catch (err) {
  if (err instanceof Error && err.message === 'Invalid GitHub Enterprise URL/domain') {
    promptUserAgain('Enter a bare hostname like company.ghe.com, or leave blank');
  } else throw err;
}

Prevention

When it happens

Trigger: Entering a non-blank string at the 'GitHub Enterprise URL/domain' prompt that normalizeDomain cannot parse into a valid domain — e.g. 'my company', 'http://' with no host, or a malformed URL like 'https://ghe..com'.

Common situations: Typing the full web UI path (e.g. 'https://company.ghe.com/orgs/...') or trailing text/typos; pasting an SSO URL or a hostname with protocol, port, or path fragments that the normalizer rejects; confusion between github.com and GHE.com data-residency domains.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/026f329fb6720748. Report an issue: GitHub.