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

Function safeMarshalJSON

coderd/x/chatd/chatdebug/model.go:747–759  ·  view source on GitHub ↗

safeMarshalJSON marshals value to JSON. On failure it returns a diagnostic error object rather than panicking, which is appropriate for debug telemetry where a marshal failure should not crash the caller.

(label string, value any)

Source from the content-addressed store, hash-verified

745// for debug telemetry where a marshal failure should not crash the
746// caller.
747func safeMarshalJSON(label string, value any) json.RawMessage {
748 data, err := json.Marshal(value)
749 if err != nil {
750 fallback, fallbackErr := json.Marshal(map[string]string{
751 "error": fmt.Sprintf("chatdebug: failed to marshal %s: %v", label, err),
752 })
753 if fallbackErr == nil {
754 return append(json.RawMessage(nil), fallback...)
755 }
756 return json.RawMessage(`{"error":"chatdebug: failed to marshal value"}`)
757 }
758 return append(json.RawMessage(nil), data...)
759}
760
761func appendStreamContentText(
762 content []normalizedContentPart,

Callers 2

normalizeToolsFunction · 0.85

Calls 1

MarshalMethod · 0.45

Tested by

no test coverage detected