gitlab.com/beacon-software/gadget@v0.0.0-20181217202115-54565ea1ed5e/environment/errors.go (about) 1 package environment 2 3 import ( 4 "fmt" 5 "reflect" 6 7 "gitlab.com/beacon-software/gadget/errors" 8 ) 9 10 // InvalidSpecificationError indicates that a config is of the wrong type. 11 type InvalidSpecificationError struct{ trace []string } 12 13 func (err *InvalidSpecificationError) Error() string { 14 return "specification must be a struct pointer" 15 } 16 17 // Trace returns the stack trace for the error 18 func (err *InvalidSpecificationError) Trace() []string { 19 return err.trace 20 } 21 22 // NewInvalidSpecificationError instantiates a InvalidSpecificationError with a stack trace 23 func NewInvalidSpecificationError() errors.TracerError { 24 return &InvalidSpecificationError{trace: errors.GetStackTrace()} 25 } 26 27 // MissingEnvironmentVariableError indicates that a non-optional variable was not found in the environment 28 type MissingEnvironmentVariableError struct { 29 Field string 30 Tag string 31 trace []string 32 } 33 34 // NewMissingEnvironmentVariableError instantiates a MissingEnvironmentVariableError with a stack trace 35 func NewMissingEnvironmentVariableError(field string, tag string) errors.TracerError { 36 return &MissingEnvironmentVariableError{ 37 Field: field, 38 Tag: tag, 39 trace: errors.GetStackTrace(), 40 } 41 } 42 43 func (err MissingEnvironmentVariableError) Error() string { 44 return fmt.Sprintf("required environment variable %s was not set for %s", err.Tag, err.Field) 45 } 46 47 // Trace returns the stack trace for the error 48 func (err *MissingEnvironmentVariableError) Trace() []string { 49 return err.trace 50 } 51 52 // UnsupportedDataTypeError indicates that no conversion from string to the given type has been implemented 53 type UnsupportedDataTypeError struct { 54 Type reflect.Kind 55 Field string 56 trace []string 57 } 58 59 // NewUnsupportedDataTypeError instantiates a UnsupportedDataTypeError with a stack trace 60 func NewUnsupportedDataTypeError(dataType reflect.Kind, field string) errors.TracerError { 61 return &UnsupportedDataTypeError{ 62 Type: dataType, 63 Field: field, 64 trace: errors.GetStackTrace(), 65 } 66 } 67 68 func (err UnsupportedDataTypeError) Error() string { 69 return fmt.Sprintf("type %s for %s is not supported", err.Type, err.Field) 70 } 71 72 // Trace returns the stack trace for the error 73 func (err *UnsupportedDataTypeError) Trace() []string { 74 return err.trace 75 }