[#1969] local_object_storage: Simplify logic error construction

Signed-off-by: Evgenii Stratonikov <evgeniy@morphbits.ru>
This commit is contained in:
Evgenii Stratonikov 2022-10-31 10:02:30 +03:00 committed by fyrchik
parent fcdbf5e509
commit 56de2f1363
17 changed files with 25 additions and 36 deletions

View file

@ -1,12 +1,10 @@
package object package object
import ( import (
"errors"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr"
) )
// ErrObjectIsExpired is returned when the requested object's // ErrObjectIsExpired is returned when the requested object's
// epoch is less than the current one. Such objects are considered // epoch is less than the current one. Such objects are considered
// as removed and should not be returned from the Storage Engine. // as removed and should not be returned from the Storage Engine.
var ErrObjectIsExpired = logicerr.Wrap(errors.New("object is expired")) var ErrObjectIsExpired = logicerr.New("object is expired")

View file

@ -1,14 +1,12 @@
package common package common
import ( import (
"errors"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr"
) )
// ErrReadOnly MUST be returned for modifying operations when the storage was opened // ErrReadOnly MUST be returned for modifying operations when the storage was opened
// in readonly mode. // in readonly mode.
var ErrReadOnly = logicerr.Wrap(errors.New("opened as read-only")) var ErrReadOnly = logicerr.New("opened as read-only")
// ErrNoSpace MUST be returned when there is no space to put an object on the device. // ErrNoSpace MUST be returned when there is no space to put an object on the device.
var ErrNoSpace = logicerr.Wrap(errors.New("no free space")) var ErrNoSpace = logicerr.New("no free space")

View file

@ -1,7 +1,6 @@
package blobstor package blobstor
import ( import (
"errors"
"fmt" "fmt"
"github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/core/object"
@ -12,7 +11,7 @@ import (
// ErrNoPlaceFound is returned when object can't be saved to any sub-storage component // ErrNoPlaceFound is returned when object can't be saved to any sub-storage component
// because of the policy. // because of the policy.
var ErrNoPlaceFound = logicerr.Wrap(errors.New("couldn't find a place to store an object")) var ErrNoPlaceFound = logicerr.New("couldn't find a place to store an object")
// Put saves the object in BLOB storage. // Put saves the object in BLOB storage.
// //

View file

@ -1,7 +1,6 @@
package engine package engine
import ( import (
"errors"
"fmt" "fmt"
"github.com/google/uuid" "github.com/google/uuid"
@ -15,7 +14,7 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
) )
var errShardNotFound = logicerr.Wrap(errors.New("shard not found")) var errShardNotFound = logicerr.New("shard not found")
type hashedShard shardWrapper type hashedShard shardWrapper

View file

@ -13,7 +13,7 @@ import (
) )
// ErrDegradedMode is returned when metabase is in a degraded mode. // ErrDegradedMode is returned when metabase is in a degraded mode.
var ErrDegradedMode = logicerr.Wrap(errors.New("metabase is in a degraded mode")) var ErrDegradedMode = logicerr.New("metabase is in a degraded mode")
// Open boltDB instance for metabase. // Open boltDB instance for metabase.
func (db *DB) Open(readOnly bool) error { func (db *DB) Open(readOnly bool) error {

View file

@ -1,7 +1,6 @@
package meta package meta
import ( import (
"errors"
"fmt" "fmt"
"strconv" "strconv"
@ -25,7 +24,7 @@ type ExistsRes struct {
exists bool exists bool
} }
var ErrLackSplitInfo = logicerr.Wrap(errors.New("no split info on parent object")) var ErrLackSplitInfo = logicerr.New("no split info on parent object")
// SetAddress is an Exists option to set object checked for existence. // SetAddress is an Exists option to set object checked for existence.
func (p *ExistsPrm) SetAddress(addr oid.Address) { func (p *ExistsPrm) SetAddress(addr oid.Address) {

View file

@ -79,7 +79,7 @@ var errBreakBucketForEach = errors.New("bucket ForEach break")
// ErrLockObjectRemoval is returned when inhume operation is being // ErrLockObjectRemoval is returned when inhume operation is being
// performed on lock object, and it is not a forced object removal. // performed on lock object, and it is not a forced object removal.
var ErrLockObjectRemoval = logicerr.Wrap(errors.New("lock object removal")) var ErrLockObjectRemoval = logicerr.New("lock object removal")
// Inhume marks objects as removed but not removes it from metabase. // Inhume marks objects as removed but not removes it from metabase.
// //

View file

@ -35,7 +35,7 @@ type ExpiredObjectHandler func(*ExpiredObject) error
// ErrInterruptIterator is returned by iteration handlers // ErrInterruptIterator is returned by iteration handlers
// as a "break" keyword. // as a "break" keyword.
var ErrInterruptIterator = logicerr.Wrap(errors.New("iterator is interrupted")) var ErrInterruptIterator = logicerr.New("iterator is interrupted")
// IterateExpired iterates over all objects in DB which are out of date // IterateExpired iterates over all objects in DB which are out of date
// relative to epoch. Locked objects are not included (do not confuse // relative to epoch. Locked objects are not included (do not confuse

View file

@ -1,8 +1,6 @@
package meta package meta
import ( import (
"errors"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr"
cid "github.com/nspcc-dev/neofs-sdk-go/container/id" cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
oid "github.com/nspcc-dev/neofs-sdk-go/object/id" oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
@ -12,7 +10,7 @@ import (
// ErrEndOfListing is returned from object listing with cursor // ErrEndOfListing is returned from object listing with cursor
// when storage can't return any more objects after provided // when storage can't return any more objects after provided
// cursor. Use nil cursor object to start listing again. // cursor. Use nil cursor object to start listing again.
var ErrEndOfListing = logicerr.Wrap(errors.New("end of object listing")) var ErrEndOfListing = logicerr.New("end of object listing")
// Cursor is a type for continuous object listing. // Cursor is a type for continuous object listing.
type Cursor struct { type Cursor struct {

View file

@ -2,7 +2,6 @@ package meta
import ( import (
"encoding/binary" "encoding/binary"
"errors"
"fmt" "fmt"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr"
@ -17,7 +16,7 @@ var versionKey = []byte("version")
// ErrOutdatedVersion is returned on initializing // ErrOutdatedVersion is returned on initializing
// an existing metabase that is not compatible with // an existing metabase that is not compatible with
// the current code version. // the current code version.
var ErrOutdatedVersion = logicerr.Wrap(errors.New("invalid version, resynchronization is required")) var ErrOutdatedVersion = logicerr.New("invalid version, resynchronization is required")
func checkVersion(tx *bbolt.Tx, initialized bool) error { func checkVersion(tx *bbolt.Tx, initialized bool) error {
var knownVersion bool var knownVersion bool

View file

@ -1,8 +1,6 @@
package pilorama package pilorama
import ( import (
"errors"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard/mode" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard/mode"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr"
cidSDK "github.com/nspcc-dev/neofs-sdk-go/container/id" cidSDK "github.com/nspcc-dev/neofs-sdk-go/container/id"
@ -68,7 +66,7 @@ type CIDDescriptor struct {
// ErrInvalidCIDDescriptor is returned when info about tne node position // ErrInvalidCIDDescriptor is returned when info about tne node position
// in the container is invalid. // in the container is invalid.
var ErrInvalidCIDDescriptor = logicerr.Wrap(errors.New("cid descriptor is invalid")) var ErrInvalidCIDDescriptor = logicerr.New("cid descriptor is invalid")
func (d CIDDescriptor) checkValid() bool { func (d CIDDescriptor) checkValid() bool {
return 0 <= d.Position && d.Position < d.Size return 0 <= d.Position && d.Position < d.Size

View file

@ -2,7 +2,6 @@ package shard
import ( import (
"encoding/binary" "encoding/binary"
"errors"
"io" "io"
"os" "os"
@ -47,7 +46,7 @@ func (r DumpRes) Count() int {
return r.count return r.count
} }
var ErrMustBeReadOnly = logicerr.Wrap(errors.New("shard must be in read-only mode")) var ErrMustBeReadOnly = logicerr.New("shard must be in read-only mode")
// Dump dumps all objects from the shard to a file or stream. // Dump dumps all objects from the shard to a file or stream.
// //

View file

@ -1,18 +1,16 @@
package shard package shard
import ( import (
"errors"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard/mode" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard/mode"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr"
) )
// ErrReadOnlyMode is returned when it is impossible to apply operation // ErrReadOnlyMode is returned when it is impossible to apply operation
// that changes shard's memory due to the "read-only" shard's mode. // that changes shard's memory due to the "read-only" shard's mode.
var ErrReadOnlyMode = logicerr.Wrap(errors.New("shard is in read-only mode")) var ErrReadOnlyMode = logicerr.New("shard is in read-only mode")
// ErrDegradedMode is returned when operation requiring metabase is executed in degraded mode. // ErrDegradedMode is returned when operation requiring metabase is executed in degraded mode.
var ErrDegradedMode = logicerr.Wrap(errors.New("shard is in degraded mode")) var ErrDegradedMode = logicerr.New("shard is in degraded mode")
// SetMode sets mode of the shard. // SetMode sets mode of the shard.
// //

View file

@ -12,7 +12,7 @@ import (
) )
// ErrInvalidMagic is returned when dump format is invalid. // ErrInvalidMagic is returned when dump format is invalid.
var ErrInvalidMagic = logicerr.Wrap(errors.New("invalid magic")) var ErrInvalidMagic = logicerr.New("invalid magic")
// RestorePrm groups the parameters of Restore operation. // RestorePrm groups the parameters of Restore operation.
type RestorePrm struct { type RestorePrm struct {

View file

@ -1,8 +1,6 @@
package shard package shard
import ( import (
"errors"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/pilorama" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/pilorama"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr"
cidSDK "github.com/nspcc-dev/neofs-sdk-go/container/id" cidSDK "github.com/nspcc-dev/neofs-sdk-go/container/id"
@ -11,7 +9,7 @@ import (
var _ pilorama.Forest = (*Shard)(nil) var _ pilorama.Forest = (*Shard)(nil)
// ErrPiloramaDisabled is returned when pilorama was disabled in the configuration. // ErrPiloramaDisabled is returned when pilorama was disabled in the configuration.
var ErrPiloramaDisabled = logicerr.Wrap(errors.New("pilorama is disabled")) var ErrPiloramaDisabled = logicerr.New("pilorama is disabled")
// TreeMove implements the pilorama.Forest interface. // TreeMove implements the pilorama.Forest interface.
func (s *Shard) TreeMove(d pilorama.CIDDescriptor, treeID string, m *pilorama.Move) (*pilorama.LogMove, error) { func (s *Shard) TreeMove(d pilorama.CIDDescriptor, treeID string, m *pilorama.Move) (*pilorama.LogMove, error) {

View file

@ -1,10 +1,17 @@
package logicerr package logicerr
import "errors"
// Logical is a wrapper for logical errors. // Logical is a wrapper for logical errors.
type Logical struct { type Logical struct {
err error err error
} }
// New returns simple error with a provided error message.
func New(msg string) Logical {
return Wrap(errors.New(msg))
}
// Error implements the error interface. // Error implements the error interface.
func (e Logical) Error() string { func (e Logical) Error() string {
return e.err.Error() return e.err.Error()

View file

@ -1,7 +1,6 @@
package writecache package writecache
import ( import (
"errors"
"fmt" "fmt"
"time" "time"
@ -10,7 +9,7 @@ import (
) )
// ErrReadOnly is returned when Put/Write is performed in a read-only mode. // ErrReadOnly is returned when Put/Write is performed in a read-only mode.
var ErrReadOnly = logicerr.Wrap(errors.New("write-cache is in read-only mode")) var ErrReadOnly = logicerr.New("write-cache is in read-only mode")
// SetMode sets write-cache mode of operation. // SetMode sets write-cache mode of operation.
// When shard is put in read-only mode all objects in memory are flushed to disk // When shard is put in read-only mode all objects in memory are flushed to disk