From a4db43e0969125db899dae465daf3ab1385c8ce9 Mon Sep 17 00:00:00 2001 From: oliverpool <3864879+oliverpool@users.noreply.github.com> Date: Tue, 25 Aug 2020 14:11:52 +0200 Subject: Don't overwrite global err before return (#1293) Signed-off-by: Olivier Charvin --- syncapi/consumers/keychange.go | 5 ++--- syncapi/storage/shared/syncserver.go | 18 ++++-------------- 2 files changed, 6 insertions(+), 17 deletions(-) (limited to 'syncapi') diff --git a/syncapi/consumers/keychange.go b/syncapi/consumers/keychange.go index e14d2223..ee95e09d 100644 --- a/syncapi/consumers/keychange.go +++ b/syncapi/consumers/keychange.go @@ -95,9 +95,8 @@ func (s *OutputKeyChangeEventConsumer) updateOffset(msg *sarama.ConsumerMessage) } func (s *OutputKeyChangeEventConsumer) onMessage(msg *sarama.ConsumerMessage) error { - defer func() { - s.updateOffset(msg) - }() + defer s.updateOffset(msg) + var output api.DeviceMessage if err := json.Unmarshal(msg.Value, &output); err != nil { // If the message was invalid, log it and move on to the next message in the stream diff --git a/syncapi/storage/shared/syncserver.go b/syncapi/storage/shared/syncserver.go index 699a6647..4031dc74 100644 --- a/syncapi/storage/shared/syncserver.go +++ b/syncapi/storage/shared/syncserver.go @@ -455,13 +455,8 @@ func (d *Database) addPDUDeltaToResponse( if err != nil { return nil, err } - var succeeded bool - defer func() { - txerr := sqlutil.EndTransaction(txn, &succeeded) - if err == nil && txerr != nil { - err = txerr - } - }() + succeeded := false + defer sqlutil.EndTransactionWithCheck(txn, &succeeded, &err) stateFilter := gomatrixserverlib.DefaultStateFilter() // TODO: use filter provided in request @@ -641,13 +636,8 @@ func (d *Database) getResponseWithPDUsForCompleteSync( if err != nil { return } - var succeeded bool - defer func() { - txerr := sqlutil.EndTransaction(txn, &succeeded) - if err == nil && txerr != nil { - err = txerr - } - }() + succeeded := false + defer sqlutil.EndTransactionWithCheck(txn, &succeeded, &err) // Get the current sync position which we will base the sync response on. toPos, err = d.syncPositionTx(ctx, txn) -- cgit v1.2.3