diff --git a/cmd/neofs-node/grpc.go b/cmd/neofs-node/grpc.go index 6f7205a33d..588df30735 100644 --- a/cmd/neofs-node/grpc.go +++ b/cmd/neofs-node/grpc.go @@ -22,9 +22,7 @@ func initGRPC(c *cfg) { if c.cfgGRPC.tlsEnabled { creds, err := credentials.NewServerTLSFromFile(c.cfgGRPC.tlsCertFile, c.cfgGRPC.tlsKeyFile) - if err != nil { - fatalOnErr(fmt.Errorf("could not read credentionals from file: %w", err)) - } + fatalOnErrDetails("could not read credentials from file", err) serverOpts = append(serverOpts, grpc.Creds(creds)) } diff --git a/cmd/neofs-node/main.go b/cmd/neofs-node/main.go index 50350b1a48..70f891f22c 100644 --- a/cmd/neofs-node/main.go +++ b/cmd/neofs-node/main.go @@ -3,6 +3,7 @@ package main import ( "context" "flag" + "fmt" "log" "github.com/nspcc-dev/neofs-node/misc" @@ -11,12 +12,20 @@ import ( "go.uber.org/zap" ) +// prints err to standard logger and calls os.Exit(1). func fatalOnErr(err error) { if err != nil { log.Fatal(err) } } +// prints err with details to standard logger and calls os.Exit(1). +func fatalOnErrDetails(details string, err error) { + if err != nil { + log.Fatal(fmt.Errorf("%s: %w", details, err)) + } +} + func main() { configFile := flag.String("config", "", "path to config") flag.Parse() diff --git a/cmd/neofs-node/netmap.go b/cmd/neofs-node/netmap.go index 216aeb3ddf..249e6f1811 100644 --- a/cmd/neofs-node/netmap.go +++ b/cmd/neofs-node/netmap.go @@ -2,7 +2,6 @@ package main import ( "bytes" - "fmt" netmapSDK "github.com/nspcc-dev/neofs-api-go/pkg/netmap" netmapV2 "github.com/nspcc-dev/neofs-api-go/v2/netmap" @@ -111,9 +110,7 @@ func bootstrapNode(c *cfg) { initState(c) err := c.cfgNetmap.wrapper.AddPeer(c.toOnlineLocalNodeInfo()) - if err != nil { - fatalOnErr(fmt.Errorf("bootstrap error: %w", err)) - } + fatalOnErrDetails("bootstrap error", err) } func addNetmapNotificationHandler(c *cfg, sTyp string, h event.Handler) { @@ -138,14 +135,10 @@ func setNetmapNotificationParser(c *cfg, sTyp string, p event.Parser) { func initState(c *cfg) { epoch, err := c.cfgNetmap.wrapper.Epoch() - if err != nil { - fatalOnErr(fmt.Errorf("could not initialize current epoch number: %w", err)) - } + fatalOnErrDetails("could not initialize current epoch number", err) ni, err := c.netmapLocalNodeState(epoch) - if err != nil { - fatalOnErr(fmt.Errorf("could not init network state: %w", err)) - } + fatalOnErrDetails("could not init network state", err) c.handleNodeInfoStatus(ni)