{"record":{"id":"7c92882538c023fa","repo":"wavetermdev/waveterm","slug":"decoding-terminal-output-w","errorCode":null,"errorMessage":"decoding terminal output: %w","messagePattern":"decoding terminal output: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/wsh/cmd/wshcmd-debugterm.go","lineNumber":107,"sourceCode":"\t\treturn nil\n\t}\n\tif debugTermSize <= 0 {\n\t\treturn fmt.Errorf(\"size must be greater than 0\")\n\t}\n\tfullORef, err := resolveBlockArg()\n\tif err != nil {\n\t\treturn err\n\t}\n\trtn, err := wshclient.DebugTermCommand(RpcClient, wshrpc.CommandDebugTermData{\n\t\tBlockId: fullORef.OID,\n\t\tSize:    debugTermSize,\n\t}, &wshrpc.RpcOpts{Timeout: 2000})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"reading terminal output: %w\", err)\n\t}\n\ttermData, err := base64.StdEncoding.DecodeString(rtn.Data64)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"decoding terminal output: %w\", err)\n\t}\n\tvar output string\n\tif mode == DebugTermModeDecode {\n\t\toutput = formatDebugTermDecode(termData)\n\t} else {\n\t\toutput = formatDebugTermHex(termData)\n\t}\n\tWriteStdout(\"%s\", output)\n\treturn nil\n}\n\nfunc debugTermPreRun(cmd *cobra.Command, args []string) error {\n\tif debugTermStdin || debugTermInput != \"\" {\n\t\treturn nil\n\t}\n\treturn preRunSetupRpcClient(cmd, args)\n}\n","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/cmd/wsh/cmd/wshcmd-debugterm.go#L89-L125","documentation":"After a successful DebugTermCommand, the response's Data64 field is base64-decoded; a decode failure is wrapped as 'decoding terminal output'. This indicates the server returned a malformed base64 payload — a protocol/data corruption issue rather than a user input problem.","triggerScenarios":"The RPC succeeds but rtn.Data64 contains invalid base64 (corrupted response, version mismatch between wsh client and Wave server RPC handlers, or an error string placed in Data64).","commonSituations":"Mismatched wsh and Wave Terminal versions where the RPC payload format changed; a proxy or wrapper corrupting the response; backend bug returning non-base64 data in Data64.","solutions":["Update wsh and Wave Terminal to matching versions","Re-run the command to rule out a one-off corrupted response","Inspect the raw rtn payload (server logs) to see what Data64 actually contained","Report/patch upstream if the server handler emits non-base64 Data64"],"exampleFix":"// before\nold-wsh debugterm <blockid> --size 4096   # version mismatch corrupts payload\n// after\n# upgrade both sides, then:\nwsh debugterm <blockid> --size 4096","handlingStrategy":"type-guard","validationCode":"// sanity-check the payload shape before decoding:\nif rtn == nil || rtn.Data64 == \"\" || len(rtn.Data64)%4 != 0 || !isBase64(rtn.Data64) {\n\treturn fmt.Errorf(\"malformed Data64 payload from server\")\n}\n\nfunc isBase64(s string) bool {\n\t_, err := base64.StdEncoding.DecodeString(s)\n\treturn err == nil\n}","typeGuard":"func isValidBase64(s string) bool {\n\tif s == \"\" || len(s)%4 != 0 {\n\t\treturn false\n\t}\n\t_, err := base64.StdEncoding.DecodeString(s)\n\treturn err == nil\n}","tryCatchPattern":"termData, err := base64.StdEncoding.DecodeString(rtn.Data64)\nif err != nil {\n\treturn fmt.Errorf(\"decoding terminal output: %w (payload len=%d; check wsh/Wave version match)\", err, len(rtn.Data64))\n}","preventionTips":["Keep wsh CLI and Wave Terminal on the same version","Log the payload length and a prefix when decoding fails to spot corruption","Re-run once to rule out a transient corrupted response","Never modify the RPC response in transit (avoid re-wrapping through proxies/scripts)"],"tags":["base64","decoding","rpc","version-mismatch"],"backgroundTag":"base64-decode-failed","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}