grafana/k6 · error

wrong status code (%d) for: %s

Error message

wrong status code (%d) for: %s

What it means

Raised in fetch when a remote module request returns any non-200 status other than 404 (e.g. 403 Forbidden, 500, 502). It means the server responded but refused or failed to serve the module. The at-fault inputs are the returned status code and the fetched URL.

Source

Thrown at internal/loader/loader.go:224

	startTime := time.Now()
	ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
	defer cancel()
	req, err := http.NewRequestWithContext(ctx, http.MethodGet, u, nil)
	if err != nil {
		return nil, err
	}
	res, err := http.DefaultClient.Do(req) //nolint:gosec
	if err != nil {
		return nil, err
	}
	defer func() { _ = res.Body.Close() }()

	if res.StatusCode != http.StatusOK {
		switch res.StatusCode {
		case http.StatusNotFound:
			return nil, fmt.Errorf("not found: %s", u)
		default:
			return nil, fmt.Errorf("wrong status code (%d) for: %s", res.StatusCode, u)
		}
	}

	data, err := io.ReadAll(res.Body)
	if err != nil {
		return nil, err
	}

	logger.WithFields(logrus.Fields{
		"url": u,
		"t":   time.Since(startTime),
		"len": len(data),
	}).Debug("Fetched!")
	return data, nil
}

View on GitHub (pinned to 01ffac6f24)

Solutions

  1. Check the status code to identify the cause: 403 may require auth headers, 5xx indicates a server problem
  2. Retry later for transient 5xx responses
  3. Serve the module from a different mirror or host it locally
  4. If auth is needed, use a URL/CDN that serves files publicly
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at internal/loader/loader.go:224 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18). Data as JSON: /api/errors/8b43023c256032f2. Report an issue: GitHub.