errors.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. Copyright The containerd Authors.
  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 cni
  14. import (
  15. "errors"
  16. )
  17. var (
  18. ErrCNINotInitialized = errors.New("cni plugin not initialized")
  19. ErrInvalidConfig = errors.New("invalid cni config")
  20. ErrNotFound = errors.New("not found")
  21. ErrRead = errors.New("failed to read config file")
  22. ErrInvalidResult = errors.New("invalid result")
  23. ErrLoad = errors.New("failed to load cni config")
  24. )
  25. // IsCNINotInitialized returns true if the error is due to cni config not being initialized
  26. func IsCNINotInitialized(err error) bool {
  27. return errors.Is(err, ErrCNINotInitialized)
  28. }
  29. // IsInvalidConfig returns true if the error is invalid cni config
  30. func IsInvalidConfig(err error) bool {
  31. return errors.Is(err, ErrInvalidConfig)
  32. }
  33. // IsNotFound returns true if the error is due to a missing config or result
  34. func IsNotFound(err error) bool {
  35. return errors.Is(err, ErrNotFound)
  36. }
  37. // IsReadFailure return true if the error is a config read failure
  38. func IsReadFailure(err error) bool {
  39. return errors.Is(err, ErrRead)
  40. }
  41. // IsInvalidResult return true if the error is due to invalid cni result
  42. func IsInvalidResult(err error) bool {
  43. return errors.Is(err, ErrInvalidResult)
  44. }