github.com/jpreese/tflint@v0.19.2-0.20200908152133-b01686250fb6/tflint/errors.go (about)

     1  package tflint
     2  
     3  import "fmt"
     4  
     5  const (
     6  	// EvaluationError is an error when interpolation failed (unexpected)
     7  	EvaluationError string = "E:Evaluation"
     8  	// UnknownValueError is an error when an unknown value is referenced
     9  	UnknownValueError string = "W:UnknownValue"
    10  	// NullValueError is an error when null value is referenced
    11  	NullValueError string = "W:NullValue"
    12  	// TypeConversionError is an error when type conversion of cty.Value failed
    13  	TypeConversionError string = "E:TypeConversion"
    14  	// TypeMismatchError is an error when a type of cty.Value is not as expected
    15  	TypeMismatchError string = "E:TypeMismatch"
    16  	// UnevaluableError is an error when a received expression has unevaluable references.
    17  	UnevaluableError string = "W:Unevaluable"
    18  	// UnexpectedAttributeError is an error when handle unexpected attributes (e.g. block)
    19  	UnexpectedAttributeError string = "E:UnexpectedAttribute"
    20  	// ExternalAPIError is an error when calling the external API (e.g. AWS SDK)
    21  	ExternalAPIError string = "E:ExternalAPI"
    22  	// ContextError is pseudo error code for propagating runtime context.
    23  	ContextError string = "I:Context"
    24  
    25  	// FatalLevel is a recorverable error, it cause panic
    26  	FatalLevel string = "Fatal"
    27  	// ErrorLevel is a user-level error, it display and feedback error information
    28  	ErrorLevel string = "Error"
    29  	// WarningLevel is a user-level warning. Although it is an error, it has no effect on execution.
    30  	WarningLevel string = "Warning"
    31  )
    32  
    33  // Error is application error object. It has own error code
    34  // for processing according to a type of error.
    35  type Error struct {
    36  	Code    string
    37  	Level   string
    38  	Message string
    39  	Cause   error
    40  }
    41  
    42  // Error shows error message. This must be implemented for error interface.
    43  func (e *Error) Error() string {
    44  	if e.Message != "" && e.Cause != nil {
    45  		return fmt.Sprintf("%s; %s", e.Message, e.Cause)
    46  	}
    47  
    48  	if e.Message == "" && e.Cause != nil {
    49  		return e.Cause.Error()
    50  	}
    51  
    52  	return e.Message
    53  }
    54  
    55  // NewContextError makes a new context error
    56  func NewContextError(msg string, cause error) *Error {
    57  	return &Error{
    58  		Code:    ContextError,
    59  		Level:   ErrorLevel,
    60  		Message: msg,
    61  		Cause:   cause,
    62  	}
    63  }