Checking errors from transactions in go

This commit is contained in:
Imbus 2024-03-19 02:14:09 +01:00
parent 7db03e8dbd
commit 4dbbee3249

View file

@ -204,15 +204,22 @@ func (d *Db) AddProject(name string, description string, username string) error
tx := d.MustBegin() tx := d.MustBegin()
_, err := tx.Exec(projectInsert, name, description, username) _, err := tx.Exec(projectInsert, name, description, username)
if err != nil { if err != nil {
tx.Rollback() if err := tx.Rollback(); err != nil {
return err
}
return err return err
} }
_, err = tx.Exec(changeUserRole, "project_manager", username, name) _, err = tx.Exec(changeUserRole, "project_manager", username, name)
if err != nil { if err != nil {
tx.Rollback() if err := tx.Rollback(); err != nil {
return err return err
} }
tx.Commit() return err
}
if err := tx.Commit(); err != nil {
return err
}
return err return err
} }