errors.go 1.7 KB

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