go-kratos/kratos · error

unable to parse repo url

Error message

unable to parse repo url

What it means

Thrown by the kratos CLI helper base.ParseVCSUrl (cmd/kratos/internal/base/vcs_url.go:57). The function normalizes a VCS repo string (SCP-like 'git@host:path', bare 'host/path', or a full URL) into a *url.URL, then accepts it only if the resulting scheme is one of git, https, http, git+ssh, ssh, file, ftp, ftps. This error means the normalized URL's scheme is not in that allowlist, so the CLI refuses to treat the string as a repo URL.

Source

Thrown at cmd/kratos/internal/base/vcs_url.go:57

			repo = "ssh:" + repo
		} else if strings.HasPrefix(repo, "//") {
			repo = "https:" + repo
		}
		repoURL, err = url.Parse(repo)
		if err != nil {
			return nil, err
		}
	}

	// Iterate over insecure schemes too, because this function simply
	// reports the state of the repo. If we can't see insecure schemes then
	// we can't report the actual repo URL.
	for _, s := range scheme {
		if repoURL.Scheme == s {
			return repoURL, nil
		}
	}
	return nil, errors.New("unable to parse repo url")
}

View on GitHub (pinned to 668db92c2c)

Solutions

  1. Rewrite the repo string as a full https URL, e.g. 'https://github.com/user/repo.git'
  2. Or use SCP-like syntax 'git@github.com:user/repo.git' which the scpSyntaxRe converts to ssh://
  3. Remove unsupported scheme prefixes (svn, rsync, git+https, git+http) before calling the CLI
  4. Verify the URL with 'git ls-remote <url>' before passing it to the CLI
  5. Upgrade the kratos CLI in case the scheme allowlist was extended

Example fix

// before
repoURL, err := base.ParseVCSUrl("git+https://github.com/go-kratos/kratos.git")
// err = unable to parse repo url

// after
repoURL, err := base.ParseVCSUrl("https://github.com/go-kratos/kratos.git")
// or SCP-like:
repoURL, err := base.ParseVCSUrl("git@github.com:go-kratos/kratos.git")
Defensive patterns

Strategy: validation

Validate before calling

var allowedSchemes = map[string]bool{"git":true,"https":true,"http":true,"git+ssh":true,"ssh":true,"file":true,"ftp":true,"ftps":true}

func validRepoURL(repo string) bool {
    u, err := url.Parse(repo)
    if err != nil { return false }
    if u.Scheme == "" { // scp-like or bare host/path; both are accepted forms
        return true
    }
    return allowedSchemes[u.Scheme]
}

Prevention

When it happens

Trigger: Calling base.ParseVCSUrl (used by 'kratos repo add' / other CLI repo handling) with a string whose scheme is unsupported: 'git+https://github.com/user/repo.git' (git+https is NOT in the list), 'svn://...' , 'rsync://...', or a malformed string that url.Parse maps to an empty/unknown scheme. Full https URLs and SCP-like 'git@github.com:user/repo' forms succeed; those are the only shapes guaranteed to pass.

Common situations: Typo'd or exotic scheme in the repo argument of a kratos CLI command; using the 'git+https' alias that Go's own vcs code accepts but this allowlist does not; passing a Windows path like 'c:/src/repo' which parses with an unexpected scheme; older kratos CLI versions with a shorter allowlist.

Understand the failure class

Related errors


AI-assisted analysis of go-kratos/kratos@668db92c2c (2026-08-16). Data as JSON: /api/errors/640114935d33fc16. Report an issue: GitHub.