From 9207833a716296ba9a25f1d19943a32e290dd50a Mon Sep 17 00:00:00 2001 From: Markus Pesch Date: Fri, 9 Apr 2021 16:55:35 +0200 Subject: [PATCH] fix: add missing error handling --- pkg/repository/postgres.go | 4 ++++ pkg/repository/sqlite.go | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/pkg/repository/postgres.go b/pkg/repository/postgres.go index b6f59c6..607f737 100644 --- a/pkg/repository/postgres.go +++ b/pkg/repository/postgres.go @@ -891,6 +891,10 @@ func (d *Postgres) Import(ctx context.Context, src Repository) error { } sensors, err := src.GetSensors(ctx) + if err != nil { + return err + } + err = d.insertOrUpdateSensors(tx, sensors...) if err != nil { return err diff --git a/pkg/repository/sqlite.go b/pkg/repository/sqlite.go index 7d87327..75f6dc0 100644 --- a/pkg/repository/sqlite.go +++ b/pkg/repository/sqlite.go @@ -921,6 +921,9 @@ func (d *SQLite) GetTemperatures(ctx context.Context) ([]*types.MeasuredValue, e // Import imports devices, sensors and all measured values from a source // repository. Existing entries will be updated. func (d *SQLite) Import(ctx context.Context, src Repository) error { + d.mutex.Lock() + defer d.mutex.Unlock() + tx, err := d.dbo.BeginTx(ctx, &sql.TxOptions{ReadOnly: false}) if err != nil { return err @@ -938,6 +941,10 @@ func (d *SQLite) Import(ctx context.Context, src Repository) error { } sensors, err := src.GetSensors(ctx) + if err != nil { + return err + } + err = d.insertOrUpdateSensors(tx, sensors...) if err != nil { return err