golang-migrate/migrate · error
invalid repo
Error message
invalid repo
What it means
github.ErrInvalidRepo is returned by Github.Open when the URL path yields no repo segment after trimming slashes (len(pe) < 1). The driver expects 'github://host/owner/repo/...path' and needs at least one path element to use as the repo.
Source
Thrown at source/github/github.go:26
nurl "net/url"
"os"
"path"
"strings"
"golang.org/x/oauth2"
"github.com/golang-migrate/migrate/v4/source"
"github.com/google/go-github/v39/github"
)
func init() {
source.Register("github", &Github{})
}
var (
ErrNoUserInfo = fmt.Errorf("no username:token provided")
ErrNoAccessToken = fmt.Errorf("no access token")
ErrInvalidRepo = fmt.Errorf("invalid repo")
ErrInvalidGithubClient = fmt.Errorf("expected *github.Client")
ErrNoDir = fmt.Errorf("no directory")
)
type Github struct {
config *Config
client *github.Client
options *github.RepositoryContentGetOptions
migrations *source.Migrations
}
type Config struct {
Owner string
Repo string
Path string
Ref string
}
View on GitHub (pinned to 01a9643f14)
Solutions
- Include owner and repo in the URL path: 'github://user:token@github.com/owner/repo/path/to/migrations'
- Note the driver maps path element 0 to Repo (Owner comes from u.Host) — structure the URL accordingly
- Validate the URL contains a non-empty path before calling Open
Example fix
// before
source.Open("github://user:token@github.com/")
// after
source.Open("github://user:token@github.com/owner/repo/migrations") Defensive patterns
Strategy: validation
Validate before calling
u, err := url.Parse(sourceURL)
if err != nil {
return err
}
pe := strings.Split(strings.Trim(u.Path, "/"), "/")
if len(pe) < 1 || pe[0] == "" {
return fmt.Errorf("github source url must include a repo path: github://token@github.com/owner/repo")
} Type guard
func hasRepoInPath(raw string) bool {
u, err := url.Parse(raw)
return err == nil && strings.Trim(u.Path, "/") != ""
} Try / catch
d, err := source.Open(srcURL)
if err != nil {
if errors.Is(err, source_github.ErrInvalidRepo) {
return fmt.Errorf("source url %q missing repo path segment", srcURL)
}
return err
} Prevention
- Template the full host/owner/repo/path URL and validate placeholders were filled
- Remember owner comes from host, repo from first path segment in this driver
- Test URL construction with a unit test before deployment
When it happens
Trigger: Open('github://token@github.com/') or 'github://token@github.com' — empty path — so strings.Split of the trimmed path returns fewer than 1 element.
Common situations: URL templates where owner/repo placeholders were not filled; trailing-slash-only paths; copying only the host from a repo URL and dropping the path.
Related errors
AI-assisted analysis of golang-migrate/migrate@01a9643f14 (2026-09-02).
Data as JSON: /api/errors/83374242249eb762.
Report an issue: GitHub.