Skip to content

Commit

Permalink
added error utlity
Browse files Browse the repository at this point in the history
Signed-off-by: kumarabd <[email protected]>
  • Loading branch information
kumarabd committed Jun 23, 2021
1 parent 32c4b29 commit b9d09d2
Show file tree
Hide file tree
Showing 10 changed files with 1,094 additions and 31 deletions.
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
check:
check: error
golangci-lint run

check-clean-cache:
Expand All @@ -8,4 +8,7 @@ protoc-setup:
wget -P meshes https://raw.githubusercontent.com/layer5io/meshery/master/meshes/meshops.proto

proto:
protoc -I meshes/ meshes/meshops.proto --go_out=plugins=grpc:./meshes/
protoc -I meshes/ meshes/meshops.proto --go_out=plugins=grpc:./meshes/

error:
go run github.com/layer5io/meshkit/cmd/errorutil -d . update
44 changes: 24 additions & 20 deletions adapter/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,88 +38,92 @@ const (
ErrOpenOAMRefFileCode = "1014"
ErrJSONMarshalCode = "1015"
ErrOAMRetryCode = "1016"
ErrSmiInitCode = "1007"
ErrInstallSmiCode = "1008"
ErrConnectSmiCode = "1009"
ErrDeleteSmiCode = "1010"
)

var (
ErrGetName = errors.NewDefault(ErrGetNameCode, "Unable to get mesh name")
ErrOpInvalid = errors.NewDefault(ErrOpInvalidCode, "Invalid operation")
ErrNoResponse = errors.NewDefault(ErrNoResponseCode, "No response from the smi tool")
ErrGetName = errors.New(ErrGetNameCode, errors.Alert, []string{"Unable to get mesh name"}, []string{}, []string{}, []string{})
ErrOpInvalid = errors.New(ErrOpInvalidCode, errors.Alert, []string{"Invalid operation"}, []string{}, []string{}, []string{})
ErrNoResponse = errors.New(ErrNoResponseCode, errors.Alert, []string{"No response from the smi tool"}, []string{}, []string{}, []string{})

// ErrAuthInfosInvalidMsg is the error message when the all of auth infos have invalid or inaccessible paths
// as there certificate paths
ErrAuthInfosInvalidMsg = fmt.Errorf("none of the auth infos are valid either the certificate path is invalid or is inaccessible")
)

func ErrCreateInstance(err error) error {
return errors.NewDefault(ErrCreateInstanceCode, "Error creating adapter instance", err.Error())
return errors.New(ErrCreateInstanceCode, errors.Alert, []string{"Error creating adapter instance"}, []string{err.Error()}, []string{}, []string{})
}

func ErrMeshConfig(err error) error {
return errors.NewDefault(ErrMeshConfigCode, "Error configuration mesh", err.Error())
return errors.New(ErrMeshConfigCode, errors.Alert, []string{"Error configuration mesh"}, []string{err.Error()}, []string{}, []string{})
}

func ErrValidateKubeconfig(err error) error {
return errors.NewDefault(ErrValidateKubeconfigCode, "Error validating kubeconfig", err.Error())
return errors.New(ErrValidateKubeconfigCode, errors.Alert, []string{"Error validating kubeconfig"}, []string{err.Error()}, []string{}, []string{})
}

func ErrClientConfig(err error) error {
return errors.NewDefault(ErrClientConfigCode, "Error setting client Config", err.Error())
return errors.New(ErrClientConfigCode, errors.Alert, []string{"Error setting client Config"}, []string{err.Error()}, []string{}, []string{})
}

func ErrClientSet(err error) error {
return errors.NewDefault(ErrClientSetCode, "Error setting clientset", err.Error())
return errors.New(ErrClientSetCode, errors.Alert, []string{"Error setting clientset"}, []string{err.Error()}, []string{}, []string{})
}

func ErrStreamEvent(err error) error {
return errors.NewDefault(ErrStreamEventCode, "Error streaming event", err.Error())
return errors.New(ErrStreamEventCode, errors.Alert, []string{"Error streaming event"}, []string{err.Error()}, []string{}, []string{})
}
func ErrListOperations(err error) error {
return errors.NewDefault(ErrListOperationsCode, "Error listing operations", err.Error())
return errors.New(ErrListOperationsCode, errors.Alert, []string{"Error listing operations"}, []string{err.Error()}, []string{}, []string{})
}

func ErrNewSmi(err error) error {
return errors.NewDefault(ErrNewSmiCode, "Error creating new SMI test client", err.Error())
return errors.New(ErrNewSmiCode, errors.Alert, []string{"Error creating new SMI test client"}, []string{err.Error()}, []string{}, []string{})
}

func ErrRunSmi(err error) error {
return errors.NewDefault(ErrRunSmiCode, "Error running SMI conformance test", err.Error())
return errors.New(ErrRunSmiCode, errors.Alert, []string{"Error running SMI conformance test"}, []string{err.Error()}, []string{}, []string{})
}

// ErrSmiInit is the error for smi init method
func ErrSmiInit(des string) error {
return errors.NewDefault(errors.ErrSmiInit, des)
return errors.New(ErrSmiInitCode, errors.Alert, []string{des}, []string{}, []string{}, []string{})
}

// ErrInstallSmi is the error for installing smi tool
func ErrInstallSmi(err error) error {
return errors.NewDefault(errors.ErrInstallSmi, fmt.Sprintf("Error installing smi tool: %s", err.Error()))
return errors.New(ErrInstallSmiCode, errors.Alert, []string{"Error installing smi tool"}, []string{err.Error()}, []string{}, []string{})
}

