VictoriaMetrics/VictoriaMetrics · error

cannot parse organizations response from %q: %w; response bo

Error message

cannot parse organizations response from %q: %w; response body: %s

What it means

getOrganizations received a response but json.Unmarshal failed to decode it into organizationsPage ({organizations, nextPageToken}). The URL and full response body are included in the message. Indicates the body was not the expected JSON document.

Source

Thrown at lib/promscrape/discovery/yandexcloud/yandexcloud.go:220

	ID             string            `json:"id"`
	Labels         map[string]string `json:"labels"`
	OrganizationID string            `json:"organizationId"`
	Description    string            `json:"description"`
	CreatedAt      time.Time         `json:"createdAt"`
}

func (cfg *apiConfig) getOrganizations() ([]organization, error) {
	orgsURL := cfg.serviceEndpoints["organization-manager"] + "/organization-manager/v1/organizations"
	var orgs []organization
	nextLink := orgsURL
	for {
		data, err := getAPIResponse(nextLink, cfg)
		if err != nil {
			return nil, fmt.Errorf("cannot get organizations: %w", err)
		}
		var op organizationsPage
		if err := json.Unmarshal(data, &op); err != nil {
			return nil, fmt.Errorf("cannot parse organizations response from %q: %w; response body: %s", nextLink, err, data)
		}
		orgs = append(orgs, op.Organizations...)
		if len(op.NextPageToken) == 0 {
			return orgs, nil
		}
		nextLink = orgsURL + "&pageToken=" + url.QueryEscape(op.NextPageToken)
	}
}

// See https://cloud.yandex.com/en-ru/docs/organization/api-ref/Organization/list
type organizationsPage struct {
	Organizations []organization `json:"organizations"`
	NextPageToken string         `json:"nextPageToken"`
}

type organization struct {
	Name        string            `json:"name"`
	ID          string            `json:"id"`

View on GitHub (pinned to 5079fb58f1)

Solutions

  1. Examine the embedded response body to see what was actually returned
  2. If it's an error envelope, fix auth/permissions indicated there
  3. Bypass any HTTP proxy or fix its configuration so raw JSON arrives
  4. Upgrade VictoriaMetrics if the Yandex API response format changed
Defensive patterns

Strategy: validation

Validate before calling

var probe struct{ Organizations []json.RawMessage `json:"organizations"` }
if err := json.Unmarshal(body, &probe); err != nil {
	log.Printf("unexpected org response: %.200s", body)
}

Type guard

func looksLikeOrganizationsPage(b []byte) bool {
	var probe struct{ Organizations []json.RawMessage `json:"organizations"` }
	return json.Unmarshal(b, &probe) == nil
}

Try / catch

if err != nil {
	log.Printf("org list unparsable: %v; body head: %.100s", err, body)
}

Prevention

When it happens

Trigger: API returns a non-list payload (error envelope, empty/HTML body, proxy interception) for the organizations list or a paginated page; or Yandex changed the response schema.

Common situations: Proxy/captive portal returning HTML; token accepted but payload is a permission-denied error JSON; stale VictoriaMetrics version incompatible with a changed Yandex API response format.

Understand the failure class

Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.

Related errors


AI-assisted analysis of VictoriaMetrics/VictoriaMetrics@5079fb58f1 (2026-09-03). Data as JSON: /api/errors/3bbaae92c26a21ba. Report an issue: GitHub.