charmbracelet/glow · error

HTTP status %d

Error message

HTTP status %d

What it means

After a successful GET, glow requires exactly http.StatusOK; any other final status code becomes this error with the numeric code. http.Get follows redirects automatically, so the reported code is that of the last response in the chain. The message shows only the number, not the reason phrase or URL, so the operator must map the code to a cause themselves.

Source

Thrown at main.go:99

	src, err := readmeURL(arg)
	if src != nil && err == nil {
		// if there's an error, try next methods...
		return src, nil
	}

	// HTTP(S) URLs:
	if u, err := url.ParseRequestURI(arg); err == nil && strings.Contains(arg, "://") { //nolint:nestif
		if u.Scheme != "" {
			if u.Scheme != "http" && u.Scheme != "https" {
				return nil, fmt.Errorf("%s is not a supported protocol", u.Scheme)
			}
			// consumer of the source is responsible for closing the ReadCloser.
			resp, err := http.Get(u.String()) //nolint: noctx,bodyclose
			if err != nil {
				return nil, fmt.Errorf("unable to get url: %w", err)
			}
			if resp.StatusCode != http.StatusOK {
				return nil, fmt.Errorf("HTTP status %d", resp.StatusCode)
			}
			return &source{resp.Body, u.String()}, nil
		}
	}

	// a directory:
	if len(arg) == 0 {
		// use the current working dir if no argument was supplied
		arg = "."
	}
	st, err := os.Stat(arg)
	if err == nil && st.IsDir() { //nolint:nestif
		var src *source
		_ = filepath.Walk(arg, func(path string, _ os.FileInfo, err error) error {
			if err != nil {
				return err
			}
			for _, v := range readmeNames {

View on GitHub (pinned to e3970c813d)

Solutions

  1. Open the URL with curl -I to confirm which status is returned
  2. 404: fix the URL; 403: check auth/hotlinking/expiry; 429: wait and retry
  3. 5xx: retry later - it is a server-side problem
  4. If a redirect target fails, fetch the final URL directly

Example fix

// before
if resp.StatusCode != http.StatusOK {
	return nil, fmt.Errorf("HTTP status %d", resp.StatusCode)
}

// after
if resp.StatusCode != http.StatusOK {
	return nil, fmt.Errorf("GET %s: %s", u.String(), resp.Status)
}
Defensive patterns

Strategy: validation

Validate before calling

func urlReturns200(raw string) error {
	res, err := http.Head(raw) //nolint:noctx
	if err != nil { return err }
	defer res.Body.Close()
	if res.StatusCode != http.StatusOK {
		return fmt.Errorf("precheck: %s for %s", res.Status, raw)
	}
	return nil
}

Prevention

When it happens

Trigger: 404 for a wrong URL; 403 from hotlink protection, WAF rules, or expired presigned URLs; 429 rate limiting (common when fetching GitHub raw content); 5xx server errors; 204 from API endpoints that return no content.

Common situations: Stale documentation links, GitHub rate limits on raw.githubusercontent.com, expired S3 presigned URLs, origin-server outages behind a CDN.

Related errors


AI-assisted analysis of charmbracelet/glow@e3970c813d (2026-08-15). Data as JSON: /api/errors/3bf308f8c3434651. Report an issue: GitHub.