grafana/k6 · error
failed to encode project list
Error message
failed to encode project list: %w
What it means
Wrapped error in cmdCloudProjectList.outputJSON: encoding the fetched project list to JSON failed. As with the test list, this only happens if the data contains values the encoder cannot represent — effectively an internal fault.
Solutions
- Retry the 'k6 cloud project list' command
- Report as an internal bug if it reproduces consistently
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at internal/cmd/cloud_project_list.go:79 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/a00abe865cec9cb0.
Report an issue: GitHub.
Appendix: source
Thrown at internal/cmd/cloud_project_list.go:79
if len(projects) == 0 {
printToStdout(c.globalState, stackHeader+
"No projects found.\n"+
"To create a project, visit https://grafana.com/docs/grafana-cloud/testing/k6/projects-and-users/projects/\n")
return nil
}
printToStdout(c.globalState, stackHeader+formatProjectTable(projects))
return nil
}
func (c *cmdCloudProjectList) outputJSON(projects []cloudapiv6.Project) error {
buf := &bytes.Buffer{}
enc := json.NewEncoder(buf)
enc.SetEscapeHTML(false)
enc.SetIndent("", " ")
if err := enc.Encode(projects); err != nil {
return fmt.Errorf("failed to encode project list: %w", err)
}
printToStdout(c.globalState, buf.String())
return nil
}
func formatProjectTable(projects []cloudapiv6.Project) string {
var buf strings.Builder
w := tabwriter.NewWriter(&buf, 0, 0, 3, ' ', 0)
_, _ = fmt.Fprintln(w, "ID\tNAME\tDEFAULT")
for _, p := range projects {
def := "no"
if p.IsDefault {
def = "yes"
}
_, _ = fmt.Fprintf(w, "%d\t%s\t%s\n", p.ID, p.Name, def)
}
_ = w.Flush()View on GitHub (pinned to 01ffac6f24)