-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into ab/port-check
- Loading branch information
Showing
3 changed files
with
84 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,67 @@ | ||
package localerr | ||
|
||
import "errors" | ||
var _ error = (*LocalError)(nil) | ||
|
||
// LocalError adds a user-friendly help message to specific errors. | ||
type LocalError struct { | ||
help string | ||
msg string | ||
} | ||
|
||
// Help will displayed to the user if this specific error is ever returned. | ||
func (e *LocalError) Help() string { | ||
return e.help | ||
} | ||
|
||
// Error returns the error message. | ||
func (e *LocalError) Error() string { | ||
return e.msg | ||
} | ||
|
||
var ( | ||
// ErrAirbyteDir is returned anytime an there is an issue in accessing the paths.Airbyte directory. | ||
ErrAirbyteDir = errors.New("airbyte directory is inaccessible") | ||
ErrAirbyteDir = &LocalError{ | ||
msg: "airbyte directory is inaccessible", | ||
help: `The ~/.airbyte directory is inaccessible. | ||
You may need to remove this directory before trying your command again.`, | ||
} | ||
|
||
// ErrClusterNotFound is returned in the event that no cluster was located. | ||
ErrClusterNotFound = errors.New("no existing cluster found") | ||
ErrClusterNotFound = &LocalError{ | ||
msg: "no existing cluster found", | ||
help: `No cluster was found. If this is unexpected, | ||
you may need to run the "local install" command again.`, | ||
} | ||
|
||
// ErrDocker is returned anytime an error occurs when attempting to communicate with docker. | ||
ErrDocker = errors.New("error communicating with docker") | ||
ErrDocker = &LocalError{ | ||
msg: "error communicating with docker", | ||
help: `An error occurred while communicating with the Docker daemon. | ||
Ensure that Docker is running and is accessible. You may need to upgrade to a newer version of Docker. | ||
For additional help please visit https://docs.docker.com/get-docker/`, | ||
} | ||
|
||
// ErrKubernetes is returned anytime an error occurs when attempting to communicate with the kubernetes cluster. | ||
ErrKubernetes = errors.New("error communicating with kubernetes") | ||
ErrKubernetes = &LocalError{ | ||
msg: "error communicating with kubernetes", | ||
help: `An error occurred while communicating with the Kubernetes cluster. | ||
If this error persists, you may need to run the uninstall command before attempting to run | ||
the install command again.`, | ||
} | ||
|
||
// ErrIngress is returned in the event that ingress configuration failed. | ||
ErrIngress = errors.New("error configuring ingress") | ||
ErrIngress = &LocalError{ | ||
msg: "error configuring ingress", | ||
help: `An error occurred while configuring ingress. | ||
This could be in indication that the ingress port is already in use by a different application. | ||
The ingress port can be changed by passing the flag --port.`, | ||
} | ||
|
||
// ErrPort is returned in the event that the requested port is unavailable. | ||
ErrPort = errors.New("error verifying port availability") | ||
ErrPort = &LocalError{ | ||
msg: "error verifying port availability", | ||
help: `An error occurred while verifying if the request port is available. | ||
This could be in indication that the ingress port is already in use by a different application. | ||
The ingress port can be changed by passing the flag --port.`, | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package localerr | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
func TestLocalError(t *testing.T) { | ||
f := func() error { | ||
return &LocalError{ | ||
help: "help message", | ||
msg: "error message", | ||
} | ||
} | ||
|
||
err := f() | ||
var e *LocalError | ||
if !errors.As(err, &e) { | ||
t.Fatal("error should be of type LocalError") | ||
} | ||
|
||
if d := cmp.Diff("help message", e.Help()); d != "" { | ||
t.Errorf("help message diff:\n%s", d) | ||
} | ||
if d := cmp.Diff("error message", e.Error()); d != "" { | ||
t.Errorf("error message diff:\n%s", d) | ||
} | ||
} |