MCPcopy Index your code
hub / github.com/coder/coder / nullJSON

Method nullJSON

coderd/x/chatd/chatdebug/service.go:706–732  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

704// never need to be cleared during normal operation. The jsonClear
705// sentinel exists for the sole exception (error retry clearing).
706func (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
734func (s *Service) publishEvent(
735 ctx context.Context,

Callers 4

CreateRunMethod · 0.95
UpdateRunMethod · 0.95
CreateStepMethod · 0.95
UpdateStepMethod · 0.95

Calls 3

MarshalMethod · 0.45
ErrorMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected