forked from adamlaska/boulder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrollback.go
More file actions
33 lines (29 loc) · 859 Bytes
/
rollback.go
File metadata and controls
33 lines (29 loc) · 859 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package db
import (
"fmt"
)
// RollbackError is a combination of a database error and the error, if any,
// encountered while trying to rollback the transaction.
type RollbackError struct {
Err error
RollbackErr error
}
// Error implements the error interface
func (re *RollbackError) Error() string {
if re.RollbackErr == nil {
return re.Err.Error()
}
return fmt.Sprintf("%s (also, while rolling back: %s)", re.Err, re.RollbackErr)
}
// rollback rolls back the provided transaction. If the rollback fails for any
// reason a `RollbackError` error is returned wrapping the original error. If no
// rollback error occurs then the original error is returned.
func rollback(tx Transaction, err error) error {
if txErr := tx.Rollback(); txErr != nil {
return &RollbackError{
Err: err,
RollbackErr: txErr,
}
}
return err
}