lima-vm/lima · error

failed to fetch file: %w

Error message

failed to fetch file: %w

What it means

resolveGitHubSymlink fetches the candidate .yaml file via getGitHubUserContent (raw.githubusercontent.com). If the HTTP request itself fails at the transport level (DNS failure, connection refused, TLS error, context cancellation), the error is wrapped as "failed to fetch file: %w". This is a network/transport failure, not an HTTP status problem.

Source

Thrown at pkg/limatmpl/github.go:155

	var repoData struct {
		DefaultBranch string `json:"default_branch"`
	}
	if err := json.Unmarshal(body, &repoData); err != nil {
		return "", fmt.Errorf("failed to parse GitHub API response: %w", err)
	}
	if repoData.DefaultBranch == "" {
		return "", fmt.Errorf("repository %s/%s has no default branch", org, repo)
	}
	return repoData.DefaultBranch, nil
}

// resolveGitHubSymlink checks if a file at the given path is a symlink/redirect to another file.
// If the file contains a single line without newline, space, or colon then it's treated as a path to the actual file.
// Returns a URL to the redirect path if found, or a URL for original path otherwise.
func resolveGitHubSymlink(ctx context.Context, org, repo, branch, filePath, origBranch string) (string, error) {
	resp, err := getGitHubUserContent(ctx, org, repo, branch, filePath)
	if err != nil {
		return "", fmt.Errorf("failed to fetch file: %w", err)
	}
	defer resp.Body.Close()

	// Special rule for branch/tag propagation for github:ORG// requests.
	if resp.StatusCode == http.StatusNotFound && repo == org {
		defaultBranch, err := getGitHubDefaultBranch(ctx, org, repo)
		if err == nil {
			return resolveGitHubRedirect(ctx, org, repo, defaultBranch, filePath, branch)
		}
	}
	if resp.StatusCode != http.StatusOK {
		return "", fmt.Errorf("file %#q not found or inaccessible: status %d", resp.Request.URL, resp.StatusCode)
	}

	// Read first 1KB to check the file content
	buf := make([]byte, 1024)
	n, err := resp.Body.Read(buf)
	if err != nil && !errors.Is(err, io.EOF) {

View on GitHub (pinned to dd909d0973)

Solutions

  1. Check basic connectivity: `curl -I https://raw.githubusercontent.com`
  2. Configure proxy environment variables (HTTPS_PROXY/HTTP_PROXY) if behind a corporate firewall
  3. Retry the command; transient DNS or connection failures often resolve
  4. If the context was cancelled, increase the timeout or rerun without interruption

Example fix

// before
export HTTPS_PROXY=
// after
export HTTPS_PROXY=http://proxy.corp.example:3128
Defensive patterns

Strategy: retry

Validate before calling

// preflight connectivity check
if _, err := http.Get("https://raw.githubusercontent.com"); err != nil {
    return fmt.Errorf("cannot reach raw.githubusercontent.com: %w", err)
}

Try / catch

url, err := transformGitHubURL(ctx, ref)
if err != nil && strings.Contains(err.Error(), "failed to fetch file") {
    // retry with backoff
    for i := 0; i < 3; i++ {
        time.Sleep(time.Duration(1<<i) * time.Second)
        if url, err = transformGitHubURL(ctx, ref); err == nil { break }
    }
}

Prevention

When it happens

Trigger: transformGitHubURL -> resolveGitHubSymlink -> getGitHubUserContent where http.DefaultClient.Do returns a non-nil error: no network connectivity, DNS resolution failure for raw.githubusercontent.com, blocked egress, expired TLS, or the caller's context being cancelled.

Common situations: Running limactl offline or behind a corporate proxy without HTTP_PROXY configured; firewall blocking raw.githubusercontent.com; IPv6 misconfiguration; context deadline exceeded on slow networks.

Understand the failure class

Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.

Related errors


AI-assisted analysis of lima-vm/lima@dd909d0973 (2026-09-01). Data as JSON: /api/errors/575ee0e531e66e96. Report an issue: GitHub.