Checking errors from transactions in go
This commit is contained in:
parent
7db03e8dbd
commit
4dbbee3249
1 changed files with 10 additions and 3 deletions
|
@ -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
|
return err
|
||||||
}
|
}
|
||||||
tx.Commit()
|
if err := tx.Commit(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue