Merge pull request #77 from cerc-io/ian/v5_dev

fix: err overshadowing in defers
This commit is contained in:
Ian Norden 2023-06-01 08:23:02 -05:00 committed by GitHub
commit da02e5ac12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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
}
tx := pubTx{snapTx, nil}
// we must avoid overshadowing the `err`
defer func() {
err = snapt.CommitOrRollback(tx, err)
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
}

View File

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