wavetermdev/waveterm · error
nil message
Error message
nil message
What it means
EncodeWaveOSCMessageEx serializes an *RpcMessage to JSON and wraps it in an OSC sequence. A nil message pointer cannot be marshalled meaningfully, so the function rejects it explicitly with this sentinel error before touching json.Marshal.
Source
Thrown at pkg/wshutil/wshutil.go:117
var buf bytes.Buffer
buf.Write(makeOscPrefix(oscNum))
escSeq := [6]byte{'\\', 'u', '0', '0', '0', '0'}
for _, b := range barr {
if b < 0x20 || b == 0x7f {
escSeq[4] = HexChars[b>>4]
escSeq[5] = HexChars[b&0x0f]
buf.Write(escSeq[:])
} else {
buf.WriteByte(b)
}
}
buf.WriteByte(BEL)
return buf.Bytes(), nil
}
func EncodeWaveOSCMessageEx(oscNum string, msg *RpcMessage) ([]byte, error) {
if msg == nil {
return nil, fmt.Errorf("nil message")
}
barr, err := json.Marshal(msg)
if err != nil {
return nil, fmt.Errorf("error marshalling message to json: %w", err)
}
return EncodeWaveOSCBytes(oscNum, barr)
}
var shutdownOnce sync.Once
func DoShutdown(reason string, exitCode int, quiet bool) {
shutdownOnce.Do(func() {
defer os.Exit(exitCode)
if !quiet && reason != "" {
log.Printf("shutting down: %s\n", reason)
}
})
}View on GitHub (pinned to a4447c1563)
Solutions
- Construct a valid RpcMessage before calling; never pass a nil pointer.
- Check the upstream producer for paths that return a nil message.
- If an empty message is intended, pass &RpcMessage{} with appropriate fields instead.
Example fix
// before
var msg *RpcMessage
barr, err := EncodeWaveOSCMessageEx("1337;", msg) // panics into error
// after
msg := &RpcMessage{Command: "waveclient:getdata", Data: basePayload}
barr, err := EncodeWaveOSCMessageEx("1337;", msg) Defensive patterns
Strategy: validation
Validate before calling
if msg == nil {
return errors.New("cannot encode nil RpcMessage")
} Type guard
func hasMessage(m *wshutil.RpcMessage) bool { return m != nil } Try / catch
if msg == nil { return errors.New("no message to send") }
if _, err := EncodeWaveOSCMessageEx(oscNum, msg); err != nil {
return fmt.Errorf("encode failed: %w", err)
} Prevention
- Check producers for code paths returning nil messages
- Initialize messages with &RpcMessage{} rather than var msg *RpcMessage
- Validate messages at API boundaries before queuing
When it happens
Trigger: Calling EncodeWaveOSCMessageEx with msg == nil — e.g. a channel or variable holding a typed-nil *RpcMessage, or an upstream function returning nil on a path the caller didn't check.
Common situations: Uninitialized message variable; an RPC builder that returns (nil, nil) on an edge case; passing a nil pointer through a message queue unchecked.
Related errors
- linePtr is nil
- nil wshrpc passed to wshclient
- file info is required
- invalid AIMessage: %w
- part %d: text type requires non-empty text field
AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01).
Data as JSON: /api/errors/65a63d917efd0a08.
Report an issue: GitHub.