chenhg5/cc-connect · error
wps-agentspace: marshal frame: %w
Error message
wps-agentspace: marshal frame: %w
What it means
writeJSON marshals the outer wsFrame envelope to JSON; a failure here means the frame struct itself cannot be serialized. Since wsFrame is fixed (Event string, Data []byte), this is nearly impossible in normal operation and signals a code-level change to the frame struct or a corrupted Data field.
Source
Thrown at platform/wps-agentspace/wpsagentspace.go:655
DeviceName: p.deviceName,
Timestamp: time.Now().UnixMilli(),
})
}
// writeJSON sends a JSON frame through the write channel.
func (p *Platform) writeJSON(event string, data any) error {
frame := wsFrame{
Event: event,
}
jsonData, err := json.Marshal(data)
if err != nil {
return fmt.Errorf("wps-agentspace: marshal: %w", err)
}
frame.Data = jsonData
raw, err := json.Marshal(frame)
if err != nil {
return fmt.Errorf("wps-agentspace: marshal frame: %w", err)
}
select {
case p.writeCh <- raw:
return nil
default:
return fmt.Errorf("wps-agentspace: write buffer full")
}
}
// writeLoop serializes all WebSocket writes.
func (p *Platform) writeLoop(conn *websocket.Conn) {
for msg := range p.writeCh {
if p.stopped.Load() {
return
}
// msg is already JSON-encoded bytes from writeJSON
if err := conn.WriteMessage(websocket.TextMessage, msg.([]byte)); err != nil {View on GitHub (pinned to 4000b2338a)
Solutions
- Check recent changes to the wsFrame struct for unserializable fields
- Inspect the wrapped inner error for the failing Go path
- Revert the struct change or implement MarshalJSON for the new field type
Example fix
// before
type wsFrame struct {
Event string
Data []byte
Callback func() // unserializable
}
// after
type wsFrame struct {
Event string
Data []byte
} Defensive patterns
Strategy: validation
Validate before calling
func assertFrameSerializable(f wsFrame) error { _, err := json.Marshal(f); return err } Try / catch
if err := p.sendText(chatID, text); err != nil { if strings.Contains(err.Error(), "marshal frame:") { slog.Error("frame serialization failed", "err", err) } } Prevention
- Never add unserializable fields to wsFrame
- Add a marshaling round-trip test for wsFrame
- Use []byte fields only for already-serialized data
When it happens
Trigger: Calling writeJSON (via sendInit, heartbeatLoop, handleFrame, sendText, sendTyping) after wsFrame has been modified to include unserializable fields, or Data has been altered.
Common situations: A developer adds a field of unsupported type to wsFrame or embeds a struct with cyclic references; production builds then fail on every send.
Understand the failure class
Background: json.Marshal / "failed to marshal" errors in Go: why "unsupported type" happens and how to fix it — this error's family across 22 libraries.
Related errors
- wps-agentspace: marshal: %w
- marshal: %w
- codex app-server encode: %w
- marshal: %w
- piSession: marshal command: %w
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/2cd52095e4da18d2.
Report an issue: GitHub.