Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Refactor errors to errors.go files #56

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions cmd/connectivity_pod_to_pod.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"github.com/pkg/errors"
"github.com/spf13/cobra"

"github.com/openservicemesh/osm-health/pkg/connectivity"
Expand All @@ -27,17 +26,17 @@ func newConnectivityPodToPodCmd() *cobra.Command {
Args: cobra.ExactArgs(2),
RunE: func(_ *cobra.Command, args []string) error {
if len(args) < 2 {
return errors.Errorf("provide both SOURCE_POD and DESTINATION_POD")
return ErrNoSourcePodOrNoDestinationPod
}

fromPod, err := kuberneteshelper.PodFromString(args[0])
if err != nil {
return errors.New("invalid SOURCE_POD")
return ErrInvalidSourcePod
}

toPod, err := kuberneteshelper.PodFromString(args[1])
if err != nil {
return errors.New("invalid DESTINATION_POD")
return ErrInvalidDestinationPod
}

connectivity.PodToPod(fromPod, toPod)
Expand Down
7 changes: 3 additions & 4 deletions cmd/connectivity_pod_to_url.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"net/url"

"github.com/pkg/errors"
"github.com/spf13/cobra"

"github.com/openservicemesh/osm-health/pkg/connectivity"
Expand All @@ -29,17 +28,17 @@ func newConnectivityPodToURLCmd() *cobra.Command {
Args: cobra.ExactArgs(2),
RunE: func(_ *cobra.Command, args []string) error {
if len(args) < 2 {
return errors.Errorf("provide both SOURCE_POD and DESTINATION_URL")
return ErrNoSourcePodOrNoDestinationURL
}

fromPod, err := kuberneteshelper.PodFromString(args[0])
if err != nil {
return errors.New("invalid SOURCE_POD")
return ErrInvalidSourcePod
}

toURL, err := url.Parse(args[1])
if err != nil {
return errors.New("invalid DESTINATION_URL")
return ErrInvalidDestinationURL
}

connectivity.PodToURL(fromPod, toURL)
Expand Down
23 changes: 23 additions & 0 deletions cmd/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package main

import "errors"

var (
// ErrNoSourcePodOrNoDestinationPod is an error when the user does not supply the SOURCE_POD or the DESTINATION_POD.
ErrNoSourcePodOrNoDestinationPod = errors.New("provide both SOURCE_POD and DESTINATION_POD")

// ErrInvalidSourcePod is an error when the supplied source pod is invalid.
ErrInvalidSourcePod = errors.New("invalid SOURCE_POD")

// ErrInvalidDestinationPod is an error when the supplied destination pod is invalid.
ErrInvalidDestinationPod = errors.New("invalid DESTINATION_POD")

// ErrNoSourcePodOrNoDestinationURL is an error when the user does not supply the SOURCE_POD or the DESTINATION_URL.
ErrNoSourcePodOrNoDestinationURL = errors.New("provide both SOURCE_POD and DESTINATION_URL")

// ErrInvalidDestinationURL is an error when the supplied destination URL is invalid.
ErrInvalidDestinationURL = errors.New("invalid DESTINATION_URL")

// ErrNoDestinationPod is an error when the user does not supply the DESTINATION_POD.
ErrNoDestinationPod = errors.New("provide DESTINATION_POD")
)
5 changes: 2 additions & 3 deletions cmd/ingress_to_pod.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"github.com/pkg/errors"
"github.com/spf13/cobra"

"github.com/openservicemesh/osm-health/pkg/ingress"
Expand All @@ -16,7 +15,7 @@ func newIngressToPodCmd() *cobra.Command {
Args: cobra.ExactArgs(1),
RunE: func(_ *cobra.Command, args []string) error {
if len(args) < 1 {
return errors.Errorf("missing DESTINATION_POD parameter")
return ErrNoDestinationPod
}
log.Info().Msgf("Checking Ingress to Pod %s", args[0])

Expand All @@ -27,7 +26,7 @@ func newIngressToPodCmd() *cobra.Command {

toPod, err := kuberneteshelper.PodFromString(args[0])
if err != nil {
return errors.New("invalid DESTINATION_POD")
return ErrInvalidDestinationPod
}

ingress.ToPod(client, toPod)
Expand Down