grafana/k6 · error

could not marshal YAML

Error message

could not marshal YAML: %w

What it means

yamlPrint wraps yaml.Marshal failing on the value being printed (end-of-test summary data in ui.go). Since the printed structs are plain serializable Go values, this is an internal error, not something the user's input controls.

Solutions

  1. Inspect the wrapped yaml error for the offending field
  2. Report as a k6 bug — summary data should always be YAML-marshalable
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at internal/cmd/ui.go:400 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18). Data as JSON: /api/errors/02cee4171bc3cfa2. Report an issue: GitHub.

Appendix: source

Thrown at internal/cmd/ui.go:400

			// Default ticker-based progress bar resizing
			if gs.Stdout.IsTTY && !terminalSizeUnknown && winch == nil {
				tw, _, err := term.GetSize(stdoutFD)
				if tw > 0 && err == nil {
					termWidth = tw
				}
			}
		}
		renderProgressBars(true)
		gs.OutMutex.Lock()
		printProgressBars()
		gs.OutMutex.Unlock()
	}
}

func yamlPrint(w io.Writer, v any) error {
	data, err := yaml.Marshal(v)
	if err != nil {
		return fmt.Errorf("could not marshal YAML: %w", err)
	}
	_, err = fmt.Fprint(w, string(data))
	if err != nil {
		return fmt.Errorf("could flush the data to the output: %w", err)
	}
	return nil
}

View on GitHub (pinned to 01ffac6f24)