-
Notifications
You must be signed in to change notification settings - Fork 11
chore: clean-up custom error and help message #98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it would be better as an interface, which we could implement on any custom error types we have. hmmm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I debated that as well, but didn't see a need for it yet. It would be easy enough to change if we decide to do that later.