{"record":{"id":"7417e7ad7438973c","repo":"sipeed/picoclaw","slug":"failed-to-marshal-message-w","errorCode":null,"errorMessage":"failed to marshal message: %w","messagePattern":"failed to marshal message: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"info","filePath":"pkg/channels/whatsapp/whatsapp.go","lineNumber":138,"sourceCode":"\tdefault:\n\t}\n\n\tc.mu.Lock()\n\tdefer c.mu.Unlock()\n\n\tif c.conn == nil {\n\t\treturn nil, fmt.Errorf(\"whatsapp connection not established: %w\", channels.ErrTemporary)\n\t}\n\n\tpayload := map[string]any{\n\t\t\"type\":    \"message\",\n\t\t\"to\":      msg.ChatID,\n\t\t\"content\": msg.Content,\n\t}\n\n\tdata, err := json.Marshal(payload)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to marshal message: %w\", err)\n\t}\n\n\t_ = c.conn.SetWriteDeadline(time.Now().Add(10 * time.Second))\n\tif err := c.conn.WriteMessage(websocket.TextMessage, data); err != nil {\n\t\t_ = c.conn.SetWriteDeadline(time.Time{})\n\t\treturn nil, fmt.Errorf(\"whatsapp send: %w\", channels.ErrTemporary)\n\t}\n\t_ = c.conn.SetWriteDeadline(time.Time{})\n\n\treturn nil, nil\n}\n\nfunc (c *WhatsAppChannel) listen() {\n\tfor {\n\t\tselect {\n\t\tcase <-c.ctx.Done():\n\t\t\treturn\n\t\tdefault:","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/sipeed/picoclaw/blob/49183d7e8daed0dba89ddbb6fcb60089401d9680/pkg/channels/whatsapp/whatsapp.go#L120-L156","documentation":"Returned when json.Marshal fails on the outbound payload map {type, to, content} in the WhatsApp bridge channel's Send. Because all three values are Go strings, this branch is effectively unreachable in practice - encoding/json never fails on string values (invalid UTF-8 is replaced with U+FFFD). Marshal only errors on unsupported types (chan, func, complex, NaN/Inf floats) which cannot occur here.","triggerScenarios":"Theoretically only if msg.Content or msg.ChatID were changed to a non-marshalable type in a future refactor of bus.OutboundMessage. No runtime input can trigger it today.","commonSituations":"Essentially never hit; appears in error catalogues as dead defensive code. If it does appear after a refactor, a field type changed to something json cannot encode.","solutions":["If encountered after modifying message structs, verify msg.Content and msg.ChatID remain strings.","No action needed otherwise - this is defensive dead code for an all-string payload."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":"if _, err := ch.Send(ctx, msg); err != nil && strings.Contains(err.Error(), \"failed to marshal message\") {\n    // unreachable in current code; treat as a bug and report upstream\n}","preventionTips":["No runtime prevention needed for an all-string payload.","If refactoring OutboundMessage field types, keep them JSON-marshalable to preserve this guarantee."],"tags":["whatsapp","json","unreachable","dead-code"],"backgroundTag":null,"analyzedSha":"49183d7e8daed0dba89ddbb6fcb60089401d9680","analyzedAt":"2026-08-15T21:55:41.315Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}