errorwrapper

package module
v0.8.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2021 License: MIT Imports: 16 Imported by: 47

README

errorwrapper Intro

Errorwrapper package

errorwrapper is wrapper that helps error handling smartly in go.

Git Clone

git clone https://gitlab.com/evatix-go/errorwrapper.git

2FA enabled, for linux

git clone https://[YourGitLabUserName]:[YourGitlabAcessTokenGenerateFromGitlabsTokens]@gitlab.com/evatix-go/errorwrapper.git

Prerequisites
  • Update git to latest 2.29
  • Update or install the latest of Go 1.15.2
  • Either add your ssh key to your gitlab account
  • Or, use your access token to clone it.

Installation

go get gitlab.com/evatix-go/errorwrapper

Go get issue for private package
  • Update git to 2.29
  • Enable go modules. (Windows : go env -w GO111MODULE=on, Unix : export GO111MODULE=on)
  • Add gitlab.com/evatix-go to go env private

To set for Windows:

go env -w GOPRIVATE=[AddExistingOnes;]gitlab.com/evatix-go

To set for Unix:

expoort GOPRIVATE=[AddExistingOnes;]gitlab.com/evatix-go

Why errorwrapper?

It is to avoid the if-else part for checking errors not nil or handle error based if exits.

Training Videos

Examples

Example 1
errtype.OutOfRangeValue.Panic("something wrong", "alim", []int{1, 2})

image

Example 2
errtype.NotSupportInWindows.PanicNoRefs("not support in windows")

image

Example 3
err2 := errnew.Messages(errtype.Conversion, "I am not ready", "Convert failed.")
fmt.Println(1, err2.IsErrorEquals(err2.Error()))
fmt.Println(2, err2.GetTypeVariantStruct().Variant.IsConversion())
fmt.Println(3, err2.GetTypeVariantStruct().Variant.Is(errtype.Conversion))
fmt.Println(4, err2.GetTypeString())
fmt.Println(5, err2.GetTypeWithCodeString())
fmt.Println(6, err2.GetTypeVariantStruct().Variant.Is(errtype.NotSupportInWindows))
fmt.Println(7, err2.FullString())
fmt.Println(8, err2.IsErrorMessage(err2.FullString(), false))
fmt.Println(9, err2.IsErrorMessage(err2.Error().Error(), false))

image

