[#1693] services: Replace conditional panics with asserts

Change-Id: Ic79609e6ad867caa88ad245b3014aa7fc32e05a8
Signed-off-by: Ekaterina Lebedeva <ekaterina.lebedeva@yadro.com>
This commit is contained in:
Ekaterina Lebedeva 2025-04-08 16:54:05 +03:00
parent fc6abe30b8
commit bc045b29e2
4 changed files with 14 additions and 13 deletions

View file

@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/assert"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/version"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/util/response"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/netmap"
@ -46,10 +47,12 @@ type NetworkInfo interface {
}
func NewExecutionService(s NodeState, v versionsdk.Version, netInfo NetworkInfo, respSvc *response.Service) Server {
if s == nil || netInfo == nil || !version.IsValid(v) || respSvc == nil {
// this should never happen, otherwise it programmers bug
panic("can't create netmap execution service")
}
// this should never happen, otherwise it's a programmer's bug
msg := "BUG: can't create netmap execution service"
assert.False(s == nil, msg, "node state is nil")
assert.False(netInfo == nil, msg, "network info is nil")
assert.False(respSvc == nil, msg, "response service is nil")
assert.True(version.IsValid(v), msg, "invalid version")
res := &executorSvc{
state: s,

View file

@ -3,6 +3,7 @@ package tombstone
import (
"fmt"
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/assert"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
lru "github.com/hashicorp/golang-lru/v2"
"go.uber.org/zap"
@ -49,9 +50,7 @@ func NewChecker(oo ...Option) *ExpirationChecker {
panicOnNil(cfg.tsSource, "Tombstone source")
cache, err := lru.New[string, uint64](cfg.cacheSize)
if err != nil {
panic(fmt.Errorf("could not create LRU cache with %d size: %w", cfg.cacheSize, err))
}
assert.NoError(err, fmt.Sprintf("could not create LRU cache with %d size", cfg.cacheSize))
return &ExpirationChecker{
cache: cache,

View file

@ -4,6 +4,7 @@ import (
"context"
"fmt"
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/assert"
getsvc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/get"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/util"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
@ -38,9 +39,7 @@ func (s *TombstoneSourcePrm) SetGetService(v *getsvc.Service) {
// Panics if any of the provided options does not allow
// constructing a valid tombstone local Source.
func NewSource(p TombstoneSourcePrm) Source {
if p.s == nil {
panic("Tombstone source: nil object service")
}
assert.False(p.s == nil, "Tombstone source: nil object service")
return Source(p)
}

View file

@ -1,9 +1,11 @@
package policer
import (
"fmt"
"sync"
"time"
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/assert"
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
lru "github.com/hashicorp/golang-lru/v2"
"go.uber.org/zap"
@ -57,9 +59,7 @@ func New(opts ...Option) *Policer {
c.log = c.log.With(zap.String("component", "Object Policer"))
cache, err := lru.New[oid.Address, time.Time](int(c.cacheSize))
if err != nil {
panic(err)
}
assert.NoError(err, fmt.Sprintf("could not create LRU cache with %d size", c.cacheSize))
return &Policer{
cfg: c,