MCPcopy
hub / github.com/connectrpc/connect-go / wrapIfLikelyWithGRPCNotUsedError

Function wrapIfLikelyWithGRPCNotUsedError

error.go:366–382  ·  view source on GitHub ↗

wrapIfLikelyWithGRPCNotUsedError adds a wrapping error that has a message telling the caller that they likely forgot to use connect.WithGRPC(). This happens when running a gRPC-only server. This is fragile and may break over time, and this should be considered a best-effort.

(err error)

Source from the content-addressed store, hash-verified

364// This happens when running a gRPC-only server.
365// This is fragile and may break over time, and this should be considered a best-effort.
366func wrapIfLikelyWithGRPCNotUsedError(err error) error {
367 if err == nil {
368 return nil
369 }
370 if _, ok := asError(err); ok {
371 return err
372 }
373 // golang.org/x/net code has been investigated and there is no typing of this error
374 // it is created with fmt.Errorf
375 // http2/transport.go:573: return nil, fmt.Errorf("http2: Transport: cannot retry err [%v] after Request.Body was written; define Request.GetBody to avoid this error", err)
376 if errString := err.Error(); strings.HasPrefix(errString, `Post "`) &&
377 strings.Contains(errString, `http2: Transport: cannot retry err`) &&
378 strings.HasSuffix(errString, `after Request.Body was written; define Request.GetBody to avoid this error`) {
379 return fmt.Errorf("possible missing connect.WithGPRC() client option when talking to gRPC server, see %s: %w", commonErrorsURL, err)
380 }
381 return err
382}
383
384// HTTP/2 has its own set of error codes, which it sends in RST_STREAM frames.
385// When the server sends one of these errors, we should map it back into our

Callers 1

makeRequestMethod · 0.85

Calls 3

asErrorFunction · 0.85
ErrorMethod · 0.80
ContainsMethod · 0.65

Tested by

no test coverage detected