errors.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. Copyright 2014 CoreOS, Inc.
  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. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package etcdserver
  14. import (
  15. "errors"
  16. etcdErr "github.com/coreos/etcd/error"
  17. "github.com/coreos/etcd/Godeps/_workspace/src/golang.org/x/net/context"
  18. )
  19. var (
  20. ErrUnknownMethod = errors.New("etcdserver: unknown method")
  21. ErrStopped = errors.New("etcdserver: server stopped")
  22. ErrIDRemoved = errors.New("etcdserver: ID removed")
  23. ErrIDExists = errors.New("etcdserver: ID exists")
  24. ErrIDNotFound = errors.New("etcdserver: ID not found")
  25. ErrPeerURLexists = errors.New("etcdserver: peerURL exists")
  26. ErrCanceled = errors.New("etcdserver: request cancelled")
  27. ErrTimeout = errors.New("etcdserver: request timed out")
  28. )
  29. func parseCtxErr(err error) error {
  30. switch err {
  31. case context.Canceled:
  32. return ErrCanceled
  33. case context.DeadlineExceeded:
  34. return ErrTimeout
  35. default:
  36. return err
  37. }
  38. }
  39. func isKeyNotFound(err error) bool {
  40. e, ok := err.(*etcdErr.Error)
  41. return ok && e.ErrorCode == etcdErr.EcodeKeyNotFound
  42. }