kubernetes/kops · error

error marshaling json: %v

Error message

error marshaling json: %v

What it means

When `kops toolbox dump` is run with -o json, cloudResources are serialized with json.MarshalIndent. This error means the in-memory dump structure failed JSON marshaling — e.g. a value containing an unsupported type (chan, func) or an encoding failure. The command aborts with no output.

Source

Thrown at cmd/kops/toolbox_dump.go:312

	}

	if cloudResources != nil {
		switch options.Output {
		case OutputYaml:
			b, err := kops.ToRawYaml(cloudResources)
			if err != nil {
				return fmt.Errorf("error marshaling yaml: %v", err)
			}
			_, err = out.Write(b)
			if err != nil {
				return fmt.Errorf("error writing to stdout: %v", err)
			}
			return nil

		case OutputJSON:
			b, err := json.MarshalIndent(cloudResources, "", "  ")
			if err != nil {
				return fmt.Errorf("error marshaling json: %v", err)
			}
			_, err = out.Write(b)
			if err != nil {
				return fmt.Errorf("error writing to stdout: %v", err)
			}
			return nil

		default:
			return fmt.Errorf("unsupported output format: %q", options.Output)
		}
	}
	return nil
}

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Retry with -o yaml to isolate whether only the JSON encoder fails
  2. Update kops to the latest release
  3. Report the failing cluster/provider to kops maintainers if reproducible
Defensive patterns

Strategy: try-catch

Validate before calling

// No caller-side validation; ensure kops version is current and the dump targets a supported cluster.

Try / catch

b, err := json.MarshalIndent(cloudResources, "", "  ")
if err != nil {
	return fmt.Errorf("error marshaling json: %v", err)
}
// treat as unrecoverable for JSON output; retry with -o yaml if JSON fails at runtime

Prevention

When it happens

Trigger: Running `kops toolbox dump -o json` when the collected cloudResources contain values json.MarshalIndent cannot encode.

Common situations: kops internal type regressions; unusual cloud resources producing non-encodable data; running a dev/alpha build of kops.

Understand the failure class

Background: json.Marshal / "failed to marshal" errors in Go: why "unsupported type" happens and how to fix it — this error's family across 22 libraries.

Related errors


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