From b5256ccf4c8edcdafb90a5ea7ed2a3a9d06f1ea5 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Wed, 19 May 2021 18:36:03 +0300 Subject: [PATCH] [#521] Fix issues with transition from `pkg/errors` pkg Wrap functions at `pkg/errors` return nil if error argument was nil. fmt.Errorf always returns error so we need to add missing error checks to the code. Signed-off-by: Alex Vanin --- cmd/neofs-node/netmap.go | 12 +++++++++--- pkg/core/object/fmt.go | 2 +- pkg/services/object/put/streamer.go | 6 ++++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/cmd/neofs-node/netmap.go b/cmd/neofs-node/netmap.go index 0efbfb817..216aeb3dd 100644 --- a/cmd/neofs-node/netmap.go +++ b/cmd/neofs-node/netmap.go @@ -111,7 +111,9 @@ func bootstrapNode(c *cfg) { initState(c) err := c.cfgNetmap.wrapper.AddPeer(c.toOnlineLocalNodeInfo()) - fatalOnErr(fmt.Errorf("bootstrap error: %w", err)) + if err != nil { + fatalOnErr(fmt.Errorf("bootstrap error: %w", err)) + } } func addNetmapNotificationHandler(c *cfg, sTyp string, h event.Handler) { @@ -136,10 +138,14 @@ func setNetmapNotificationParser(c *cfg, sTyp string, p event.Parser) { func initState(c *cfg) { epoch, err := c.cfgNetmap.wrapper.Epoch() - fatalOnErr(fmt.Errorf("could not initialize current epoch number: %w", err)) + if err != nil { + fatalOnErr(fmt.Errorf("could not initialize current epoch number: %w", err)) + } ni, err := c.netmapLocalNodeState(epoch) - fatalOnErr(fmt.Errorf("could not init network state: %w", err)) + if err != nil { + fatalOnErr(fmt.Errorf("could not init network state: %w", err)) + } c.handleNodeInfoStatus(ni) diff --git a/pkg/core/object/fmt.go b/pkg/core/object/fmt.go index 9051944d6..29ef45b27 100644 --- a/pkg/core/object/fmt.go +++ b/pkg/core/object/fmt.go @@ -81,7 +81,7 @@ func (v *FormatValidator) Validate(obj *Object) error { // TODO: combine small checks if err := v.checkExpiration(obj); err != nil { - return fmt.Errorf("object did not pass expiration ch: %weck", err) + return fmt.Errorf("object did not pass expiration check: %w", err) } if err := object.CheckHeaderVerificationFields(obj.SDK()); err != nil { diff --git a/pkg/services/object/put/streamer.go b/pkg/services/object/put/streamer.go index cea78b125..902999e04 100644 --- a/pkg/services/object/put/streamer.go +++ b/pkg/services/object/put/streamer.go @@ -157,9 +157,11 @@ func (p *Streamer) SendChunk(prm *PutChunkPrm) error { return errNotInit } - _, err := p.target.Write(prm.chunk) + if _, err := p.target.Write(prm.chunk); err != nil { + return fmt.Errorf("(%T) could not write payload chunk to target: %w", p, err) + } - return fmt.Errorf("(%T) could not write payload chunk to target: %w", p, err) + return nil } func (p *Streamer) Close() (*PutResponse, error) {