errors.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright 2019 Yunion
  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. /*
  15. Copyright 2015 The Kubernetes Authors.
  16. Licensed under the Apache License, Version 2.0 (the "License");
  17. you may not use this file except in compliance with the License.
  18. You may obtain a copy of the License at
  19. http://www.apache.org/licenses/LICENSE-2.0
  20. Unless required by applicable law or agreed to in writing, software
  21. distributed under the License is distributed on an "AS IS" BASIS,
  22. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  23. See the License for the specific language governing permissions and
  24. limitations under the License.
  25. */
  26. package exec
  27. import "time"
  28. // NewTimeoutError returns a new TimeoutError.
  29. func NewTimeoutError(err error, timeout time.Duration) *TimeoutError {
  30. return &TimeoutError{
  31. err: err,
  32. timeout: timeout,
  33. }
  34. }
  35. // TimeoutError is an error returned on exec probe timeouts. It should be returned by CRI implementations
  36. // in order for the exec prober to interpret exec timeouts as failed probes.
  37. // TODO: this error type can likely be removed when we support CRI errors.
  38. type TimeoutError struct {
  39. err error
  40. timeout time.Duration
  41. }
  42. // Error returns the error string.
  43. func (t *TimeoutError) Error() string {
  44. return t.err.Error()
  45. }
  46. // Timeout returns the timeout duration of the exec probe.
  47. func (t *TimeoutError) Timeout() time.Duration {
  48. return t.timeout
  49. }