// ErrConnectSmi is the error for connecting to smi tool
func ErrConnectSmi(err error) error {
return errors.NewDefault(errors.ErrConnectSmi, fmt.Sprintf("Error connecting to smi tool: %s", err.Error()))
return errors.New(ErrConnectSmiCode, errors.Alert, []string{"Error connecting to smi tool: %s"}, []string{err.Error()}, []string{}, []string{})
}

// ErrDeleteSmi is the error for deleting smi tool
func ErrDeleteSmi(err error) error {
return errors.NewDefault(errors.ErrDeleteSmi, fmt.Sprintf("Error deleting smi tool: %s", err.Error()))
return errors.New(ErrDeleteSmiCode, errors.Alert, []string{"Error deleting smi tool: %s"}, []string{err.Error()}, []string{}, []string{})
}

// ErrOpenOAMDefintionFile is the error for opening OAM Definition file
func ErrOpenOAMDefintionFile(err error) error {
return errors.NewDefault(ErrOpenOAMDefintionFileCode, fmt.Sprintf("error opening OAM Definition File: %s", err.Error()))
return errors.New(ErrOpenOAMDefintionFileCode, errors.Alert, []string{"error opening OAM Definition File: %s"}, []string{err.Error()}, []string{}, []string{})
}

// ErrOpenOAMRefFile is the error for opening OAM Schema Ref file
func ErrOpenOAMRefFile(err error) error {
return errors.NewDefault(ErrOpenOAMRefFileCode, fmt.Sprintf("error opening OAM Schema Ref File: %s", err.Error()))
return errors.New(ErrOpenOAMRefFileCode, errors.Alert, []string{"error opening OAM Schema Ref File: %s"}, []string{err.Error()}, []string{}, []string{})
}

// ErrJSONMarshal is the error for json marhal failure
func ErrJSONMarshal(err error) error {
return errors.NewDefault(ErrOAMRetryCode, fmt.Sprintf("error marshal JSON: %s", err.Error()))
return errors.New(ErrOAMRetryCode, errors.Alert, []string{"error marshal JSON: %s"}, []string{err.Error()}, []string{}, []string{})
}

func ErrOAMRetry(err error) error {
return errors.NewDefault(ErrOAMRetryCode, fmt.Sprintf("error marshal JSON: %s", err.Error()))
return errors.New(ErrOAMRetryCode, errors.Alert, []string{"error marshal JSON: %s"}, []string{err.Error()}, []string{}, []string{})
}
13 changes: 9 additions & 4 deletions api/grpc/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,22 @@ import (
)

var (
ErrRequestInvalid = errors.NewDefault("603", "Apply Request invalid")
ErrRequestInvalidCode = "1000"
ErrPanicCode = "1001"
ErrGrpcListenerCode = "1002"
ErrGrpcServerCode = "1003"

ErrRequestInvalid = errors.New(ErrRequestInvalidCode, errors.Alert, []string{"Apply Request invalid"}, []string{}, []string{}, []string{})
)

func ErrPanic(r interface{}) error {
return errors.NewDefault(errors.ErrPanic, fmt.Sprintf("%v", r))
return errors.New(ErrPanicCode, errors.Alert, []string{fmt.Sprintf("%v", r)}, []string{}, []string{}, []string{})
}

func ErrGrpcListener(err error) error {
return errors.NewDefault(errors.ErrGrpcListener, fmt.Sprintf("Error during grpc listener initialization : %v", err))
return errors.New(ErrGrpcListenerCode, errors.Alert, []string{"Error during grpc listener initialization"}, []string{err.Error()}, []string{}, []string{})
}

func ErrGrpcServer(err error) error {
return errors.NewDefault(errors.ErrGrpcServer, fmt.Sprintf("Error during grpc server initialization : %v", err))
return errors.New(ErrGrpcServerCode, errors.Alert, []string{"Error during grpc server initialization"}, []string{err.Error()}, []string{}, []string{})
}
5 changes: 5 additions & 0 deletions component_info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "meshery-adapter-library",
"type": "library",
"next_error_code": 1011
}
9 changes: 6 additions & 3 deletions config/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,19 @@ import (
)

var (
ErrEmptyConfigCode = "1004"
ErrViperCode = "1005"
ErrInMemCode = "1006"
// ErrEmptyConfig is returned when the config has not been initialized.
ErrEmptyConfig = errors.NewDefault(errors.ErrEmptyConfig, "Config not initialized")
ErrEmptyConfig = errors.New(ErrEmptyConfigCode, errors.Alert, []string{"Config not initialized"}, []string{}, []string{}, []string{})
)

// ErrViper returns a MeshKit error wrapping err in case of an (initialization) error in the Viper provider.
func ErrViper(err error) error {
return errors.NewDefault(errors.ErrViper, "Viper initialization failed with error: ", err.Error())
return errors.New(ErrViperCode, errors.Alert, []string{"Viper initialization failed with error: "}, []string{err.Error()}, []string{}, []string{})
}

// ErrViper returns a MeshKit error wrapping err in case of an (initialization) error in the in-memory provider.
func ErrInMem(err error) error {
return errors.NewDefault(errors.ErrInMem, "InMem initialization failed with error: ", err.Error())
return errors.New(ErrInMemCode, errors.Alert, []string{"InMem initialization failed with error: "}, []string{err.Error()}, []string{}, []string{})
}
Loading

0 comments on commit b9d09d2

Please sign in to comment.