{"record":{"id":"02cee4171bc3cfa2","repo":"grafana/k6","slug":"could-not-marshal-yaml-w","errorCode":null,"errorMessage":"could not marshal YAML: %w","messagePattern":"could not marshal YAML: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cmd/ui.go","lineNumber":400,"sourceCode":"\t\t\t// Default ticker-based progress bar resizing\n\t\t\tif gs.Stdout.IsTTY && !terminalSizeUnknown && winch == nil {\n\t\t\t\ttw, _, err := term.GetSize(stdoutFD)\n\t\t\t\tif tw > 0 && err == nil {\n\t\t\t\t\ttermWidth = tw\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\trenderProgressBars(true)\n\t\tgs.OutMutex.Lock()\n\t\tprintProgressBars()\n\t\tgs.OutMutex.Unlock()\n\t}\n}\n\nfunc yamlPrint(w io.Writer, v any) error {\n\tdata, err := yaml.Marshal(v)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"could not marshal YAML: %w\", err)\n\t}\n\t_, err = fmt.Fprint(w, string(data))\n\tif err != nil {\n\t\treturn fmt.Errorf(\"could flush the data to the output: %w\", err)\n\t}\n\treturn nil\n}\n","sourceCodeStart":382,"sourceCodeEnd":408,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/cmd/ui.go#L382-L408","documentation":"yamlPrint (used to render YAML output for status/stats views in internal/cmd/ui.go) marshals its value with yaml.Marshal before printing. A marshal failure means the data contains a type YAML cannot represent (non-string map keys, channels, funcs, cycles). Because k6 feeds it fixed internal structures, this error in a stock binary indicates an internal invariant break rather than a user mistake.","triggerScenarios":"Calling the code path through yamlPrint with a value yaml.Marshal cannot encode; practically only reachable in custom/modified k6 builds that put unsupported types into the printed struct.","commonSituations":"Custom k6 forks adding non-serializable fields to status or stats data; extremely rare in stock binaries.","solutions":["For stock k6, report a bug at https://github.com/grafana/k6/issues with the exact command and 'k6 version' output","For custom builds, keep the printed struct limited to strings, numbers, bools, slices, and nested maps","Work around by using a different output form for that data (e.g. capture the JSON equivalent)"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"out=$(k6 status 2>&1)\nif [ $? -ne 0 ] && echo \"$out\" | grep -q 'could not marshal YAML'; then\n  echo \"YAML rendering failed — likely an internal bug; falling back\" >&2\n  k6 version  # gather build info and report upstream\nfi","preventionTips":["Pin a known-good k6 version in CI","For custom builds, keep printed structs marshal-safe: strings, numbers, bools, slices, nested maps only","Report marshal failures upstream with a reproduction"],"tags":["yaml","serialization","cli"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}