{"record":{"id":"2dcb38cffcc6413f","repo":"wavetermdev/waveterm","slug":"formatting-version-info-v","errorCode":null,"errorMessage":"formatting version info: %v","messagePattern":"formatting version info: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/wsh/cmd/wshcmd-version.go","lineNumber":65,"sourceCode":"\t}\n\n\tupdateChannel, err := wshclient.GetUpdateChannelCommand(RpcClient, &wshrpc.RpcOpts{Timeout: 2000, Route: wshutil.ElectronRoute})\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif versionJSON {\n\t\tinfo := map[string]interface{}{\n\t\t\t\"version\":       resp.Version,\n\t\t\t\"clientid\":      resp.ClientId,\n\t\t\t\"buildtime\":     resp.BuildTime,\n\t\t\t\"configdir\":     resp.ConfigDir,\n\t\t\t\"datadir\":       resp.DataDir,\n\t\t\t\"updatechannel\": updateChannel,\n\t\t}\n\t\toutBArr, err := json.MarshalIndent(info, \"\", \"  \")\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"formatting version info: %v\", err)\n\t\t}\n\t\tWriteStdout(\"%s\\n\", string(outBArr))\n\t\treturn nil\n\t}\n\n\t// Default verbose text output\n\tfmt.Printf(\"v%s (%s)\\n\", resp.Version, resp.BuildTime)\n\tfmt.Printf(\"clientid:  %s\\n\", resp.ClientId)\n\tfmt.Printf(\"configdir: %s\\n\", resp.ConfigDir)\n\tfmt.Printf(\"datadir:   %s\\n\", resp.DataDir)\n\tfmt.Printf(\"update-channel: %s\\n\", updateChannel)\n\treturn nil\n}\n","sourceCodeStart":47,"sourceCodeEnd":79,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/cmd/wsh/cmd/wshcmd-version.go#L47-L79","documentation":"In `wsh version --output json` mode, the collected info map is serialized with json.MarshalIndent. MarshalIndent rarely fails for this plain map[string]string, so this wrapper indicates an unexpected serialization bug or malformed data placed into the info map.","triggerScenarios":"json.MarshalIndent(info, \"\", \"  \") returning an error — practically only if a non-JSON-serializable value (e.g. a channel or func) is inserted into the info map.","commonSituations":"A code change adds a field to the info map that isn't a JSON-safe type; running a build with locally modified version info sources.","solutions":["Retry with a stock build; if it persists, report it as a bug since this map should only contain strings.","Audit the info map construction in wshcmd-version.go for non-serializable values added by recent changes.","As a workaround use the default verbose text output (omit --output json)."],"exampleFix":"// before\noutBArr, err := json.MarshalIndent(info, \"\", \"  \")\nif err != nil {\n\treturn fmt.Errorf(\"formatting version info: %v\", err)\n}\n// after\noutBArr, err := json.MarshalIndent(info, \"\", \"  \")\nif err != nil {\n\treturn fmt.Errorf(\"formatting version info: %v\", err)\n}\n_ = outBArr // ensure info only contains string values when extending the map","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"outBArr, err := json.MarshalIndent(info, \"\", \"  \")\nif err != nil {\n\t// fall back to plain text output so the command still succeeds\n\treturn printPlainTextVersion()\n}","preventionTips":["Only put JSON-serializable values (strings) into the info map.","Add a unit test that marshals the version info map.","Report persistent failures on a stock build as a bug upstream."],"tags":["json","serialization","cli"],"backgroundTag":"json-marshal-failed","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}