1 true
2 true
3 true
4 Conversion (Code - 69) : Conversion related error, cannot process the request.
5 (Code - #69) : Conversion
6 false
7 [Error (Conversion - #69): Conversion related error, cannot process the request.
"I am not ready, Convert failed."]
8 false
9 true

Example 4
err2 := errnew.Messages(errtype.Conversion, "I am not ready", "Convert failed.")
fmt.Println(1, err2.FullString())
err2.HandleErrorWithRefs("hello", "var", []int{1, 2})

image

1 [Error (Conversion - #69): Conversion related error, cannot process the request.
"I am not ready, Convert failed."]
panic: hello
[Error (Conversion - #69): Conversion related error, cannot process the request.
"I am not ready, Convert failed."] 
Reference { var([]int): [1 2] }
Example 5 : JSON Parsing
err := errnew.Refs(errtype.AnalysisFailed, "varName", []int{1, 20}, ",", "msg1")
collection := errwrappers.New(5)
collection.AddWrapperPtr(&err)
fmt.Println(collection.String())
jsonResult := collection.Json()

errorsCollection := errwrappers.New(1)
jsonResult.Unmarshal(&errorsCollection)

fmt.Println(errorsCollection.String())

Serializing ErrorWrapper

# Error Wrappers - Collection - Length[1]

- [Error (AnalysisFailed - #138): Analysis is failed. Please consult with appropriate personnel to get the solution.
"msg1" Reference(s) {varName([]int) : [1 20]}.]
# Error Wrappers - Collection - Length[1]

- [Error (AnalysisFailed - #138): Analysis is failed. Please consult with appropriate personnel to get the solution.
"msg1" Reference(s) {varName(string) : [1 20]}.]

Process finished with exit code 0

Acknowledgement

Any other packages used

Issues

Notes

Contributors

License

Evatix MIT License

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	StaticEmpty    = Empty()
	StaticEmptyPtr = &StaticEmpty
)

Functions

func ErrorMessageToError added in v0.8.0

func ErrorMessageToError(err error, msg string) error

ErrorMessageToError final error is nil if err is nil

func ErrorsToString added in v0.8.0

func ErrorsToString(errItems ...error) error

ErrorsToString nil items will be ignored.

func ErrorsToStringUsingJoiner added in v0.8.0

func ErrorsToStringUsingJoiner(
	joiner string,
	errItems ...error,
) string

ErrorsToStringUsingJoiner nil items will be ignored.

func MessagesJoined added in v0.7.8

func MessagesJoined(messages []string) string

func SimpleReferencesCompile added in v0.7.0

func SimpleReferencesCompile(
	errType errtype.Variation,
	references ...interface{},
) string

func SimpleReferencesCompileOptimized added in v0.7.0

func SimpleReferencesCompileOptimized(
	errType errtype.Variation,
	references ...interface{},
) string

SimpleReferencesCompileOptimized

errconsts.SimpleReferenceCompileOptimizedFormat = `%typeName (..., "reference")`

Types

type StringFmtFunc added in v0.7.9

type StringFmtFunc = func(wrapper *Wrapper) string

type Wrapper

type Wrapper struct {
	// contains filtered or unexported fields
}

func Empty added in v0.0.2

func Empty() Wrapper

func EmptyPrint added in v0.0.4

func EmptyPrint() Wrapper

func EmptyPtr added in v0.0.4

func EmptyPtr() *Wrapper

func ErrorsToWrapper added in v0.8.0

func ErrorsToWrapper(
	errType errtype.Variation,
	errItems ...error,
) *Wrapper

ErrorsToWrapper nil items will be ignored.

func New

func New(errType errtype.Variation) Wrapper

func NewErrUsingAllParams

func NewErrUsingAllParams(
	stackSkipIndex int,
	errType errtype.Variation,
	isDisplayableError bool,
	err error,
	references *refs.Collection,
) Wrapper

func NewErrUsingAllParamsPtr

func NewErrUsingAllParamsPtr(
	stackSkipIndex int,
	errType errtype.Variation,
	isDisplayableError bool,
	err error,
	references *refs.Collection,
) *Wrapper

func NewError added in v0.1.9

func NewError(
	stackSkipIndex int,
	err error,
) Wrapper

func NewErrorPlusMsgUsingAllParamsPtr added in v0.0.2

func NewErrorPlusMsgUsingAllParamsPtr(
	stackSkipIndex int,
	errType errtype.Variation,
	isDisplayableError bool,
	err error,
	message string,
	references *refs.Collection,
) *Wrapper

func NewErrorPtr added in v0.1.9

func NewErrorPtr(
	stackSkipIndex int,
	err error,
) *Wrapper

func NewErrorRef1 added in v0.6.5

func NewErrorRef1(
	stackSkipIndex int,
	errType errtype.Variation,
	err error,
	var1 string,
	val1 interface{},
) *Wrapper

NewErrorRef1 alias for NewRef

func NewFromDataModel added in v0.4.0

func NewFromDataModel(
	model *WrapperDataModel,
) *Wrapper

func NewGeneric

func NewGeneric(
	stackSkipIndex int,
	error error,
) Wrapper

func NewGenericPtr added in v0.3.9

func NewGenericPtr(
	stackSkipIndex int,
	error error,
) *Wrapper

func NewMsgDisplayErrorPtr added in v0.7.9

func NewMsgDisplayErrorPtr(
	stackSkipIndex int,
	errType errtype.Variation,
	message string,
	references *refs.Collection,
) *Wrapper

func NewMsgDisplayErrorReferencesPtr added in v0.8.3

func NewMsgDisplayErrorReferencesPtr(
	stackSkipIndex int,
	errType errtype.Variation,
	message string,
	references ...ref.Value,
) *Wrapper

func NewMsgDisplayErrorUsingStackTracesPtr added in v0.7.9

func NewMsgDisplayErrorUsingStackTracesPtr(
	errType errtype.Variation,
	message string,
	stackTraces codestack.TraceCollection,
	references ...ref.Value,
) *Wrapper

func NewMsgUsingAllParams

func NewMsgUsingAllParams(
	stackSkipIndex int,
	errType errtype.Variation,
	isDisplayableError bool,
	message string,
	references *refs.Collection,
) Wrapper

func NewMsgUsingAllParamsPtr

func NewMsgUsingAllParamsPtr(
	stackSkipIndex int,
	errType errtype.Variation,
	isDisplayableError bool,
	message string,
	references *refs.Collection,
) *Wrapper

func NewMsgUsingCodeStacksPtr added in v0.7.9

func NewMsgUsingCodeStacksPtr(
	errType errtype.Variation,
	isDisplayableError bool,
	message string,
	codeStacks codestack.TraceCollection,
	references *refs.Collection,
) *Wrapper

func NewOnlyRefs added in v0.5.2

func NewOnlyRefs(
	stackSkipIndex int,
	errType errtype.Variation,
	refValues ...ref.Value,
) *Wrapper

func NewPath added in v0.5.2

func NewPath(
	stackSkipIndex int,
	errType errtype.Variation,
	error error,
	filePath string,
) *Wrapper

func NewPathMessage added in v0.5.2

func NewPathMessage(
	stackSkipIndex int,
	errType errtype.Variation,
	filePath string,
	messages ...string,
) *Wrapper

func NewPtr added in v0.0.7

func NewPtr(errType errtype.Variation) *Wrapper

func NewPtrUsingStackSkip added in v0.7.9

func NewPtrUsingStackSkip(
	stackStartIndex int,
	errType errtype.Variation,
) *Wrapper

func NewRef added in v0.5.2

func NewRef(
	stackSkipIndex int,
	errType errtype.Variation,
	err error,
	varName string,
	val interface{},
) *Wrapper

func NewRef1 added in v0.5.4

func NewRef1(
	stackSkipIndex int,
	errType errtype.Variation,
	var1 string,
	val1 interface{},
) *Wrapper

func NewRef1Msg added in v0.7.0

func NewRef1Msg(
	stackSkipIndex int,
	errType errtype.Variation,
	msg string,
	var1 string,
	val1 interface{},
) *Wrapper

func NewRef2 added in v0.5.2

func NewRef2(
	stackSkipIndex int,
	errType errtype.Variation,
	error error,
	varName string,
	val interface{},
	varName2 string,
	val2 interface{},
) *Wrapper

func NewRef2Msg added in v0.7.0

func NewRef2Msg(
	stackSkipIndex int,
	errType errtype.Variation,
	msg string,
	var1 string,
	val1 interface{},
	var2 string,
	val2 interface{},
) *Wrapper

func NewRefWithMessage added in v0.5.2

func NewRefWithMessage(
	stackSkipIndex int,
	errType errtype.Variation,
	message string,
	refValues ...ref.Value,
) *Wrapper

func NewRefs added in v0.5.2

func NewRefs(
	stackSkipIndex int,
	errType errtype.Variation,
	error error,
	refValues ...ref.Value,
) *Wrapper

func NewUnknownUsingMessage

func NewUnknownUsingMessage(
	stackSkipIndex int,
	isDisplayableError bool,
	message string,
) Wrapper

func NewUnknownUsingMessagePtr added in v0.3.9

func NewUnknownUsingMessagePtr(
	stackSkipIndex int,
	isDisplayableError bool,
	message string,
) *Wrapper

func NewUsingError

func NewUsingError(
	stackSkipIndex int,
	errType errtype.Variation,
	err error,
) Wrapper

func NewUsingErrorAndMessage added in v0.4.7

func NewUsingErrorAndMessage(
	stackSkipIndex int,
	err error,
	msg string,
) *Wrapper

func NewUsingErrorPtr

func NewUsingErrorPtr(
	stackSkipIndex int,
	errType errtype.Variation,
	err error,
) *Wrapper

func NewUsingErrorPtrErrorInPtr added in v0.1.9

func NewUsingErrorPtrErrorInPtr(
	stackSkipIndex int,
	errType errtype.Variation,
	err *error,
) *Wrapper

func NewUsingErrorWithoutTypeDisplay

func NewUsingErrorWithoutTypeDisplay(
	errType errtype.Variation,
	err error,
) Wrapper

func NewUsingErrorWithoutTypeDisplayPtr added in v0.3.9

func NewUsingErrorWithoutTypeDisplayPtr(
	errType errtype.Variation,
	err error,
) *Wrapper

func NewUsingMessage

func NewUsingMessage(
	stackSkipIndex int,
	errType errtype.Variation,
	message string,
) Wrapper

func NewUsingMessagePtr added in v0.1.9

func NewUsingMessagePtr(
	stackSkipIndex int,
	errType errtype.Variation,
	message string,
) *Wrapper

func NewUsingSeparator

func NewUsingSeparator(
	stackSkipIndex int,
	errType errtype.Variation,
	joiner string,
	messages ...string,
) Wrapper

func NewUsingSeparatorPtr added in v0.3.9

func NewUsingSeparatorPtr(
	stackSkipIndex int,
	errType errtype.Variation,
	joiner string,
	messages ...string,
) *Wrapper

func NewUsingTypeErrorAndMessage added in v0.4.7

func NewUsingTypeErrorAndMessage(
	stackSkipIndex int,
	errType errtype.Variation,
	err error,
	msg string,
) *Wrapper

func NewUsingWrapper added in v0.5.4

func NewUsingWrapper(
	stackSkipIndex int,
	currentWrapper *Wrapper,
	additionalReferences ...ref.Value,
) *Wrapper

func TypeReferenceQuick added in v0.7.0

func TypeReferenceQuick(
	stackSkipIndex int,
	errType errtype.Variation,
	referencesValues ...interface{},
) *Wrapper

TypeReferenceQuick - errorTypeName - (...., items)...

func (*Wrapper) AsErrorWrapper added in v0.7.3

func (it *Wrapper) AsErrorWrapper() *Wrapper

func (*Wrapper) AsJsonContractsBinder added in v0.4.9

func (it *Wrapper) AsJsonContractsBinder() corejson.JsonContractsBinder

func (Wrapper) Clone added in v0.8.4

func (it Wrapper) Clone() Wrapper

func (*Wrapper) ClonePtr added in v0.1.9

func (it *Wrapper) ClonePtr() *Wrapper

func (*Wrapper) CompiledError added in v0.5.4

func (it *Wrapper) CompiledError() error

func (*Wrapper) CompiledErrorWithStackTraces added in v0.7.9

func (it *Wrapper) CompiledErrorWithStackTraces() error

func (*Wrapper) ConcatNew added in v0.4.7

func (it *Wrapper) ConcatNew(
	skipStackIndex int,
	err error,
) *Wrapper

ConcatNew It will create new errorwrapper.Wrapper and combined error with consts.DefaultErrorLineSeparator

func (*Wrapper) ConcatNewErrors added in v0.4.7

func (it *Wrapper) ConcatNewErrors(
	skipStackIndex int,
	errItems ...error,
) *Wrapper

ConcatNewErrors It will create new errorwrapper.Wrapper and combined errors with consts.DefaultErrorLineSeparator

func (*Wrapper) ConcatNewMessage added in v0.4.7

func (it *Wrapper) ConcatNewMessage(
	skipStackIndex int,
	errMsg string,
) *Wrapper

ConcatNewMessage It will create new errorwrapper.Wrapper and combined msg with consts.DefaultErrorLineSeparator

func (*Wrapper) ConcatNewMessageWithRef1 added in v0.5.4

func (it *Wrapper) ConcatNewMessageWithRef1(
	skipStackIndex int,
	errMsg string,
	var1 string, val1 interface{},
) *Wrapper

func (*Wrapper) ConcatNewMessageWithRef2 added in v0.5.4

func (it *Wrapper) ConcatNewMessageWithRef2(
	skipStackIndex int,
	errMsg string,
	var1 string, val1 interface{},
	var2 string, val2 interface{},
) *Wrapper

func (*Wrapper) ConcatNewMessageWithRefs added in v0.5.4

func (it *Wrapper) ConcatNewMessageWithRefs(
	skipStackIndex int,
	errMsg string,
	references ...ref.Value,
) *Wrapper

func (*Wrapper) ConcatNewMessageWithRefsOnly added in v0.5.4

func (it *Wrapper) ConcatNewMessageWithRefsOnly(
	references ...ref.Value,
) *Wrapper

func (*Wrapper) ConcatNewMessages added in v0.4.9

func (it *Wrapper) ConcatNewMessages(
	skipStackIndex int,
	errMessages ...string,
) *Wrapper

ConcatNewMessages It will create new errorwrapper.Wrapper and combined msg with consts.DefaultErrorLineSeparator

func (*Wrapper) ConcatNewWrapperError added in v0.4.7

func (it *Wrapper) ConcatNewWrapperError(
	skipStackIndex int,
	another *Wrapper,
) *Wrapper

ConcatNewWrapperError Warning : It will not take anything other than error message to combine with.

func (*Wrapper) ConcatWithNewStackSkip added in v0.8.6

func (it *Wrapper) ConcatWithNewStackSkip(
	skipStackIndex int,
) *Wrapper

func (*Wrapper) ConcatWithNewStackTraces added in v0.8.6

func (it *Wrapper) ConcatWithNewStackTraces(
	stackTraces ...codestack.Trace,
) *Wrapper

func (*Wrapper) Dispose added in v0.7.9

func (it *Wrapper) Dispose()

func (*Wrapper) Error

func (it *Wrapper) Error() error

func (*Wrapper) ErrorString

func (it *Wrapper) ErrorString() string

ErrorString if empty error then returns ""

func (*Wrapper) FullOrErrorMessage added in v0.7.1

func (it *Wrapper) FullOrErrorMessage(
	isErrorMessage bool,
) string

func (*Wrapper) FullString

func (it *Wrapper) FullString() string

func (*Wrapper) FullStringSplitByNewLine added in v0.7.1

func (it *Wrapper) FullStringSplitByNewLine() []string

func (*Wrapper) FullStringWithLimitTraces added in v0.7.9

func (it *Wrapper) FullStringWithLimitTraces(limit int) string

func (*Wrapper) FullStringWithTraces added in v0.7.9

func (it *Wrapper) FullStringWithTraces() string

func (*Wrapper) GetTypeVariantStruct

func (it *Wrapper) GetTypeVariantStruct() errtype.VariantStructure

func (*Wrapper) HandleError

func (it *Wrapper) HandleError()

HandleError Only call panic if has currentError

func (*Wrapper) HandleErrorWithMsg

func (it *Wrapper) HandleErrorWithMsg(newMessage string)

HandleErrorWithMsg Only call panic if has currentError

func (*Wrapper) HandleErrorWithRefs

func (it *Wrapper) HandleErrorWithRefs(
	newMessage string,
	refVar,
	refVal interface{},
)

func (*Wrapper) HasError

func (it *Wrapper) HasError() bool

func (*Wrapper) IsEmpty

func (it *Wrapper) IsEmpty() bool

func (*Wrapper) IsEmptyError added in v0.4.9

func (it *Wrapper) IsEmptyError() bool

func (*Wrapper) IsEquals

func (it *Wrapper) IsEquals(another *Wrapper) bool

func (*Wrapper) IsErrorEquals

func (it *Wrapper) IsErrorEquals(err error) bool

func (*Wrapper) IsErrorMessage

func (it *Wrapper) IsErrorMessage(msg string, isCaseSensitive bool) bool

IsErrorMessage If error IsEmpty then returns false regardless

func (*Wrapper) IsErrorMessageContains

func (it *Wrapper) IsErrorMessageContains(
	msg string,
	isCaseSensitive bool,
) bool

IsErrorMessageContains If error IsEmpty then returns false regardless

func (*Wrapper) IsErrorMessageEqual

func (it *Wrapper) IsErrorMessageEqual(msg string) bool

func (*Wrapper) IsFailed added in v0.7.0

func (it *Wrapper) IsFailed() bool

func (*Wrapper) IsReferencesEmpty added in v0.0.4

func (it *Wrapper) IsReferencesEmpty() bool

func (*Wrapper) IsSuccess added in v0.7.0

func (it *Wrapper) IsSuccess() bool

func (*Wrapper) IsTypeOf

func (it *Wrapper) IsTypeOf(errType errtype.Variation) bool

func (*Wrapper) IsValid added in v0.7.0

func (it *Wrapper) IsValid() bool

func (Wrapper) Json added in v0.4.0

func (it Wrapper) Json() corejson.Result

func (*Wrapper) JsonModel added in v0.4.0

func (it *Wrapper) JsonModel() *WrapperDataModel

func (*Wrapper) JsonModelAny added in v0.4.0

func (it *Wrapper) JsonModelAny() interface{}

func (*Wrapper) JsonParseSelfInject added in v0.4.0

func (it *Wrapper) JsonParseSelfInject(
	jsonResult *corejson.Result,
) error

func (Wrapper) JsonPtr added in v0.7.9

func (it Wrapper) JsonPtr() *corejson.Result

func (*Wrapper) Log added in v0.4.0

func (it *Wrapper) Log()

func (*Wrapper) LogFatal added in v0.4.0

func (it *Wrapper) LogFatal()

func (*Wrapper) LogFatalWithTraces added in v0.8.0

func (it *Wrapper) LogFatalWithTraces()

func (*Wrapper) LogWithTraces added in v0.8.0

func (it *Wrapper) LogWithTraces()

func (*Wrapper) MarshalJSON added in v0.4.0

func (it *Wrapper) MarshalJSON() ([]byte, error)

func (*Wrapper) ParseInjectUsingJson added in v0.4.0

func (it *Wrapper) ParseInjectUsingJson(
	jsonResult *corejson.Result,
) (*Wrapper, error)

func (*Wrapper) ParseInjectUsingJsonMust added in v0.4.0

func (it *Wrapper) ParseInjectUsingJsonMust(
	jsonResult *corejson.Result,
) *Wrapper

ParseInjectUsingJsonMust Panic if error

func (*Wrapper) RawErrorTypeName added in v0.8.3

func (it *Wrapper) RawErrorTypeName() string

func (*Wrapper) References added in v0.6.3

func (it *Wrapper) References() *refs.Collection

func (*Wrapper) StackTraceString added in v0.7.9

func (it *Wrapper) StackTraceString() string

func (*Wrapper) StackTracesLimit added in v0.7.9

func (it *Wrapper) StackTracesLimit(limit int) *codestack.TraceCollection

func (*Wrapper) String

func (it *Wrapper) String() string

func (*Wrapper) Type

func (it *Wrapper) Type() errtype.Variation

func (*Wrapper) TypeCodeNameString added in v0.8.3

func (it *Wrapper) TypeCodeNameString() string

TypeCodeNameString

Format : errconsts.ErrorCodeWithTypeNameFormat

"(Code - #%d) : %s"

func (*Wrapper) TypeName added in v0.8.3

func (it *Wrapper) TypeName() string

func (*Wrapper) TypeNameCode added in v0.8.3

func (it *Wrapper) TypeNameCode() string

TypeNameCode

"(#%d - %s)"

func (*Wrapper) TypeNameWithCustomMessage added in v0.8.3

func (it *Wrapper) TypeNameWithCustomMessage(customMessage string) string

TypeNameWithCustomMessage

errconsts.ErrorCodeHyphenTypeNameWithLineFormat = "(#%d - %s) %s"

func (*Wrapper) TypeString

func (it *Wrapper) TypeString() string

TypeString

Format : errconsts.VariantStructStringFormat

"%s (Code - %d) : %s" : "TypeName (Code - ValueInt) : Message from type string"

func (*Wrapper) UnmarshalJSON added in v0.4.0

func (it *Wrapper) UnmarshalJSON(data []byte) error

func (*Wrapper) ValidationErrUsingTextValidator added in v0.7.1

func (it *Wrapper) ValidationErrUsingTextValidator(
	validator *corevalidator.TextValidator,
	params *corevalidator.ValidatorParamsBase,
) *Wrapper

func (*Wrapper) Value

func (it *Wrapper) Value() error

type WrapperDataModel added in v0.4.0

type WrapperDataModel struct {
	IsDisplayableError bool
	CurrentError       string
	ErrorType          errtype.Variation
	StackTraces        codestack.TraceCollection
	References         *refs.Collection
	HasError           bool
}

func NewDataModel added in v0.4.0

func NewDataModel(wrapper *Wrapper) *WrapperDataModel

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL