grafana/k6 · error
failed to encode load zone list: %w
Error message
failed to encode load zone list: %w
What it means
`k6 cloud load-zones list --json` (cmdCloudLoadZoneList.outputJSON) encodes the fetched load-zone slice with encoding/json and wraps an encoder failure in this message. For plain data structs like LoadZone, Encode cannot fail in practice — there are no channels, funcs, or cyclic references — so hitting this error indicates an internal defect or memory-level fault rather than a user mistake.
Source
Thrown at internal/cmd/cloud_load_zone_list.go:77
stackHeader := fmt.Sprintf("Load zones for %s:\n\n", cloudStackName(cloudConfig))
if len(loadZones) == 0 {
printToStdout(c.globalState, stackHeader+"No load zones found.\n")
return nil
}
printToStdout(c.globalState, stackHeader+formatLoadZoneTable(loadZones))
return nil
}
func (c *cmdCloudLoadZoneList) outputJSON(loadZones []cloudapiv6.LoadZone) error {
buf := &bytes.Buffer{}
enc := json.NewEncoder(buf)
enc.SetEscapeHTML(false)
enc.SetIndent("", " ")
if err := enc.Encode(loadZones); err != nil {
return fmt.Errorf("failed to encode load zone list: %w", err)
}
printToStdout(c.globalState, buf.String())
return nil
}
func formatLoadZoneTable(loadZones []cloudapiv6.LoadZone) string {
var buf strings.Builder
w := tabwriter.NewWriter(&buf, 0, 0, 3, ' ', 0)
_, _ = fmt.Fprintln(w, "ID\tNAME\tTYPE\tAVAILABLE")
for _, z := range loadZones {
zoneType := "private"
if z.Public {
zoneType = "public"
}
available := "no"
if z.Available {
available = "yes"View on GitHub (pinned to 93accf6570)
Solutions
- Run the command without --json (table output) to confirm the API call itself works
- Upgrade or downgrade k6 to a version where this path is known-good
- Report the bug to grafana/k6 with the k6 version and full output
Example fix
# before k6 cloud load-zones list --json # after k6 cloud load-zones list # table output as a workaround
Defensive patterns
Strategy: try-catch
Try / catch
if err := cmdCloudLoadZoneList.outputJSON(zones); err != nil {
// fall back to table output; encoder failure is internal, data itself is valid
printToStdout(gs, formatLoadZoneTable(zones))
} Prevention
- Pin k6 versions in CI so an internal regression cannot appear mid-pipeline
- Smoke-test --json output after every k6 upgrade
- Report encoder failures upstream — they are bugs, not config issues
When it happens
Trigger: Running the load-zone list command with --json output while json.Encoder.Encode returns an error; realistically only reachable if a LoadZone field type stops being serializable in a future k6 version.
Common situations: Essentially never seen; would appear right after a k6 upgrade that changed the LoadZone model, on any invocation regardless of environment.
Related errors
- failed to encode test list: %w
- failed to encode project list: %w
- failed to get version details with extensions: %w
- Error while parsing selector `${selector}` - cannot use ${op
- received empty projects page with next link
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/9d7dc47d3bc8635f.
Report an issue: GitHub.