{"record":{"id":"026f329fb6720748","repo":"mastra-ai/mastra","slug":"invalid-github-enterprise-url-domain","errorCode":null,"errorMessage":"Invalid GitHub Enterprise URL/domain","messagePattern":"Invalid GitHub Enterprise URL/domain","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mastracode/sdk/src/auth/providers/github-copilot.ts","lineNumber":397,"sourceCode":"  onAuth: (url: string, instructions?: string) => void;\n  onPrompt: (prompt: { message: string; placeholder?: string; allowEmpty?: boolean }) => Promise<string>;\n  onProgress?: (message: string) => void;\n  signal?: AbortSignal;\n}): Promise<GitHubCopilotCredentials> {\n  const input = await options.onPrompt({\n    message: 'GitHub Enterprise URL/domain (blank for github.com)',\n    placeholder: 'company.ghe.com',\n    allowEmpty: true,\n  });\n\n  if (options.signal?.aborted) {\n    throw new Error('Login cancelled');\n  }\n\n  const trimmed = input.trim();\n  const enterpriseDomain = normalizeDomain(input);\n  if (trimmed && !enterpriseDomain) {\n    throw new Error('Invalid GitHub Enterprise URL/domain');\n  }\n  let pending = await startGitHubCopilotDeviceLogin(enterpriseDomain ?? undefined, { signal: options.signal });\n  options.onAuth(pending.url, pending.instructions);\n\n  while (true) {\n    if (options.signal?.aborted) {\n      throw new Error('Login cancelled');\n    }\n\n    // Wait before polling (safety margin over the server interval), clamped to the deadline.\n    const remainingMs = Math.max(pending.deadlineAt - Date.now(), 0);\n    await abortableSleep(Math.min(copilotNextPollDelayMs(pending), remainingMs), options.signal);\n\n    const result = await pollGitHubCopilotDeviceLogin(pending, {\n      signal: options.signal,\n      onProgress: options.onProgress,\n    });\n    if (result.status === 'complete') {","sourceCodeStart":379,"sourceCodeEnd":415,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/sdk/src/auth/providers/github-copilot.ts#L379-L415","documentation":"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.","triggerScenarios":"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'.","commonSituations":"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.","solutions":["Re-run login and enter a bare hostname such as 'company.ghe.com' (or leave blank for github.com)","Strip protocol, port, and path from the value you enter — only the domain is expected","Verify the enterprise domain with your GitHub Enterprise admin; data-residency tenants use *.ghe.com"],"exampleFix":"// before (at prompt)\nGitHub Enterprise URL/domain (blank for github.com): https://company.ghe.com/login/oauth\n// after\nGitHub Enterprise URL/domain (blank for github.com): company.ghe.com","handlingStrategy":"validation","validationCode":"function normalizeDomain(input) {\n  const host = input.trim().replace(/^https?:\\/\\//, '').split(/[/:?#]/)[0];\n  return /^[a-zA-Z0-9]([a-zA-Z0-9-]*\\.)*[a-zA-Z]{2,}$/.test(host) ? host : null;\n}\n// Pre-validate what you feed scripted/automated prompts:\nconst domain = normalizeDomain(userInput); // null => prompt again before calling login","typeGuard":"function isPlausibleDomain(v: unknown): v is string {\n  return typeof v === 'string' && /^[a-zA-Z0-9]([a-zA-Z0-9-]*\\.)*[a-zA-Z]{2,}$/.test(v);\n}","tryCatchPattern":"try {\n  await login('github-copilot');\n} catch (err) {\n  if (err instanceof Error && err.message === 'Invalid GitHub Enterprise URL/domain') {\n    promptUserAgain('Enter a bare hostname like company.ghe.com, or leave blank');\n  } else throw err;\n}","preventionTips":["Enter only the bare hostname (no protocol, port, or path) at the prompt","Leave the prompt blank when using github.com","Confirm the exact GHE.com / GHE domain with your enterprise admin before automating the prompt"],"tags":["auth","validation","input","github-enterprise"],"backgroundTag":"invalid-input-validation","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}