Skip to content

Commit 8b7a013

Browse files
author
Ibrahim Jarif
authored
Handler error in writeBatch.Flush (hypermodeinc#1421)
The writeBatch.Flush was skipping the error returned by wb.Commit() call. We shouldn't ignore the error.
1 parent 82dec91 commit 8b7a013

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

batch.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ func (wb *WriteBatch) commit() error {
181181
return wb.err
182182
}
183183
if err := wb.throttle.Do(); err != nil {
184-
return err
184+
wb.err = err
185+
return wb.err
185186
}
186187
wb.txn.CommitWith(wb.callback)
187188
wb.txn = wb.db.newTransaction(true, wb.isManaged)
@@ -193,11 +194,15 @@ func (wb *WriteBatch) commit() error {
193194
// returns any error stored by WriteBatch.
194195
func (wb *WriteBatch) Flush() error {
195196
wb.Lock()
197+
// commit will set the wb.err so no need to check the error here.
196198
_ = wb.commit()
197199
wb.txn.Discard()
198200
wb.Unlock()
199201

200202
if err := wb.throttle.Finish(); err != nil {
203+
if wb.err != nil {
204+
return errors.Errorf("wb.err: %s err: %s", wb.err, err)
205+
}
201206
return err
202207
}
203208

0 commit comments

Comments
 (0)