goharbor/harbor · error

failed to create request

Error message

failed to create request: %v

What it means

Wrapping error inside HTTPStatusCodeHealthChecker's CheckFunc: http.NewRequest failed while building the probe request, which only happens when the checker was configured with an invalid URL or unsupported HTTP method - a configuration-time defect, not a runtime endpoint failure.

Solutions

  1. Fix the URL passed to HTTPStatusCodeHealthChecker (must be absolute and well-formed).
  2. Use a valid HTTP method constant when constructing the checker.
  3. Verify configuration sources that supply the endpoint URL.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/controller/health/checker.go:44 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of goharbor/harbor@7b2fd08cc5 (2026-08-16). Data as JSON: /api/errors/7d8da380293af863. Report an issue: GitHub.

Appendix: source

Thrown at src/controller/health/checker.go:44

	"github.com/beego/beego/v2/client/orm"
	"github.com/docker/distribution/health"

	httputil "github.com/goharbor/harbor/src/common/http"
	"github.com/goharbor/harbor/src/common/utils"
	"github.com/goharbor/harbor/src/lib/cache"
	"github.com/goharbor/harbor/src/lib/config"
	"github.com/goharbor/harbor/src/lib/errors"
	"github.com/goharbor/harbor/src/lib/log"
)

// HTTPStatusCodeHealthChecker implements a Checker to check that the HTTP status code
// returned matches the expected one
func HTTPStatusCodeHealthChecker(method string, url string, header http.Header,
	timeout time.Duration, statusCode int) health.Checker {
	return health.CheckFunc(func() error {
		req, err := http.NewRequest(method, url, nil)
		if err != nil {
			return fmt.Errorf("failed to create request: %v", err)
		}
		for key, values := range header {
			for _, value := range values {
				req.Header.Add(key, value)
			}
		}

		client := httputil.NewClient(&http.Client{
			Transport: httputil.GetHTTPTransport(),
			Timeout:   timeout,
		})
		resp, err := client.Do(req)
		if err != nil {
			return fmt.Errorf("failed to check health: %v", err)
		}
		defer resp.Body.Close()
		if resp.StatusCode != statusCode {
			data, err := io.ReadAll(resp.Body)

View on GitHub (pinned to 7b2fd08cc5)