errorwrapper

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2021 License: MIT Imports: 12 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 CombineErrorAndMessageToError added in v0.4.7

func CombineErrorAndMessageToError(err error, msg string) error

final error is nil if err is nil

func CombineErrorsToSingle added in v0.4.7

func CombineErrorsToSingle(errItems ...error) error

nil items will be ignored.

func CombineErrorsToSingleString added in v0.4.7

func CombineErrorsToSingleString(
	separator string,
	errItems ...error,
) string

nil items will be ignored.

Types

type Wrapper

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

func CombineErrorsToSingleWrapper added in v0.4.7

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

nil items will be ignored.

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 New

func New(errType errtype.Variation) Wrapper

func NewDirectory

func NewDirectory(error error) Wrapper

func NewDirectoryPath

func NewDirectoryPath(msg, path string) Wrapper

func NewDirectoryPathPtr added in v0.3.9

func NewDirectoryPathPtr(msg, path string) *Wrapper

func NewDirectoryPtr added in v0.3.9

func NewDirectoryPtr(error error) *Wrapper

func NewEmptyPathPtr added in v0.3.9

func NewEmptyPathPtr() *Wrapper

func NewErrUsingAllParams

func NewErrUsingAllParams(
	errType errtype.Variation,
	isPrintErrorType bool,
	err error,
	refs *refs.Collection,
) Wrapper

func NewErrUsingAllParamsPtr

func NewErrUsingAllParamsPtr(
	errType errtype.Variation,
	isPrintErrorType bool,
	err error,
	refs *refs.Collection,
) *Wrapper

func NewError added in v0.1.9

func NewError(
	err error,
) Wrapper

func NewErrorPlusMsgUsingAllParamsPtr added in v0.0.2

func NewErrorPlusMsgUsingAllParamsPtr(
	errType errtype.Variation,
	isPrintErrorType bool,
	err error,
	message string,
	refs *refs.Collection,
) *Wrapper

func NewErrorPtr added in v0.1.9

func NewErrorPtr(
	err error,
) *Wrapper

func NewFile

func NewFile(error error) Wrapper

func NewFilePath

func NewFilePath(msg, path string) Wrapper

func NewFilePathPtr added in v0.3.9

func NewFilePathPtr(msg, path string) *Wrapper

func NewFilePtr added in v0.3.9

func NewFilePtr(error error) *Wrapper

func NewFromDataModel added in v0.4.0

func NewFromDataModel(
	model *WrapperDataModel,
) *Wrapper

func NewGeneric

func NewGeneric(error error) Wrapper

func NewGenericPtr added in v0.3.9

func NewGenericPtr(error error) *Wrapper

func NewMsgUsingAllParams

func NewMsgUsingAllParams(
	errType errtype.Variation,
	isPrintErrorType bool,
	message string,
	refs *refs.Collection,
) Wrapper

func NewMsgUsingAllParamsPtr

func NewMsgUsingAllParamsPtr(
	errType errtype.Variation,
	isPrintErrorType bool,
	message string,
	refs *refs.Collection,
) *Wrapper

func NewPtr added in v0.0.7

func NewPtr(errType errtype.Variation) *Wrapper

func NewUnknownUsingMessage

func NewUnknownUsingMessage(
	msg string,
	isPrintErrorType bool,
) Wrapper

func NewUnknownUsingMessagePtr added in v0.3.9

func NewUnknownUsingMessagePtr(
	msg string,
	isPrintErrorType bool,
) *Wrapper

func NewUsingError

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

func NewUsingErrorAndMessage added in v0.4.7

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

func NewUsingErrorPtr

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

func NewUsingErrorPtrErrorInPtr added in v0.1.9

