hashicorp/terraform · error

error parsing GitHub URL

Error message

error parsing GitHub URL: %s

What it means

Returned by detectGitHub when url.Parse rejects the synthesized 'https://github.com/<user>/<repo>' URL. Since the parts already passed the length check, a parse failure means the username or repo segment contains characters illegal in a URL host/path. The %s is the url.Parse error.

Solutions

  1. Verify the username/repo contains only valid URL path characters.
  2. Use the explicit git::https:// form with a known-good URL.
  3. URL-encode any unusual characters or, better, rename the repo.

Example fix

# before (space -> parse fails)
source = "github.com/my org/repo"

# after
source = "github.com/my-org/repo"
Defensive patterns

Strategy: validation

Validate before calling

// Reject GitHub sources with URL-illegal characters before detection.
// func validGitHubChars(user, repo string) error {
//     for _, s := range []string{user, repo} {
//         if strings.ContainsAny(s, " \t\n\r") { return fmt.Errorf("invalid char in %q", s) }
//     }
//     return nil
// }

Prevention

When it happens

Trigger: A GitHub username or repo name with control characters, spaces, or invalid percent-encoding is concatenated into the URL and url.Parse fails.

Common situations: Raw spaces or non-ASCII characters in the path; pasted URL with stray characters; malformed query string from a copy mistake.

Related errors


AI-assisted analysis of hashicorp/terraform@d32a084675 (2026-08-11). Data as JSON: /api/errors/a38787470dded6a2. Report an issue: GitHub.

Appendix: source

Thrown at internal/getmodules/moduleaddrs/detect_git.go:54

// translates them into git HTTP source addresses.
func detectGitHub(src string) (string, bool, error) {
	if len(src) == 0 {
		return "", false, nil
	}

	if strings.HasPrefix(src, "github.com/") {
		src, rawQuery, _ := strings.Cut(src, "?")

		parts := strings.Split(src, "/")
		if len(parts) < 3 {
			return "", false, fmt.Errorf(
				"GitHub URLs should be github.com/username/repo")
		}

		urlStr := fmt.Sprintf("https://%s", strings.Join(parts[:3], "/"))
		url, err := url.Parse(urlStr)
		if err != nil {
			return "", true, fmt.Errorf("error parsing GitHub URL: %s", err)
		}
		url.RawQuery = rawQuery

		if !strings.HasSuffix(url.Path, ".git") {
			url.Path += ".git"
		}

		if len(parts) > 3 {
			url.Path += "//" + strings.Join(parts[3:], "/")
		}

		return "git::" + url.String(), true, nil
	}

	return "", false, nil
}

// detectBitBucket detects shorthand schemeless references to bitbucket.org and

View on GitHub (pinned to d32a084675)