forked from TrueCloudLab/frostfs-node
[#552] cmd/node: Implement error checker with details
Implement function `fatalOnErrDetails` similar to `fatalOnErr` but accepting string details that are written to log output. Use the function everywhere in application code without wrapping in an if-else statement. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
ead4513feb
commit
6b1916a529
3 changed files with 13 additions and 13 deletions
|
@ -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))
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue