{"record":{"id":"9d7dc47d3bc8635f","repo":"grafana/k6","slug":"failed-to-encode-load-zone-list-w","errorCode":null,"errorMessage":"failed to encode load zone list: %w","messagePattern":"failed to encode load zone list: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cmd/cloud_load_zone_list.go","lineNumber":77,"sourceCode":"\n\tstackHeader := fmt.Sprintf(\"Load zones for %s:\\n\\n\", cloudStackName(cloudConfig))\n\n\tif len(loadZones) == 0 {\n\t\tprintToStdout(c.globalState, stackHeader+\"No load zones found.\\n\")\n\t\treturn nil\n\t}\n\n\tprintToStdout(c.globalState, stackHeader+formatLoadZoneTable(loadZones))\n\treturn nil\n}\n\nfunc (c *cmdCloudLoadZoneList) outputJSON(loadZones []cloudapiv6.LoadZone) error {\n\tbuf := &bytes.Buffer{}\n\tenc := json.NewEncoder(buf)\n\tenc.SetEscapeHTML(false)\n\tenc.SetIndent(\"\", \"  \")\n\tif err := enc.Encode(loadZones); err != nil {\n\t\treturn fmt.Errorf(\"failed to encode load zone list: %w\", err)\n\t}\n\n\tprintToStdout(c.globalState, buf.String())\n\treturn nil\n}\n\nfunc formatLoadZoneTable(loadZones []cloudapiv6.LoadZone) string {\n\tvar buf strings.Builder\n\tw := tabwriter.NewWriter(&buf, 0, 0, 3, ' ', 0)\n\t_, _ = fmt.Fprintln(w, \"ID\\tNAME\\tTYPE\\tAVAILABLE\")\n\tfor _, z := range loadZones {\n\t\tzoneType := \"private\"\n\t\tif z.Public {\n\t\t\tzoneType = \"public\"\n\t\t}\n\t\tavailable := \"no\"\n\t\tif z.Available {\n\t\t\tavailable = \"yes\"","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/cmd/cloud_load_zone_list.go#L59-L95","documentation":"`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.","triggerScenarios":"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.","commonSituations":"Essentially never seen; would appear right after a k6 upgrade that changed the LoadZone model, on any invocation regardless of environment.","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"],"exampleFix":"# before\nk6 cloud load-zones list --json\n# after\nk6 cloud load-zones list  # table output as a workaround","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := cmdCloudLoadZoneList.outputJSON(zones); err != nil {\n    // fall back to table output; encoder failure is internal, data itself is valid\n    printToStdout(gs, formatLoadZoneTable(zones))\n}","preventionTips":["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"],"tags":["go","json","cli","internal-error"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}