From 4dbbee324922e86a9a96d6ac05df7d3969bf3525 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Tue, 19 Mar 2024 02:14:09 +0100 Subject: [PATCH] Checking errors from transactions in go --- backend/internal/database/db.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/backend/internal/database/db.go b/backend/internal/database/db.go index ad408a7..bc6e1e8 100644 --- a/backend/internal/database/db.go +++ b/backend/internal/database/db.go @@ -204,15 +204,22 @@ func (d *Db) AddProject(name string, description string, username string) error tx := d.MustBegin() _, err := tx.Exec(projectInsert, name, description, username) if err != nil { - tx.Rollback() + if err := tx.Rollback(); err != nil { + return err + } return err } _, err = tx.Exec(changeUserRole, "project_manager", username, name) if err != nil { - tx.Rollback() + if err := tx.Rollback(); err != nil { + return err + } return err } - tx.Commit() + if err := tx.Commit(); err != nil { + return err + } + return err }