123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- package volume
- import (
- "fmt"
- )
- const (
-
- ErrCodeNotSupported int = iota + 1
- ErrCodeNoPathDefined
- ErrCodeFsInfoFailed
- )
- func NewNotSupportedError() *MetricsError {
- return &MetricsError{
- Code: ErrCodeNotSupported,
- Msg: "metrics are not supported for MetricsNil Volumes",
- }
- }
- func NewNotSupportedErrorWithDriverName(name string) *MetricsError {
- return &MetricsError{
- Code: ErrCodeNotSupported,
- Msg: fmt.Sprintf("metrics are not supported for %s volumes", name),
- }
- }
- func NewNoPathDefinedError() *MetricsError {
- return &MetricsError{
- Code: ErrCodeNoPathDefined,
- Msg: "no path defined for disk usage metrics.",
- }
- }
- func NewFsInfoFailedError(err error) *MetricsError {
- return &MetricsError{
- Code: ErrCodeFsInfoFailed,
- Msg: fmt.Sprintf("Failed to get FsInfo due to error %v", err),
- }
- }
- type MetricsError struct {
- Code int
- Msg string
- }
- func (e *MetricsError) Error() string {
- return fmt.Sprintf("%s", e.Msg)
- }
- func IsNotSupported(err error) bool {
- return isErrCode(err, ErrCodeNotSupported)
- }
- func isErrCode(err error, code int) bool {
- if err == nil {
- return false
- }
- if e, ok := err.(*MetricsError); ok {
- return e.Code == code
- }
- return false
- }
|