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
- Use the bare 'owner/repo' shorthand or the repository root URL.
- If you must accept deep links, pre-process the URL to keep only the first two path segments.
- 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
- Store/accept the repo-root URL or 'owner/repo' shorthand, not deep file links.
- Pre-slice deep links to the first two path segments.
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
- Invalid repo URL: ${source}
- Invalid scope: ${argv.scope}. Please use one of ${Object.val
- Invalid scope: ${argv.scope}. Please use one of ${Object.val
- Invalid regex pattern in allowedExtensions setting: "${patte
- Installing extensions from remote sources is disallowed by y
AI-assisted analysis of google-gemini/gemini-cli@5024443c72 (2026-08-12).
Data as JSON: /api/errors/e8941ce5fb69ec3a.
Report an issue: GitHub.