func NewUsingErrorPtrErrorInPtr(
	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(
	errType errtype.Variation,
	message string,
) Wrapper

func NewUsingMessagePtr added in v0.1.9

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

func NewUsingSeparator

func NewUsingSeparator(
	errType errtype.Variation,
	separator string,
	messages ...string,
) Wrapper

func NewUsingSeparatorPtr added in v0.3.9

func NewUsingSeparatorPtr(
	errType errtype.Variation,
	separator string,
	messages ...string,
) *Wrapper

func NewUsingTypeErrorAndMessage added in v0.4.7

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

func (*Wrapper) AsJsonContractsBinder added in v0.4.9

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

func (*Wrapper) ClonePtr added in v0.1.9

func (errorWrapper *Wrapper) ClonePtr() *Wrapper

func (*Wrapper) ConcatNew added in v0.4.7

func (errorWrapper *Wrapper) ConcatNew(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 (errorWrapper *Wrapper) ConcatNewErrors(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 (errorWrapper *Wrapper) ConcatNewMessage(errMsg string) *Wrapper

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

func (*Wrapper) ConcatNewMessages added in v0.4.9

func (errorWrapper *Wrapper) ConcatNewMessages(funcName string, 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 (errorWrapper *Wrapper) ConcatNewWrapperError(another *Wrapper) *Wrapper

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

func (*Wrapper) Error

func (errorWrapper *Wrapper) Error() error

func (*Wrapper) ErrorString

func (errorWrapper *Wrapper) ErrorString() string

ErrorString if empty error then returns ""

func (*Wrapper) FullString

func (errorWrapper *Wrapper) FullString() string

func (*Wrapper) FullStringPtr

func (errorWrapper *Wrapper) FullStringPtr() *string

func (*Wrapper) GetTypeString

func (errorWrapper *Wrapper) GetTypeString() string

func (*Wrapper) GetTypeVariantStruct

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

func (*Wrapper) GetTypeWithCodeString

func (errorWrapper *Wrapper) GetTypeWithCodeString() string

func (*Wrapper) GetTypeWithCodeStringPtr

func (errorWrapper *Wrapper) GetTypeWithCodeStringPtr() *string

func (*Wrapper) HandleError

func (errorWrapper *Wrapper) HandleError()

HandleError Only call panic if has currentError

func (*Wrapper) HandleErrorWithMsg

func (errorWrapper *Wrapper) HandleErrorWithMsg(newMessage string)

HandleErrorWithMsg Only call panic if has currentError

func (*Wrapper) HandleErrorWithRefs

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

func (*Wrapper) HasError

func (errorWrapper *Wrapper) HasError() bool

func (*Wrapper) IsEmpty

func (errorWrapper *Wrapper) IsEmpty() bool

func (*Wrapper) IsEmptyError added in v0.4.9

func (errorWrapper *Wrapper) IsEmptyError() bool

func (*Wrapper) IsEquals

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

func (*Wrapper) IsErrorEquals

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

func (*Wrapper) IsErrorMessage

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

IsErrorMessage If error IsEmpty then returns false regardless

func (*Wrapper) IsErrorMessageContains

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

IsErrorMessageContains If error IsEmpty then returns false regardless

func (*Wrapper) IsErrorMessageEqual

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

func (*Wrapper) IsReferencesEmpty added in v0.0.4

func (errorWrapper *Wrapper) IsReferencesEmpty() bool

func (*Wrapper) IsTypeOf

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

func (*Wrapper) Json added in v0.4.0

func (errorWrapper *Wrapper) Json() *corejson.Result

func (*Wrapper) JsonModel added in v0.4.0

func (errorWrapper *Wrapper) JsonModel() *WrapperDataModel

func (*Wrapper) JsonModelAny added in v0.4.0

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

func (*Wrapper) JsonParseSelfInject added in v0.4.0

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

func (*Wrapper) Log added in v0.4.0

func (errorWrapper *Wrapper) Log()

func (*Wrapper) LogFatal added in v0.4.0

func (errorWrapper *Wrapper) LogFatal()

func (*Wrapper) MarshalJSON added in v0.4.0

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

func (*Wrapper) ParseInjectUsingJson added in v0.4.0

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

func (*Wrapper) ParseInjectUsingJsonMust added in v0.4.0

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

Panic if error

func (*Wrapper) String

func (errorWrapper *Wrapper) String() string

func (*Wrapper) StringPtr

func (errorWrapper *Wrapper) StringPtr() *string

func (*Wrapper) Type

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

func (*Wrapper) TypeString

func (errorWrapper *Wrapper) TypeString() *string

func (*Wrapper) UnmarshalJSON added in v0.4.0

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

func (*Wrapper) Value

func (errorWrapper *Wrapper) Value() error

type WrapperDataModel added in v0.4.0

type WrapperDataModel struct {
	IsPrintErrorType bool
	CurrentError     string
	References       *refs.Collection
	ErrorType        errtype.Variation
	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