kubernetes/kops · error

error writing to output: %v

Error message

error writing to output: %v

What it means

After successfully marshaling the YAML bytes, RunGetAssets writes them to the provided io.Writer (stdout); any write failure is wrapped with this message. This is an I/O error, not a serialization error — the output stream rejected or failed the write.

Source

Thrown at cmd/kops/get_assets.go:164

		err := assetcopy.Copy(updateClusterResults.ImageAssets, updateClusterResults.FileAssets, f.VFSContext(), updateClusterResults.Cluster)
		if err != nil {
			return err
		}
	}

	switch options.Output {
	case OutputTable:
		if err = imageOutputTable(result.Images, out); err != nil {
			return err
		}
		return fileOutputTable(result.Files, out)
	case OutputYaml:
		y, err := yaml.Marshal(result)
		if err != nil {
			return fmt.Errorf("unable to marshal YAML: %v", err)
		}
		if _, err := out.Write(y); err != nil {
			return fmt.Errorf("error writing to output: %v", err)
		}
	case OutputJSON:
		j, err := json.Marshal(result)
		if err != nil {
			return fmt.Errorf("unable to marshal JSON: %v", err)
		}
		if _, err := out.Write(j); err != nil {
			return fmt.Errorf("error writing to output: %v", err)
		}
	default:
		return fmt.Errorf("unsupported output format: %q", options.Output)
	}

	return nil
}

func imageOutputTable(images []*Image, out io.Writer) error {
	fmt.Println("")

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Redirect to a file instead of a pipe, or avoid consumers that close stdout early
  2. Check available disk space on the target of the redirection
  3. Rerun in a healthy terminal/SSH session to rule out closed descriptors

Example fix

// before
kops get assets -o yaml | head -20
// after
kops get assets -o yaml > assets.yaml && head -20 assets.yaml
Defensive patterns

Strategy: try-catch

Try / catch

if _, err := out.Write(y); err != nil {
    if errors.Is(err, syscall.EPIPE) {
        return nil // consumer closed stdout; benign
    }
    return fmt.Errorf("error writing to output: %v", err)
}

Prevention

When it happens

Trigger: `kops get assets -o yaml` with stdout redirected to a full disk, a closed pipe (e.g. `| head`), or a broken file descriptor.

Common situations: Piping to commands that exit early (head, grep -q with immediate match); CI capturing output on a full filesystem; broken terminal/SSH session closing stdout.

Related errors


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