errorwrapper

package module
v0.3.8 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2021 License: MIT Imports: 7 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] }

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

This section is empty.

Types

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 New

func New(errType errtype.Variation) Wrapper

func NewDirectory

func NewDirectory(error error) Wrapper

func NewDirectoryPath

func NewDirectoryPath(msg, path string) 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(
	error 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(
	error error,
) *Wrapper

func NewFile

func NewFile(error error) Wrapper

func NewFilePath

func NewFilePath(msg, path string) Wrapper

func NewGeneric

func NewGeneric(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 NewUsingError

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

func NewUsingErrorPtr

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

func NewUsingErrorPtrErrorInPtr added in v0.1.9

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

func NewUsingErrorWithoutTypeDisplay

func NewUsingErrorWithoutTypeDisplay(
	errType errtype.Variation,
	error 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 (*Wrapper) ClonePtr added in v0.1.9

func (errorWrapper *Wrapper) ClonePtr() *Wrapper

func (*Wrapper) Error

func (errorWrapper *Wrapper) Error() error

func (*Wrapper) ErrorPtr

func (errorWrapper *Wrapper) ErrorPtr() *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()

Only call panic if has currentError

func (*Wrapper) HandleErrorWithMsg

func (errorWrapper *Wrapper) HandleErrorWithMsg(newMessage string)

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) 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

If error IsEmpty then returns false regardless

func (*Wrapper) IsErrorMessageContains

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

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) 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) Value

func (errorWrapper *Wrapper) Value() *error

Jump to

Keyboard shortcuts

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