MCPcopy Index your code
hub / github.com/mudler/LocalAI / isConnectionError

Function isConnectionError

pkg/model/connection_errors.go:15–35  ·  view source on GitHub ↗

isConnectionError returns true if the error indicates the remote endpoint is unreachable (connection refused, reset, gRPC Unavailable). Returns false for timeouts and deadline exceeded — those may indicate a busy server, not a dead one.

(err error)

Source from the content-addressed store, hash-verified

13// unreachable (connection refused, reset, gRPC Unavailable). Returns false for
14// timeouts and deadline exceeded — those may indicate a busy server, not a dead one.
15func isConnectionError(err error) bool {
16 if err == nil {
17 return false
18 }
19
20 // gRPC Unavailable = server not reachable (covers connection refused, DNS, TLS errors)
21 if s, ok := status.FromError(err); ok && s.Code() == codes.Unavailable {
22 return true
23 }
24
25 // Syscall-level connection errors
26 if errors.Is(err, syscall.ECONNREFUSED) || errors.Is(err, syscall.ECONNRESET) {
27 return true
28 }
29
30 // Fallback string matching for wrapped errors that lose the typed error
31 msg := err.Error()
32 return strings.Contains(msg, "connection refused") ||
33 strings.Contains(msg, "connection reset") ||
34 strings.Contains(msg, "no such host")
35}

Callers 2

checkErrMethod · 0.85
checkIsLoadedMethod · 0.85

Calls 3

ContainsMethod · 0.80
IsMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected