errors.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package connection
  2. import (
  3. "github.com/cloudflare/cloudflared/edgediscovery"
  4. "github.com/cloudflare/cloudflared/h2mux"
  5. tunnelpogs "github.com/cloudflare/cloudflared/tunnelrpc/pogs"
  6. )
  7. const (
  8. DuplicateConnectionError = "EDUPCONN"
  9. )
  10. type DupConnRegisterTunnelError struct{}
  11. var errDuplicationConnection = DupConnRegisterTunnelError{}
  12. func (e DupConnRegisterTunnelError) Error() string {
  13. return "already connected to this server, trying another address"
  14. }
  15. // RegisterTunnel error from server
  16. type ServerRegisterTunnelError struct {
  17. Cause error
  18. Permanent bool
  19. }
  20. func (e ServerRegisterTunnelError) Error() string {
  21. return e.Cause.Error()
  22. }
  23. func serverRegistrationErrorFromRPC(err error) ServerRegisterTunnelError {
  24. if retryable, ok := err.(*tunnelpogs.RetryableError); ok {
  25. return ServerRegisterTunnelError{
  26. Cause: retryable.Unwrap(),
  27. Permanent: false,
  28. }
  29. }
  30. return ServerRegisterTunnelError{
  31. Cause: err,
  32. Permanent: true,
  33. }
  34. }
  35. type muxerShutdownError struct{}
  36. func (e muxerShutdownError) Error() string {
  37. return "muxer shutdown"
  38. }
  39. var errMuxerStopped = muxerShutdownError{}
  40. func isHandshakeErrRecoverable(err error, connIndex uint8, observer *Observer) bool {
  41. log := observer.log.With().
  42. Uint8(LogFieldConnIndex, connIndex).
  43. Err(err).
  44. Logger()
  45. switch err.(type) {
  46. case edgediscovery.DialError:
  47. log.Error().Msg("Connection unable to dial edge")
  48. case h2mux.MuxerHandshakeError:
  49. log.Error().Msg("Connection handshake with edge server failed")
  50. default:
  51. log.Error().Msg("Connection failed")
  52. return false
  53. }
  54. return true
  55. }