diff options
author | xengineering <me@xengineering.eu> | 2024-10-24 17:01:24 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2024-10-24 17:01:24 +0200 |
commit | dc37aaceea903fcc84144c7566a14b3c5378dcaf (patch) | |
tree | fbfb5c504c4cd1dd2389e3b66bdbca230bedbf86 | |
parent | e66691083a2455c29b50a2970c0aba1d6afca753 (diff) | |
download | ceres-dc37aaceea903fcc84144c7566a14b3c5378dcaf.tar ceres-dc37aaceea903fcc84144c7566a14b3c5378dcaf.tar.zst ceres-dc37aaceea903fcc84144c7566a14b3c5378dcaf.zip |
Rework error handling of model.DB.Transaction()
The functions in the sub-packages model, view and controller should not
log too much. Instead they should return errors which can be extended by
fmt.Errorf("<some mesage>: %w", err).
-rw-r--r-- | model/db.go | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/model/db.go b/model/db.go index f3fb607..3746f71 100644 --- a/model/db.go +++ b/model/db.go @@ -28,8 +28,7 @@ func OpenDB(path string) (*DB, error) { func (db *DB) Transaction(f func(*sql.Tx) error) error { tx, err := (*sql.DB)(db).Begin() if err != nil { - log.Printf("Failed to start database transaction: %v", err) - return err + return fmt.Errorf("Failed to start database transaction: %w", err) } defer func() { if tx.Rollback() == nil { @@ -39,8 +38,7 @@ func (db *DB) Transaction(f func(*sql.Tx) error) error { err = f(tx) if err != nil { - log.Printf("Failed transaction: %v", err) - return err + return fmt.Errorf("Failed transaction: %w", err) } return tx.Commit() |