rancher/rancher · error

failed to get locations: %w

Error message

failed to get locations: %w

What it means

listLocations wraps any pager.NextPage failure from the subscriptions ListLocations call as HTTP 400 with %w. The cause is an ARM failure on /subscriptions/{id}/providers/locations: invalid or unreadable SubscriptionID, credential/tenant mismatch, throttling, or connectivity.

Source

Thrown at pkg/api/norman/customization/aks/listers.go:545

}

type locationsResponseBody struct {
	Name        string `json:"name"`
	DisplayName string `json:"displayName"`
}

func listLocations(ctx context.Context, cap *Capabilities) ([]byte, int, error) {
	client, err := NewSubscriptionServiceClient(cap)
	if err != nil {
		return nil, http.StatusInternalServerError, err
	}

	var locations []locationsResponseBody
	pager := client.NewListLocationsPager(cap.SubscriptionID, nil)
	for pager.More() {
		page, err := pager.NextPage(ctx)
		if err != nil {
			return nil, http.StatusBadRequest, fmt.Errorf("failed to get locations: %w", err)
		}

		for _, v := range page.Value {
			locations = append(locations, locationsResponseBody{
				Name:        to.String(v.Name),
				DisplayName: to.String(v.DisplayName),
			})
		}
	}

	return encodeOutput(locations)
}

type regionsResponseBody struct {
	Name              string `json:"name"`
	DisplayName       string `json:"displayName"`
	AvailabilityZones bool   `json:"availabilityZones"`
}

View on GitHub (pinned to 932558d4e6)

Solutions

  1. Inspect the wrapped azcore error for status and error code
  2. Verify the subscription ID: az account show -o json | jq -r .id
  3. Re-create the cloud credential with matching tenant/client/subscription
  4. Retry on 429/5xx; confirm egress to management.azure.com

Example fix

// before
pager := client.NewListLocationsPager(cap.SubscriptionID, nil)
// after - validate the subscription shape first
if !subscriptionIDRe.MatchString(cap.SubscriptionID) {
    return nil, http.StatusBadRequest, fmt.Errorf("invalid subscription ID %q", cap.SubscriptionID)
}
pager := client.NewListLocationsPager(cap.SubscriptionID, nil)
Defensive patterns

Strategy: retry

Validate before calling

# verifies read access to subscription locations before the call
az account list-locations --subscription $SUB -o table

Try / catch

var re *azcore.ResponseError
if errors.As(err, &re) {
	if re.StatusCode == 401 || re.StatusCode == 403 { /* credential/tenant mismatch */ }
	if re.StatusCode == 429 || re.StatusCode >= 500 { /* retry with backoff */ }
}

Prevention

When it happens

Trigger: cap.SubscriptionID empty or malformed so ARM 400s; credential from a different tenant than the subscription (401/403); secret expiry; ARM 429; egress blocked.

Common situations: Cloud credential created against the wrong directory; subscription ID copied with whitespace or braces; national-cloud credential used against global ARM.

Related errors


AI-assisted analysis of rancher/rancher@932558d4e6 (2026-08-16). Data as JSON: /api/errors/3a1135a3fac740c4. Report an issue: GitHub.