github.com/opentofu/opentofu@v1.7.1/internal/encryption/keyprovider/errors.go (about)

     1  package keyprovider
     2  
     3  import "fmt"
     4  
     5  // ErrKeyProviderFailure indicates a generic key provider failure.
     6  type ErrKeyProviderFailure struct {
     7  	Message string
     8  	Cause   error
     9  }
    10  
    11  func (e ErrKeyProviderFailure) Error() string {
    12  	if e.Cause != nil {
    13  		return fmt.Sprintf("%s: %v", e.Message, e.Cause)
    14  	}
    15  	return e.Message
    16  }
    17  
    18  func (e ErrKeyProviderFailure) Unwrap() error {
    19  	return e.Cause
    20  }
    21  
    22  // ErrInvalidConfiguration indicates that the key provider configuration is incorrect.
    23  type ErrInvalidConfiguration struct {
    24  	Message string
    25  	Cause   error
    26  }
    27  
    28  func (e ErrInvalidConfiguration) Error() string {
    29  	if e.Cause != nil {
    30  
    31  		if e.Message != "" {
    32  			return fmt.Sprintf("%s: %v", e.Message, e.Cause)
    33  		}
    34  		return fmt.Sprintf("invalid key provider configuration: %v", e.Cause)
    35  	}
    36  	if e.Message != "" {
    37  		return e.Message
    38  	}
    39  	return "invalid provider configuration"
    40  }
    41  
    42  func (e ErrInvalidConfiguration) Unwrap() error {
    43  	return e.Cause
    44  }
    45  
    46  // ErrInvalidMetadata indicates that the key provider has received an incorrect metadata and cannot decrypt.
    47  type ErrInvalidMetadata struct {
    48  	Message string
    49  	Cause   error
    50  }
    51  
    52  func (e ErrInvalidMetadata) Error() string {
    53  	if e.Cause != nil {
    54  		if e.Message != "" {
    55  			return fmt.Sprintf("%s: %v", e.Message, e.Cause)
    56  		}
    57  		return fmt.Sprintf("invalid key provider metadata: %v", e.Cause)
    58  	}
    59  	if e.Message != "" {
    60  		return e.Message
    61  	}
    62  	return "invalid provider metadata"
    63  }
    64  
    65  func (e ErrInvalidMetadata) Unwrap() error {
    66  	return e.Cause
    67  }