charmbracelet/glow · error
invalid url: %s
Error message
invalid url: %s
What it means
findGitLabREADME mirrors the GitHub path parsing: it cuts the trimmed URL path on the first '/' to get owner and project. With fewer than two path segments, ok is false and this error reports the full URL before any request is made. It is a URL-shape validation failure only.
Source
Thrown at gitlab.go:17
package main
import (
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
"net/url"
"strings"
)
// findGitLabREADME tries to find the correct README filename in a repository using GitLab API.
func findGitLabREADME(u *url.URL) (*source, error) {
owner, repo, ok := strings.Cut(strings.TrimPrefix(u.Path, "/"), "/")
if !ok {
return nil, fmt.Errorf("invalid url: %s", u.String())
}
projectPath := url.QueryEscape(owner + "/" + repo)
type readme struct {
ReadmeURL string `json:"readme_url"`
}
apiURL := fmt.Sprintf("https://%s/api/v4/projects/%s", u.Hostname(), projectPath)
//nolint:bodyclose
// it is closed on the caller
res, err := http.Get(apiURL) //nolint: gosec,noctx
if err != nil {
return nil, fmt.Errorf("unable to get url: %w", err)
}
body, err := io.ReadAll(res.Body)View on GitHub (pinned to e3970c813d)
Solutions
- Use the full project URL: https://gitlab.com/OWNER/PROJECT
- When constructing URLs in code, require both owner and project to be non-empty
- Navigate into an actual project page before copying the URL
Example fix
# before glow https://gitlab.com/mygroup # group page, no project # after glow https://gitlab.com/mygroup/myproject
Defensive patterns
Strategy: type-guard
Type guard
func isGitLabProjectURL(u *url.URL) bool {
if u == nil || (u.Host != "gitlab.com" && !strings.HasSuffix(u.Host, ".gitlab.com")) {
return false
}
_, _, ok := strings.Cut(strings.TrimPrefix(u.Path, "/"), "/")
return ok
}
if !isGitLabProjectURL(u) {
return fmt.Errorf("expected https://gitlab.com/OWNER/PROJECT, got %s", u)
} Try / catch
src, err := findGitLabREADME(u)
if err != nil && strings.Contains(err.Error(), "invalid url") {
// deterministic shape failure — do not retry; request a proper project URL
return nil, fmt.Errorf("need owner/project URL like https://gitlab.com/OWNER/PROJECT: %w", err)
}
return src, err Prevention
- Require both owner and project segments when constructing GitLab URLs programmatically
- Copy URLs from a project page, not a group/profile page
- Unit-test URL builders with table-driven cases: empty repo, single segment, trailing slash
When it happens
Trigger: Passing https://gitlab.com alone; a user or group page like https://gitlab.com/mygroup; a project URL with an empty project segment; hand-built URLs where the project component is blank.
Common situations: Copying a group/subgroup landing page instead of a project; scripts templating the project field from an empty variable; truncated pastes.
Related errors
- invalid url: %s
- unable to parse url: %w
- %s is not a supported protocol
- can't find README in GitLab repository
- cannot use both pager and tui
AI-assisted analysis of charmbracelet/glow@e3970c813d (2026-08-15).
Data as JSON: /api/errors/c549c1ebf003daf0.
Report an issue: GitHub.