forked from letsencrypt/boulder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollback.go
40 lines (34 loc) · 1.05 KB
/
rollback.go
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
34
35
36
37
38
39
40
// Copyright 2016 ISRG. All rights reserved
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package sa
import (
"fmt"
gorp "gopkg.in/gorp.v1"
)
// 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 err is non-nil) and wraps
// the error, if any, of the rollback into a RollbackError.
//
// The err parameter must be non-nil.
//
// err = sa.Rollback(tx, err)
func Rollback(tx *gorp.Transaction, err error) error {
return &RollbackError{
Err: err,
RollbackErr: tx.Rollback(),
}
}