...

Source file src/github.com/letsencrypt/boulder/db/rollback.go

Documentation: github.com/letsencrypt/boulder/db

     1  package db
     2  
     3  import (
     4  	"fmt"
     5  )
     6  
     7  // RollbackError is a combination of a database error and the error, if any,
     8  // encountered while trying to rollback the transaction.
     9  type RollbackError struct {
    10  	Err         error
    11  	RollbackErr error
    12  }
    13  
    14  // Error implements the error interface
    15  func (re *RollbackError) Error() string {
    16  	if re.RollbackErr == nil {
    17  		return re.Err.Error()
    18  	}
    19  	return fmt.Sprintf("%s (also, while rolling back: %s)", re.Err, re.RollbackErr)
    20  }
    21  
    22  // rollback rolls back the provided transaction. If the rollback fails for any
    23  // reason a `RollbackError` error is returned wrapping the original error. If no
    24  // rollback error occurs then the original error is returned.
    25  func rollback(tx Transaction, err error) error {
    26  	if txErr := tx.Rollback(); txErr != nil {
    27  		return &RollbackError{
    28  			Err:         err,
    29  			RollbackErr: txErr,
    30  		}
    31  	}
    32  	return err
    33  }
    34  

View as plain text