MCPcopy Create free account
hub / github.com/diillson/chatcli / recoveryStreamInterceptor

Function recoveryStreamInterceptor

server/middleware.go:125–150  ·  view source on GitHub ↗

recoveryStreamInterceptor recovers from panics in stream RPCs. Security (H11): Stack traces only logged in debug mode.

(logger *zap.Logger)

Source from the content-addressed store, hash-verified

123// recoveryStreamInterceptor recovers from panics in stream RPCs.
124// Security (H11): Stack traces only logged in debug mode.
125func recoveryStreamInterceptor(logger *zap.Logger) grpc.StreamServerInterceptor {
126 return func(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) (err error) {
127 requestID := uuid.New().String()
128
129 defer func() {
130 if r := recover(); r != nil {
131 if isDebugMode() {
132 logger.Error(i18n.T("server.middleware.panic_stream"),
133 zap.String("request_id", requestID),
134 zap.Any("panic", r),
135 zap.String("method", info.FullMethod),
136 zap.String("stack", string(debug.Stack())),
137 )
138 } else {
139 logger.Error("panic recovered (stream)",
140 zap.String("request_id", requestID),
141 zap.String("method", info.FullMethod),
142 zap.String("error", sanitizePanicValue(r)),
143 )
144 }
145 err = status.Errorf(codes.Internal, "internal error (request_id: %s)", requestID)
146 }
147 }()
148 return handler(srv, ss)
149 }
150}

Callers 1

NewFunction · 0.85

Calls 6

TFunction · 0.92
isDebugModeFunction · 0.85
sanitizePanicValueFunction · 0.85
ErrorfMethod · 0.80
ErrorMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected