{"record":{"id":"ff9ad575efdad07d","repo":"abiosoft/colima","slug":"error-encoding-status-as-json-w","errorCode":null,"errorMessage":"error encoding status as json: %w","messagePattern":"error encoding status as json: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/app.go","lineNumber":423,"sourceCode":"\t\tstatus.Kubernetes = true\n\t}\n\tif inst, err := limautil.Instance(); err == nil {\n\t\tstatus.CPU = inst.CPU\n\t\tstatus.Memory = inst.Memory\n\t\tstatus.Disk = inst.Disk\n\t}\n\treturn status, nil\n}\n\nfunc (c colimaApp) Status(extended bool, jsonOutput bool) error {\n\tstatus, err := c.getStatus()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif jsonOutput {\n\t\tif err := json.NewEncoder(os.Stdout).Encode(status); err != nil {\n\t\t\treturn fmt.Errorf(\"error encoding status as json: %w\", err)\n\t\t}\n\t} else {\n\t\tlog.Println(config.CurrentProfile().DisplayName, \"is running using\", status.Driver)\n\t\tlog.Println(\"arch:\", status.Arch)\n\t\tlog.Println(\"runtime:\", status.Runtime)\n\t\tif status.MountType != \"\" {\n\t\t\tlog.Println(\"mountType:\", status.MountType)\n\t\t}\n\n\t\t// ip address\n\t\tif status.IPAddress != \"\" {\n\t\t\tlog.Println(\"address:\", status.IPAddress)\n\t\t}\n\n\t\t// docker socket\n\t\tif status.DockerSocket != \"\" {\n\t\t\tlog.Println(\"docker socket:\", status.DockerSocket)\n\t\t}","sourceCodeStart":405,"sourceCodeEnd":441,"githubUrl":"https://github.com/abiosoft/colima/blob/c3a5f9184d83a197184f897a9f07eb3c01b3bc88/app/app.go#L405-L441","documentation":"With `colima status --json`, the status struct is streamed to stdout via json.Encoder; the error surfaces only when writing to stdout fails, almost always a closed or broken pipe (e.g. piping into head) rather than an encoding problem, since statusInfo is a plain fixed-shape struct.","triggerScenarios":"`colima status -j | head -1` where the consumer exits early (EPIPE), stdout redirected to a full device, or stdout closed prematurely by the calling process.","commonSituations":"Piping json output into head/less and quitting early; output redirected to a full disk or over a file-handle limit; embedding colima in a process whose stdout is closed before the write completes.","solutions":["Buffer the output instead of early-exiting the consumer: `colima status -j > /tmp/status.json`","In pipelines, drop the truncating command or run with pipefail disabled so SIGPIPE is not fatal","When embedding, capture to a buffer/file rather than a live pipe","Check disk space if stdout is redirected to a file"],"exampleFix":"# before\ncolima status --json | head -1   # broken pipe\n\n# after\ncolima status --json > /tmp/colima-status.json\nhead -1 /tmp/colima-status.json","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"func isBrokenPipe(err error) bool {\n    return err != nil && (errors.Is(err, syscall.EPIPE) || strings.Contains(err.Error(), \"broken pipe\"))\n}","tryCatchPattern":"// capture to a buffer instead of a live pipe\nvar buf bytes.Buffer\nif err := json.NewEncoder(&buf).Encode(status); err != nil {\n    return err // encoding should never fail for statusInfo\n}\n// write buf once; treat EPIPE on stdout as consumer-exited-early, not an error","preventionTips":["Avoid early-exiting consumers of `colima status --json` (head, less -q)","Redirect json output to a file when parsing it in scripts","Handle or ignore SIGPIPE in wrappers around colima"],"tags":["json","stdout","pipe","status"],"backgroundTag":null,"analyzedSha":"c3a5f9184d83a197184f897a9f07eb3c01b3bc88","analyzedAt":"2026-08-15T18:58:08.334Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}