google-gemini/gemini-cli · error · Error

Invalid GitHub repository source: ${source}. Expected "owner

Error message

Invalid GitHub repository source: ${source}. Expected "owner/repo" or a github repo uri.

What it means

Thrown by tryParseGithubUrl() when the URL parses and is on github.com but the pathname does not split into exactly two non-empty segments (owner/repo). Sources with one segment (just 'owner') or three+ (owner/repo/extra/path) both fail this check.

Source

Thrown at packages/cli/src/config/extensions/github.ts:122

    // Throw a TypeError to maintain a consistent error contract for invalid URLs.
    // This avoids a breaking change for consumers who might expect a TypeError.
    throw new TypeError(`Invalid repo URL: ${source}`, { cause: e });
  }

  if (!parsedUrl) {
    throw new Error(`Invalid repo URL: ${source}`);
  }
  if (parsedUrl?.host !== 'github.com') {
    return null;
  }
  // The pathname should be "/owner/repo".
  const parts = parsedUrl?.pathname
    .split('/')
    // Remove the empty segments, fixes trailing and leading slashes
    .filter((part) => part !== '');

  if (parts?.length !== 2) {
    throw new Error(
      `Invalid GitHub repository source: ${source}. Expected "owner/repo" or a github repo uri.`,
    );
  }
  const owner = parts[0];
  const repo = parts[1].replace('.git', '');

  return {
    owner,
    repo,
  };
}

export async function fetchReleaseFromGithub(
  owner: string,
  repo: string,
  ref?: string,
  allowPreRelease?: boolean,
): Promise<GithubReleaseData | null> {

View on GitHub (pinned to 5024443c72)

Solutions

  1. Use the bare 'owner/repo' shorthand or the repository root URL.
  2. If you must accept deep links, pre-process the URL to keep only the first two path segments.
  3. Validate the segment count before calling and surface a friendly message.

Example fix

// before
const info = tryParseGithubUrl('owner/repo/blob/main/file.ts');
// after
const info = tryParseGithubUrl('owner/repo');
Defensive patterns

Strategy: validation

Validate before calling

function githubPathSegments(source: string): string[] | null {
  try { const u = new URL(source, 'https://github.com'); if (u.host !== 'github.com') return null; return u.pathname.split('/').filter(Boolean); } catch { return null; }
}

Type guard

function isOwnerRepoPair(segments: string[]): boolean { return segments.length === 2; }

Try / catch

try { tryParseGithubUrl(src); } catch (e) { if (/Expected "owner\/repo"/.test(String(e))) { /* suggest using repo root URL */ } throw e; }

Prevention

When it happens

Trigger: Source like 'someuser' (one segment), 'owner/repo/tree/main' (extra path segments), or a github URL pointing at a non-repo page (e.g., a gist or a settings page) whose pathname has more than two parts.

Common situations: User pastes a URL to a file inside a repo (owner/repo/blob/main/x.ts) instead of the repo root; mistyped shorthand missing the repo name; trailing slashes combined with extra path.

Related errors


AI-assisted analysis of google-gemini/gemini-cli@5024443c72 (2026-08-12). Data as JSON: /api/errors/e8941ce5fb69ec3a. Report an issue: GitHub.