github.com/wata727/tflint@v0.12.2-0.20191013070026-96dd0d36f385/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 int = 0
     8  	// UnknownValueError is an error when an unknown value is referenced
     9  	UnknownValueError int = 1 + iota
    10  	// NullValueError is an error when null value is referenced
    11  	NullValueError
    12  	// TypeConversionError is an error when type conversion of cty.Value failed
    13  	TypeConversionError
    14  	// TypeMismatchError is an error when a type of cty.Value is not as expected
    15  	TypeMismatchError
    16  	// UnevaluableError is an error when a received expression has unevaluable references.
    17  	UnevaluableError
    18  	// UnexpectedAttributeError is an error when handle unexpected attributes (e.g. block)
    19  	UnexpectedAttributeError
    20  	// ExternalAPIError is an error when calling the external API (e.g. AWS SDK)
    21  	ExternalAPIError
    22  	// ContextError is pseudo error code for propagating runtime context.
    23  	ContextError
    24  
    25  	// FatalLevel is a recorverable error, it cause panic
    26  	FatalLevel int = 0
    27  	// ErrorLevel is a user-level error, it display and feedback error information
    28  	ErrorLevel int = 1 + iota
    29  	// WarningLevel is a user-level warning. Although it is an error, it has no effect on execution.
    30  	WarningLevel
    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    int
    37  	Level   int
    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  }