{"record":{"id":"1f9c4f7a365130c0","repo":"wavetermdev/waveterm","slug":"error-writing-osc-message-adaptmsgchtopty-w","errorCode":null,"errorMessage":"error writing osc message (AdaptMsgChToPty): %w","messagePattern":"error writing osc message \\(AdaptMsgChToPty\\): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/wshutil/wshrpcio.go","lineNumber":56,"sourceCode":"\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":38,"sourceCodeEnd":61,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/wshutil/wshrpcio.go#L38-L61","documentation":"Wrapped I/O error raised while writing an OSC (terminal escape) message to the pty adapter channel (AdaptMsgChToPty). The underlying error is included with %w so callers can unwrap the cause of the write failure.","triggerScenarios":"output.Write(barr) fails inside AdaptMsgChToPty — the pty/file writer returns an error such as EIO or EPIPE when the terminal session is gone.","commonSituations":"Terminal window closed while a background process still writes; pty master side closed; SSH/remote session dropped.","solutions":["Check the wrapped error for the OS-level cause (EIO/EPIPE).","Stop producing messages to outputCh once the pty is known to be closed.","Handle terminal disconnects upstream so the channel producer is cancelled.","Re-establish the terminal session if output must be preserved."],"exampleFix":"// before\nAdaptMsgChToPty(outputCh, \"1337;\", ptyWriter)\n// after\nerr := AdaptMsgChToPty(outputCh, \"1337;\", ptyWriter)\nif err != nil {\n    close(outputCh) // stop producer; pty is gone\n}","handlingStrategy":"try-catch","validationCode":"// Verify pty writer is still open before starting the pump\nif f, ok := ptyWriter.(*os.File); ok {\n    if _, err := f.Stat(); err != nil {\n        return fmt.Errorf(\"pty closed: %w\", err)\n    }\n}","typeGuard":null,"tryCatchPattern":"err := AdaptMsgChToPty(outputCh, oscEsc, ptyWriter)\nif err != nil {\n    // pty is broken; stop producers and clean up\n    close(outputCh)\n    return fmt.Errorf(\"terminal output lost: %w\", err)\n}","preventionTips":["Cancel producers when the terminal session ends","Detect terminal disconnect and tear down the channel pump","Wrap pty writes with connection-liveness checks"],"tags":["go","io","pty","broken-pipe"],"backgroundTag":"broken-pipe-write-failure","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}