{"record":{"id":"d840f80e2b0faac5","repo":"wavetermdev/waveterm","slug":"error-decoding-input-data-w","errorCode":null,"errorMessage":"error decoding input data: %w","messagePattern":"error decoding input data: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/jobmanager/jobcmd.go","lineNumber":192,"sourceCode":"\tjm.lock.Lock()\n\tdefer jm.lock.Unlock()\n\treturn jm.setTermSize_withlock(termSize)\n}\n\n// TODO set up a single input handler loop + queue so we dont need to hold the lock but still get synchronized in-order execution\nfunc (jm *JobCmd) HandleInput(data wshrpc.CommandJobInputData) error {\n\tjm.lock.Lock()\n\tdefer jm.lock.Unlock()\n\n\tif jm.cmd == nil || jm.cmdPty == nil {\n\t\treturn fmt.Errorf(\"no active process\")\n\t}\n\n\tif len(data.InputData64) > 0 {\n\t\tinputBuf := make([]byte, base64.StdEncoding.DecodedLen(len(data.InputData64)))\n\t\tnw, err := base64.StdEncoding.Decode(inputBuf, []byte(data.InputData64))\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error decoding input data: %w\", err)\n\t\t}\n\t\t_, err = jm.cmdPty.Write(inputBuf[:nw])\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error writing to pty: %w\", err)\n\t\t}\n\t}\n\n\tif data.SigName != \"\" {\n\t\tsig := unixutil.ParseSignal(data.SigName)\n\t\tif sig != nil && jm.cmd.Process != nil {\n\t\t\terr := jm.cmd.Process.Signal(sig)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"error sending signal: %w\", err)\n\t\t\t}\n\t\t}\n\t}\n\n\tif data.TermSize != nil {","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/jobmanager/jobcmd.go#L174-L210","documentation":"HandleInput decodes the base64-encoded InputData64 field from a job-input RPC and writes the bytes to the job's PTY. This error is returned when base64.StdEncoding.Decode fails, meaning the client sent data that is not valid standard base64. It wraps the underlying decoding error (e.g. illegal base64 data at input byte N).","triggerScenarios":"Calling the job input RPC (HandleInput via the wsh job input path) with InputData64 containing characters outside the standard base64 alphabet, incorrect padding, or an empty string with whitespace/URL-safe -_ characters instead of +/.","commonSituations":"A client encodes input with base64.URLEncoding or RawStdEncoding instead of base64.StdEncoding; manual string construction that corrupts padding; a middleware or log pipeline mangles the '+' character into spaces in form/query encoding.","solutions":["Re-encode the payload on the client with base64.StdEncoding.EncodeToString before sending","If the payload uses URL-safe base64, convert with strings.NewReplacer(\"-\",\"+\",\"_\",\"/\") and re-add padding before sending","Log the InputData64 value and check the wrapped error's input byte offset to find the first corrupt character","Upgrade/fix the client library so it matches the server's standard encoding expectation"],"exampleFix":"// before\ninputData.InputData64 = base64.URLEncoding.EncodeToString(buf)\n// after\ninputData.InputData64 = base64.StdEncoding.EncodeToString(buf)","handlingStrategy":"validation","validationCode":"func isValidStdBase64(s string) bool {\n    if len(s) == 0 || len(s)%4 != 0 {\n        return false\n    }\n    _, err := base64.StdEncoding.DecodeString(s)\n    return err == nil\n}\nif !isValidStdBase64(inputData.InputData64) {\n    // fix encoding before calling the input RPC\n}","typeGuard":null,"tryCatchPattern":"if err := handleInput(data); err != nil {\n    var b64Err base64.CorruptInputError\n    if errors.As(err, &b64Err) {\n        // re-encode payload with base64.StdEncoding and retry once\n    }\n}","preventionTips":["Always encode with base64.StdEncoding.EncodeToString","Never build base64 strings by hand","Beware URL/query encoding mangling '+' into spaces","Test round-trip encode/decode in client unit tests"],"tags":["base64","decoding","input-validation"],"backgroundTag":"base64-decode-failed","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}