MCPcopy Create free account
hub / github.com/modelcontextprotocol/go-sdk / mustNotPanic

Function mustNotPanic

mcp/streamable_test.go:2466–2478  ·  view source on GitHub ↗

mustNotPanic is a helper to enforce that test handlers do not panic (see issue #556).

(t *testing.T, h http.Handler)

Source from the content-addressed store, hash-verified

2464// mustNotPanic is a helper to enforce that test handlers do not panic (see
2465// issue #556).
2466func mustNotPanic(t *testing.T, h http.Handler) http.Handler {
2467 return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
2468 defer func() {
2469 if r := recover(); r != nil {
2470 buf := make([]byte, 1<<20)
2471 n := runtime.Stack(buf, false)
2472 fmt.Fprintf(os.Stderr, "handler panic: %v\n\n%s", r, buf[:n])
2473 t.Errorf("handler panicked: %v", r)
2474 }
2475 }()
2476 h.ServeHTTP(w, req)
2477 })
2478}
2479
2480// TestPingEventFiltering verifies that the streamable client correctly filters
2481// out SSE "ping" events, which are used for keep-alive but should not be

Calls 1

ServeHTTPMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…