nullJSON marshals value to a NullRawMessage. When value is nil (including typed nils such as `var p *T = nil` whose interface representation carries a type but no value) or marshals to JSON "null", the result is {Valid: false}. Typed nils fall through the `value == nil` guard but produce `[]byte("nu
(ctx context.Context, value any)
| 704 | // never need to be cleared during normal operation. The jsonClear |
| 705 | // sentinel exists for the sole exception (error retry clearing). |
| 706 | func (s *Service) nullJSON(ctx context.Context, value any) pqtype.NullRawMessage { |
| 707 | if value == nil { |
| 708 | return pqtype.NullRawMessage{} |
| 709 | } |
| 710 | // Sentinel: emit a valid JSONB null so COALESCE replaces |
| 711 | // any previously stored value. |
| 712 | if _, ok := value.(jsonClear); ok { |
| 713 | return pqtype.NullRawMessage{ |
| 714 | RawMessage: json.RawMessage("null"), |
| 715 | Valid: true, |
| 716 | } |
| 717 | } |
| 718 | |
| 719 | data, err := json.Marshal(value) |
| 720 | if err != nil { |
| 721 | s.log.Warn(ctx, "failed to marshal chat debug JSON", |
| 722 | slog.Error(err), |
| 723 | slog.F("value_type", fmt.Sprintf("%T", value)), |
| 724 | ) |
| 725 | return pqtype.NullRawMessage{} |
| 726 | } |
| 727 | if bytes.Equal(data, []byte("null")) { |
| 728 | return pqtype.NullRawMessage{} |
| 729 | } |
| 730 | |
| 731 | return pqtype.NullRawMessage{RawMessage: data, Valid: true} |
| 732 | } |
| 733 | |
| 734 | func (s *Service) publishEvent( |
| 735 | ctx context.Context, |
no test coverage detected