hashicorp/terraform · error

error parsing BitBucket URL: %s

Error message

error parsing BitBucket URL: %s

What it means

Returned by detectBitBucket (detect_git.go:82) when url.Parse fails after prepending 'https://' to a bitbucket.org/ source string. detectBitBucket assumes the remainder after 'bitbucket.org/' forms a valid https URL; if it contains characters net/url.Parse cannot handle, parsing fails and this error wraps the underlying parse error.

Source

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

		}

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

	return "", false, nil
}

// detectBitBucket detects shorthand schemeless references to bitbucket.org and
// translates them into git HTTP source addresses.
func detectBitBucket(src string) (string, bool, error) {
	if len(src) == 0 {
		return "", false, nil
	}

	if strings.HasPrefix(src, "bitbucket.org/") {
		u, err := url.Parse("https://" + src)
		if err != nil {
			return "", true, fmt.Errorf("error parsing BitBucket URL: %s", err)
		}

		// NOTE: A long, long time ago bitbucket.org repositories could
		// potentially be either Git or Mercurial repositories and we would've
		// needed to make an API call here to know which to generate.
		//
		// Thankfully BitBucket now only supports Git, and so we can just
		// assume all bitbucket.org strings are trying to refer to Git
		// repositories.

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

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

	return "", false, nil

View on GitHub (pinned to c9def3e214)

Solutions

  1. Trim whitespace and ensure only valid URL characters appear in the source after 'bitbucket.org/'.
  2. URL-encode special characters in repo/path segments.
  3. Use the explicit git URL form: source = "git::https://bitbucket.org/user/repo.git".
  4. Inspect the parse error detail in the message to find the offending character.

Example fix

# before — stray space in repo path
source = "bitbucket.org/user/my repo"

# after — valid bitbucket shorthand
source = "bitbucket.org/user/my-repo"
Defensive patterns

Strategy: validation

Validate before calling

// Pre-parse the assembled BitBucket URL to catch bad characters
func bitbucketURLParses(src string) bool {
    if !strings.HasPrefix(src, "bitbucket.org/") {
        return true
    }
    _, err := url.Parse("https://" + src)
    return err == nil
}

Type guard

func bitbucketURLParses(src string) bool {
    if !strings.HasPrefix(src, "bitbucket.org/") {
        return false
    }
    _, err := url.Parse("https://" + src)
    return err == nil
}

Prevention

When it happens

Trigger: A module source starting with 'bitbucket.org/' whose remainder contains characters that make 'https://' + src unparseable (spaces, control characters, malformed percent-encoding, embedded newlines).

Common situations: Copy-paste of a BitBucket URL with stray whitespace, quotes, or special characters in the repo/path. Non-ASCII path segments. A source string accidentally including a scheme or malformed query string.

Related errors


AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07). Data as JSON: /api/errors/3e874d81ef5a938e. Report an issue: GitHub.