wavetermdev/waveterm · error

error writing osc message (AdaptMsgChToPty): %w

Error message

error writing osc message (AdaptMsgChToPty): %w

What it means

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.

Source

Thrown at pkg/wshutil/wshrpcio.go:56

		if _, err := output.Write([]byte{'\n'}); err != nil {
			drain = true
			return fmt.Errorf("error writing trailing newline to output (AdaptOutputChToStream): %w", err)
		}
	}
	return nil
}

func AdaptMsgChToPty(outputCh chan []byte, oscEsc string, output io.Writer) error {
	if len(oscEsc) != 5 {
		panic("oscEsc must be 5 characters")
	}
	for msg := range outputCh {
		barr, err := EncodeWaveOSCBytes(oscEsc, msg)
		if err != nil {
			return fmt.Errorf("error encoding osc message (AdaptMsgChToPty): %w", err)
		}
		if _, err := output.Write(barr); err != nil {
			return fmt.Errorf("error writing osc message (AdaptMsgChToPty): %w", err)
		}
	}
	return nil
}

View on GitHub (pinned to a4447c1563)

Solutions

  1. Check the wrapped error for the OS-level cause (EIO/EPIPE).
  2. Stop producing messages to outputCh once the pty is known to be closed.
  3. Handle terminal disconnects upstream so the channel producer is cancelled.
  4. Re-establish the terminal session if output must be preserved.

Example fix

// before
AdaptMsgChToPty(outputCh, "1337;", ptyWriter)
// after
err := AdaptMsgChToPty(outputCh, "1337;", ptyWriter)
if err != nil {
    close(outputCh) // stop producer; pty is gone
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Verify pty writer is still open before starting the pump
if f, ok := ptyWriter.(*os.File); ok {
    if _, err := f.Stat(); err != nil {
        return fmt.Errorf("pty closed: %w", err)
    }
}

Try / catch

err := AdaptMsgChToPty(outputCh, oscEsc, ptyWriter)
if err != nil {
    // pty is broken; stop producers and clean up
    close(outputCh)
    return fmt.Errorf("terminal output lost: %w", err)
}

Prevention

When it happens

Trigger: output.Write(barr) fails inside AdaptMsgChToPty — the pty/file writer returns an error such as EIO or EPIPE when the terminal session is gone.

Common situations: Terminal window closed while a background process still writes; pty master side closed; SSH/remote session dropped.

Related errors


AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01). Data as JSON: /api/errors/1f9c4f7a365130c0. Report an issue: GitHub.