errors.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright 2015 CoreOS, Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package etcdserver
  15. import (
  16. "errors"
  17. "fmt"
  18. etcdErr "github.com/coreos/etcd/error"
  19. )
  20. var (
  21. ErrUnknownMethod = errors.New("etcdserver: unknown method")
  22. ErrStopped = errors.New("etcdserver: server stopped")
  23. ErrIDRemoved = errors.New("etcdserver: ID removed")
  24. ErrIDExists = errors.New("etcdserver: ID exists")
  25. ErrIDNotFound = errors.New("etcdserver: ID not found")
  26. ErrPeerURLexists = errors.New("etcdserver: peerURL exists")
  27. ErrCanceled = errors.New("etcdserver: request cancelled")
  28. ErrTimeout = errors.New("etcdserver: request timed out")
  29. ErrTimeoutDueToLeaderFail = errors.New("etcdserver: request timed out, possibly due to previous leader failure")
  30. ErrTimeoutDueToConnectionLost = errors.New("etcdserver: request timed out, possibly due to connection lost")
  31. ErrNotEnoughStartedMembers = errors.New("etcdserver: re-configuration failed due to not enough started members")
  32. ErrNoLeader = errors.New("etcdserver: no leader")
  33. ErrRequestTooLarge = errors.New("etcdserver: request is too large")
  34. )
  35. func isKeyNotFound(err error) bool {
  36. e, ok := err.(*etcdErr.Error)
  37. return ok && e.ErrorCode == etcdErr.EcodeKeyNotFound
  38. }
  39. type DiscoveryError struct {
  40. Op string
  41. Err error
  42. }
  43. func (e DiscoveryError) Error() string {
  44. return fmt.Sprintf("failed to %s discovery cluster (%v)", e.Op, e.Err)
  45. }