gastownhall/beads · error
invalid URL: %w
Error message
invalid URL: %w
What it means
canonicalizeGitURL parses URLs containing "://" with net/url to normalize them for fingerprinting. If url.Parse rejects the string, the parse error is wrapped as "invalid URL". This indicates the git remote value is not a syntactically valid absolute URL.
Source
Thrown at internal/beads/fingerprint.go:83
}
repoURL := strings.TrimSpace(string(output))
canonical, err := canonicalizeGitURL(repoURL)
if err != nil {
return "", "", fmt.Errorf("failed to canonicalize URL: %w", err)
}
hash := sha256.Sum256([]byte(canonical))
return hex.EncodeToString(hash[:16]), RepoIDSourceRemote, nil
}
func canonicalizeGitURL(rawURL string) (string, error) {
rawURL = strings.TrimSpace(rawURL)
if strings.Contains(rawURL, "://") {
u, err := url.Parse(rawURL)
if err != nil {
return "", fmt.Errorf("invalid URL: %w", err)
}
host := strings.ToLower(u.Hostname())
if port := u.Port(); port != "" && port != "22" && port != "80" && port != "443" {
host = host + ":" + port
}
path := strings.TrimRight(u.Path, "/")
path = strings.TrimSuffix(path, ".git")
path = filepath.ToSlash(path)
return host + path, nil
}
// Detect scp-style URLs: [user@]host:path
// Must contain ":" before any "/" and not be a Windows path
colonIdx := strings.Index(rawURL, ":")
slashIdx := strings.Index(rawURL, "/")View on GitHub (pinned to 71377f2769)
Solutions
- Run `git remote set-url origin <valid-url>` with a correctly formed URL
- Validate the URL first (paste it into a browser or `python3 -c "import urllib.parse;urllib.parse.urlparse('...')"`)
- Strip whitespace/control characters before configuring the remote
- Check for shell quoting issues that embedded stray characters into .git/config
Example fix
// before git remote set-url origin "https://github.com/acme/repo.git " // after git remote set-url origin "$(echo 'https://github.com/acme/repo.git' | tr -d '[:space:]')"
Defensive patterns
Strategy: validation
Validate before calling
_, err := url.Parse(rawRemote)
if err != nil {
// remote URL invalid; fix before calling bd APIs
} Try / catch
id, err := beads.ComputeRepoIDForPath(path)
if err != nil && strings.Contains(err.Error(), "invalid URL") {
return fmt.Errorf("remote URL unparseable; re-set it: %w", err)
} Prevention
- Validate remote URLs with url.Parse before configuring them
- Quote URLs in shell to avoid embedded stray characters
- Use standard URL forms (https://host/path) for remotes
- Audit .git/config after pasting URLs from terminals
When it happens
Trigger: ComputeRepoIDForPathWithSource → canonicalizeGitURL with a remote URL that contains "://" but fails url.Parse (invalid characters, malformed scheme/authority, control characters). Also directly exercised by TestCanonicalizeGitURL_Whitespace with malformed inputs.
Common situations: Typos like `https://git hub.com/repo` (space in host); stray characters or trailing whitespace/control chars from shell paste; a non-URL string in the remote slot that happens to contain "://".
Related errors
- unexpected git rev-parse output
- failed to canonicalize URL: %w
- not a git repository
- failed to install hooks: %w
- git config --unset core.hooksPath failed: %w (output: %s)
AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30).
Data as JSON: /api/errors/94cfb89d719e674b.
Report an issue: GitHub.