{"record":{"id":"6ea347b83a103a36","repo":"wavetermdev/waveterm","slug":"error-encoding-osc-message-adaptmsgchtopty-w","errorCode":null,"errorMessage":"error encoding osc message (AdaptMsgChToPty): %w","messagePattern":"error encoding osc message \\(AdaptMsgChToPty\\): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/wshutil/wshrpcio.go","lineNumber":53,"sourceCode":"\t\t\treturn fmt.Errorf(\"error writing to output (AdaptOutputChToStream): %w\", err)\n\t\t}\n\t\t// write trailing newline\n\t\tif _, err := output.Write([]byte{'\\n'}); err != nil {\n\t\t\tdrain = true\n\t\t\treturn fmt.Errorf(\"error writing trailing newline to output (AdaptOutputChToStream): %w\", err)\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc AdaptMsgChToPty(outputCh chan []byte, oscEsc string, output io.Writer) error {\n\tif len(oscEsc) != 5 {\n\t\tpanic(\"oscEsc must be 5 characters\")\n\t}\n\tfor msg := range outputCh {\n\t\tbarr, err := EncodeWaveOSCBytes(oscEsc, msg)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error encoding osc message (AdaptMsgChToPty): %w\", err)\n\t\t}\n\t\tif _, err := output.Write(barr); err != nil {\n\t\t\treturn fmt.Errorf(\"error writing osc message (AdaptMsgChToPty): %w\", err)\n\t\t}\n\t}\n\treturn nil\n}\n","sourceCodeStart":35,"sourceCodeEnd":61,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/wshutil/wshrpcio.go#L35-L61","documentation":"AdaptMsgChToPty wraps each channel message in a Wave OSC escape sequence via EncodeWaveOSCBytes before writing to the pty. This error means the OSC encoding step failed for a message, before any bytes were written.","triggerScenarios":"EncodeWaveOSCBytes(oscEsc, msg) returns an error for a message coming off outputCh — practically, when the message exceeds the 64 MB maxSize limit (the oscEsc length is validated by panic at function entry, so encoding failures are effectively size failures).","commonSituations":"A huge RPC payload (e.g. a large file read result) is routed to terminal output and exceeds the 64 MB OSC limit.","solutions":["Reduce the message size before sending it through outputCh.","Chunk large payloads into multiple smaller messages.","Avoid routing bulk data (file reads, large command output) through the OSC message channel.","Check message origin upstream and cap payload size there."],"exampleFix":"// before\noutputCh <- largePayload // may exceed 64MB\n// after\nfor _, chunk := range chunkBytes(largePayload, 1<<20) {\n    outputCh <- chunk\n}","handlingStrategy":"validation","validationCode":"if len(msg) > 64*1024*1024 {\n    return errors.New(\"message exceeds OSC encoding limit\")\n}","typeGuard":null,"tryCatchPattern":"if err := AdaptMsgChToPty(ch, oscEsc, pty); err != nil {\n    if strings.Contains(err.Error(), \"input data too large\") {\n        return handleOversizedPayload()\n    }\n    return err\n}","preventionTips":["Cap message sizes at the producer before pushing to the channel","Chunk large payloads into multiple messages","Keep bulk data transfers off the OSC message channel"],"tags":["go","encoding","osc","payload-size"],"backgroundTag":"payload-too-large","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}