github.com/datachainlab/burrow@v0.25.0/execution/errors/vm.go (about)

     1  package errors
     2  
     3  import (
     4  	"bytes"
     5  	"fmt"
     6  
     7  	"github.com/hyperledger/burrow/crypto"
     8  	"github.com/hyperledger/burrow/permission"
     9  )
    10  
    11  type PermissionDenied struct {
    12  	Address crypto.Address
    13  	Perm    permission.PermFlag
    14  }
    15  
    16  func (err PermissionDenied) ErrorCode() Code {
    17  	return ErrorCodePermissionDenied
    18  }
    19  
    20  func (err PermissionDenied) Error() string {
    21  	return fmt.Sprintf("Account/contract %v does not have permission %v", err.Address, err.Perm)
    22  }
    23  
    24  type NestedCallError struct {
    25  	CodedError
    26  	Caller     crypto.Address
    27  	Callee     crypto.Address
    28  	StackDepth uint64
    29  }
    30  
    31  func (err NestedCallError) Error() string {
    32  	return fmt.Sprintf("error in nested call at depth %v: %s (callee) -> %s (caller): %v",
    33  		err.StackDepth, err.Callee, err.Caller, err.CodedError)
    34  }
    35  
    36  type CallError struct {
    37  	// The error from the original call which defines the overall error code
    38  	CodedError
    39  	// Errors from nested sub-calls of the original call that may have also occurred
    40  	NestedErrors []NestedCallError
    41  }
    42  
    43  func (err CallError) Error() string {
    44  	buf := new(bytes.Buffer)
    45  	buf.WriteString("Call error: ")
    46  	buf.WriteString(err.CodedError.String())
    47  	if len(err.NestedErrors) > 0 {
    48  		buf.WriteString(", nested call errors:\n")
    49  		for _, nestedErr := range err.NestedErrors {
    50  			buf.WriteString(nestedErr.Error())
    51  			buf.WriteByte('\n')
    52  		}
    53  	}
    54  	return buf.String()
    55  }