{"record":{"id":"a00abe865cec9cb0","repo":"grafana/k6","slug":"failed-to-encode-project-list-w","errorCode":null,"errorMessage":"failed to encode project list: %w","messagePattern":"failed to encode project list: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cmd/cloud_project_list.go","lineNumber":79,"sourceCode":"\n\tif len(projects) == 0 {\n\t\tprintToStdout(c.globalState, stackHeader+\n\t\t\t\"No projects found.\\n\"+\n\t\t\t\"To create a project, visit https://grafana.com/docs/grafana-cloud/testing/k6/projects-and-users/projects/\\n\")\n\t\treturn nil\n\t}\n\n\tprintToStdout(c.globalState, stackHeader+formatProjectTable(projects))\n\treturn nil\n}\n\nfunc (c *cmdCloudProjectList) outputJSON(projects []cloudapiv6.Project) error {\n\tbuf := &bytes.Buffer{}\n\tenc := json.NewEncoder(buf)\n\tenc.SetEscapeHTML(false)\n\tenc.SetIndent(\"\", \"  \")\n\tif err := enc.Encode(projects); err != nil {\n\t\treturn fmt.Errorf(\"failed to encode project list: %w\", err)\n\t}\n\n\tprintToStdout(c.globalState, buf.String())\n\treturn nil\n}\n\nfunc formatProjectTable(projects []cloudapiv6.Project) string {\n\tvar buf strings.Builder\n\tw := tabwriter.NewWriter(&buf, 0, 0, 3, ' ', 0)\n\t_, _ = fmt.Fprintln(w, \"ID\\tNAME\\tDEFAULT\")\n\tfor _, p := range projects {\n\t\tdef := \"no\"\n\t\tif p.IsDefault {\n\t\t\tdef = \"yes\"\n\t\t}\n\t\t_, _ = fmt.Fprintf(w, \"%d\\t%s\\t%s\\n\", p.ID, p.Name, def)\n\t}\n\t_ = w.Flush()","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/cmd/cloud_project_list.go#L61-L97","documentation":"`k6 cloud project list --json` (cmdCloudProjectList.outputJSON) encodes the fetched project slice with encoding/json and wraps an encoder failure here. The Project model contains only serializable fields, so Encode failing is a near-impossible internal condition rather than a response to bad input.","triggerScenarios":"Running `k6 cloud project list --json` when json.Encoder.Encode errors; realistically only after a k6 change introduces a non-serializable field to the Project type.","commonSituations":"Practically never hit; would occur uniformly across environments immediately after upgrading k6.","solutions":["Run `k6 cloud project list` without --json to confirm data retrieval works","Switch to a known-good k6 version","Report the defect to grafana/k6 with version and output"],"exampleFix":"# before\nk6 cloud project list --json\n# after\nk6 cloud project list  # table output as a workaround","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := cmdCloudProjectList.outputJSON(projects); err != nil {\n    // encoder failure is internal: fall back to the table formatter\n    printToStdout(gs, formatProjectTable(projects))\n}","preventionTips":["Pin k6 versions in pipelines","Smoke-test --json subcommands after upgrades","Report encoder failures upstream with version details"],"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"}