avoid overshadowing err in defers

This commit is contained in:
i-norden 2023-05-31 18:07:14 -05:00
parent 768357293c
commit fe88e90181
2 changed files with 6 additions and 1 deletions

View File

@ -110,6 +110,7 @@ func (p *publisher) PublishHeader(header *types.Header) (err error) {
return err return err
} }
tx := pubTx{snapTx, nil} tx := pubTx{snapTx, nil}
// we must avoid overshadowing the `err`
defer func() { defer func() {
err = snapt.CommitOrRollback(tx, err) err = snapt.CommitOrRollback(tx, err)
if err != nil { if err != nil {
@ -117,7 +118,7 @@ func (p *publisher) PublishHeader(header *types.Header) (err error) {
} }
}() }()
if err := tx.publishIPLD(headerNode.Cid(), headerNode.RawData(), header.Number); err != nil { if err = tx.publishIPLD(headerNode.Cid(), headerNode.RawData(), header.Number); err != nil {
return err return err
} }

View File

@ -200,8 +200,12 @@ func (s *Service) createSnapshot(ctx context.Context, it trie.NodeIterator, head
if err != nil { if err != nil {
return err return err
} }
// we must avoid overshadowing the `err`
defer func() { defer func() {
err = CommitOrRollback(tx, err) err = CommitOrRollback(tx, err)
if err != nil {
log.Errorf("CommitOrRollback failed: %s", err)
}
}() }()
// path (from recovery dump) to be seeked on recovery // path (from recovery dump) to be seeked on recovery