cloudflare/cloudflared · error

ErrNoBaseURL

ErrNoBaseURL

Error message

no base url

What it means

ErrNoBaseURL is returned by the diagnostic httpClient's GET method when a request is attempted while client.baseURL is nil. The diagnostic client was constructed without a base URL, so no endpoint can be resolved. It indicates a client configuration/initialization mistake, not a network failure.

Source

Thrown at diagnostic/error.go:21

import (
	"errors"
)

var (
	// Error used when there is no log directory available.
	ErrManagedLogNotFound = errors.New("managed log directory not found")
	// Error used when it is not possible to collect logs using the log configuration.
	ErrLogConfigurationIsInvalid = errors.New("provided log configuration is invalid")
	// Error used when parsing the fields of the output of collector.
	ErrInsufficientLines = errors.New("insufficient lines")
	// Error used when parsing the lines of the output of collector.
	ErrInsuficientFields = errors.New("insufficient fields")
	// Error used when given key is not found while parsing KV.
	ErrKeyNotFound = errors.New("key not found")
	// Error used when there is no disk volume information available.
	ErrNoVolumeFound = errors.New("no disk volume information found")
	// Error user when the base url of the diagnostic client is not provided.
	ErrNoBaseURL = errors.New("no base url")
	// Error used when no metrics server is found listening to the known addresses list (check [metrics.GetMetricsKnownAddresses]).
	ErrMetricsServerNotFound = errors.New("metrics server not found")
	// Error used when multiple metrics server are found listening to the known addresses list (check [metrics.GetMetricsKnownAddresses]).
	ErrMultipleMetricsServerFound = errors.New("multiple metrics server found")
	// Error used when a temporary file creation fails within the diagnostic procedure
	ErrCreatingTemporaryFile = errors.New("temporary file creation failed")
)

View on GitHub (pinned to 2253eeeb25)

Solutions

  1. Build the client with a valid base URL (e.g. from FindMetricsServer results) before issuing requests.
  2. Check for nil URL when constructing the client and fail fast at construction time.
  3. Ensure the metrics server discovery step succeeded and returned at least one instance address.
  4. Guard call sites with a nil check on the client's base URL before calling GET.

Example fix

// before
client := diagnostic.NewHTTPClient(nil, logger)
resp, err := client.GET(ctx, diagnostic.TunnelStateEndpoint)
// after
if baseURL == nil {
	return errors.New("diagnostic client requires a base URL")
}
client := diagnostic.NewHTTPClient(baseURL, logger)
resp, err := client.GET(ctx, diagnostic.TunnelStateEndpoint)
Defensive patterns

Strategy: validation

Validate before calling

if client == nil || client.BaseURL() == nil {
	return errors.New("diagnostic client has no base URL configured")
}

Type guard

func hasBaseURL(c *diagnostic.HTTPClient) bool {
	return c != nil && c.BaseURL() != nil
}

Try / catch

resp, err := client.GET(ctx, endpoint)
if errors.Is(err, diagnostic.ErrNoBaseURL) {
	return fmt.Errorf("diagnostic client misconfigured: %w", err)
}

Prevention

When it happens

Trigger: Calling GET (directly or via diagnostic client operations like RetrieveAppState or tunnel data retrieval) on a diagnostic httpClient created without a base URL — e.g. FindMetricsServer produced no usable address or the client was built with a nil *url.URL.

Common situations: Constructing diagnostic.NewHTTPClient with a nil URL after metrics discovery failed, reusing a zero-value client struct, or skipping the metrics-server lookup step before making diagnostic requests.

Understand the failure class

Background: "X is required", "must be set", "cannot be empty": the missing-required-config error family, from Vertex AI project/location to WeChat keys — this error's family across 18 libraries.

Related errors


AI-assisted analysis of cloudflare/cloudflared@2253eeeb25 (2026-09-06). Data as JSON: /api/errors/7afa381d11a49c94. Report an issue: GitHub.