kubernetes/kops · error

expected object at %q, got %T

Error message

expected object at %q, got %T

What it means

JSONObject.Object found the key present in the SQS policy document but holding a non-object value; normalization expected a nested JSON object (e.g. a Statement entry or Principal) at that key.

Source

Thrown at upup/pkg/fi/cloudup/awstasks/sqs.go:171

	v, found := (*j)[key]
	if !found {
		return nil, false, nil
	}
	s, ok := v.([]any)
	if !ok {
		return nil, false, fmt.Errorf("expected slice at %q, got %T", key, v)
	}
	return s, true, nil
}

func (j *JSONObject) Object(key string) (JSONObject, bool, error) {
	v, found := (*j)[key]
	if !found {
		return nil, false, nil
	}
	m, ok := v.(JSONObject)
	if !ok {
		return nil, false, fmt.Errorf("expected object at %q, got %T", key, v)
	}
	return m, true, nil
}

// normalizePolicy sorts the Service principals in the policy, so that we can compare policies more easily.
func normalizePolicy(policy map[string]interface{}) error {
	xform := jsonutils.NewTransformer()
	xform.AddSliceTransform(func(path string, value []any) ([]any, error) {
		if path != ".Statement[].Principal.Service[]" {
			return value, nil
		}
		return jsonutils.SortSlice(value)
	})
	if err := xform.Transform(policy); err != nil {
		return err
	}
	return nil
}

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Fix the policy so the referenced key holds a JSON object
  2. Use standard IAM policy shapes (Statement entries as objects unless arrays are expected)
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at upup/pkg/fi/cloudup/awstasks/sqs.go:171 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05). Data as JSON: /api/errors/10a9f688e9c9d079. Report an issue: GitHub.