mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-05 01:20:26 +08:00
50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
|
|
|
package caches
|
|
|
|
import "errors"
|
|
|
|
// 常用的几个错误
|
|
var (
|
|
ErrNotFound = errors.New("cache not found")
|
|
ErrFileIsWriting = errors.New("the cache file is updating")
|
|
ErrInvalidRange = errors.New("invalid range")
|
|
ErrEntityTooLarge = errors.New("entity too large")
|
|
ErrWritingUnavailable = errors.New("writing unavailable")
|
|
ErrWritingQueueFull = errors.New("writing queue full")
|
|
ErrTooManyOpenFiles = errors.New("too many open files")
|
|
)
|
|
|
|
// 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
|
|
}
|
|
if err == ErrFileIsWriting ||
|
|
err == ErrEntityTooLarge ||
|
|
err == ErrWritingUnavailable ||
|
|
err == ErrWritingQueueFull ||
|
|
err == ErrTooManyOpenFiles {
|
|
return true
|
|
}
|
|
_, ok := err.(*CapacityError)
|
|
if ok {
|
|
return true
|
|
}
|
|
return false
|
|
}
|