Files
EdgeNode/internal/caches/errors.go

50 lines
1.2 KiB
Go
Raw Normal View History

2021-06-08 11:24:41 +08:00
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package caches
import "errors"
// 常用的几个错误
var (
2022-03-15 18:32:39 +08:00
ErrNotFound = errors.New("cache not found")
2023-07-26 19:12:02 +08:00
ErrFileIsWriting = errors.New("the cache file is updating")
2022-03-15 18:32:39 +08:00
ErrInvalidRange = errors.New("invalid range")
ErrEntityTooLarge = errors.New("entity too large")
ErrWritingUnavailable = errors.New("writing unavailable")
ErrWritingQueueFull = errors.New("writing queue full")
2022-04-13 19:24:23 +08:00
ErrTooManyOpenFiles = errors.New("too many open files")
2021-06-08 11:24:41 +08:00
)
// CapacityError 容量错误
// 独立出来是为了可以在有些场合下可以忽略,防止产生没必要的错误提示数量太多
type CapacityError struct {
err string
}
func NewCapacityError(err string) error {
return &CapacityError{err: err}
}
func (this *CapacityError) Error() string {
return this.err
}
// CanIgnoreErr 检查错误是否可以忽略
func CanIgnoreErr(err error) bool {
if err == nil {
return true
}
2022-03-15 18:32:39 +08:00
if err == ErrFileIsWriting ||
err == ErrEntityTooLarge ||
err == ErrWritingUnavailable ||
2022-04-13 19:24:23 +08:00
err == ErrWritingQueueFull ||
err == ErrTooManyOpenFiles {
2021-06-08 11:24:41 +08:00
return true
}
_, ok := err.(*CapacityError)
if ok {
return true
}
return false
}