grafana/k6 · error
failed to encode test list
Error message
failed to encode test list: %w
What it means
Wrapped error in cmdCloudTestList.outputJSON: encoding the fetched cloud load test list (guaranteed non-nil) to JSON failed. Encoding failures are practically impossible for this data shape and indicate a serializer-level fault rather than bad input.
Solutions
- Treat as a k6 internal bug and report it if reproducible
- Retry the command; transient corruption of the API response data is unlikely but possible
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at internal/cmd/cloud_loadtest_list.go:121 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/908c4969c8eb2dfb.
Report an issue: GitHub.
Appendix: source
Thrown at internal/cmd/cloud_loadtest_list.go:121
if id == 0 {
return 0, errNoProjectConfigured
}
return id, nil
}
func (c *cmdCloudTestList) outputJSON(tests []v6cloudapi.LoadTest) error {
// If tests is nil, initialize it to an empty slice to avoid encoding it as null.
if tests == nil {
tests = []v6cloudapi.LoadTest{}
}
buf := &bytes.Buffer{}
enc := json.NewEncoder(buf)
enc.SetEscapeHTML(false)
enc.SetIndent("", " ")
if err := enc.Encode(tests); err != nil {
return fmt.Errorf("failed to encode test list: %w", err)
}
printToStdout(c.globalState, buf.String())
return nil
}
func formatLoadTestTable(tests []v6cloudapi.LoadTest) string {
const dateFormat = "2006-01-02 15:04"
var buf strings.Builder
w := tabwriter.NewWriter(&buf, 0, 0, 3, ' ', 0)
_, _ = fmt.Fprintln(w, "ID\tNAME\tCREATED\tUPDATED")
for _, t := range tests {
_, _ = fmt.Fprintf(w, "%d\t%s\t%s\t%s\n",
t.ID, t.Name,
t.Created.UTC().Format(dateFormat),
t.Updated.UTC().Format(dateFormat),
)View on GitHub (pinned to 01ffac6f24)