Skip to content

Commit

Permalink
c14h: return error when starting a transaction
Browse files Browse the repository at this point in the history
I believe we are currently being bitten by #8 quite regularly. This is
exacerbated by not checking for an error by tx.Begin() (that's on me, I
presume), so we panic on a nil-pointer, instead of getting an error
message. Unfortunately, I still can't see a super clear-cut way to check
whether an error is caused by this issue and it shouldn't even *be* an
issue, as *sql.DB is a connection pool - so it should just handle this
transparently, IMO. But at least if we know the error message, we might
get a hint on how to handle that correctly.
  • Loading branch information
Merovius committed Feb 20, 2020
1 parent a3a04ae commit 2a31759
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions c14h/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ func OpenDB() (err error) {

func (v *Vortrag) Put() (err error) {
log.Println("Put", v)
tx, _ := db.Begin()

tx, err := db.Begin()
if err != nil {
return err
}
defer tx.Rollback()

var stmt *sql.Stmt
Expand Down

0 comments on commit 2a31759

Please sign in to comment.