Skip to content

Commit

Permalink
refactor: prefix with err to match stdlib
Browse files Browse the repository at this point in the history
  • Loading branch information
bashbunni committed Jun 7, 2023
1 parent 5d5a228 commit 390eef1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
18 changes: 9 additions & 9 deletions main.go
Expand Up @@ -124,15 +124,15 @@ var (
}
)

type suggestionNotFoundErr struct {
type errDBNotFound struct {
suggestions []string
}

func (e suggestionNotFoundErr) Error() string {
if len(e.suggestions) == 0 {
func (err errDBNotFound) Error() string {
if len(err.suggestions) == 0 {
return "no suggestions found"
}
return fmt.Sprintf("did you mean %q", strings.Join(e.suggestions, ", "))
return fmt.Sprintf("did you mean %q", strings.Join(err.suggestions, ", "))
}

func set(cmd *cobra.Command, args []string) error {

Check warning on line 138 in main.go

View workflow job for this annotation

GitHub Actions / lint

unused-parameter: parameter 'cmd' seems to be unused, consider removing or renaming it as _ (revive)
Expand Down Expand Up @@ -226,14 +226,14 @@ func deleteDb(cmd *cobra.Command, args []string) error {
return err
}
path, err := findDb(args[0], dbs)
var notFoundErr suggestionNotFoundErr
if errors.As(err, &notFoundErr) {
var errNotFound errDBNotFound
if errors.As(err, &errNotFound) {
fmt.Printf("%q does not exist, %s\n", args[0], err.Error())
os.Exit(1)
}
if err != nil {
fmt.Printf("unexpected error: %s", err.Error())
os.Exit(1)
fmt.Printf("unexpected error: %s", err.Error())
os.Exit(1)
}
var confirmation string
fmt.Printf("are you sure you want to delete '%s' and all its contents?(y/n) ", warningStyle.Render(path))
Expand Down Expand Up @@ -271,7 +271,7 @@ func findDb(name string, dbs []string) (string, error) {
suggestions = append(suggestions, db)
}
}
return "", suggestionNotFoundErr{suggestions: suggestions}
return "", errDBNotFound{suggestions: suggestions}
}
return path, nil
}
Expand Down
18 changes: 9 additions & 9 deletions main_test.go
Expand Up @@ -19,7 +19,7 @@ func TestFindDbs(t *testing.T) {
{
name: "@spon",
dbs: defaultDbs,
err: suggestionNotFoundErr{
err: errDBNotFound{
suggestions: []string{
"@spongebob",
},
Expand All @@ -28,7 +28,7 @@ func TestFindDbs(t *testing.T) {
{
name: "@char",
dbs: defaultDbs,
err: suggestionNotFoundErr{
err: errDBNotFound{
suggestions: []string{
"@charm.sh.kv.user.default",
"@charm.sh.skate.default",
Expand All @@ -38,7 +38,7 @@ func TestFindDbs(t *testing.T) {
{
name: "spon",
dbs: defaultDbs,
err: suggestionNotFoundErr{
err: errDBNotFound{
suggestions: []string{
"@spongebob",
},
Expand All @@ -47,21 +47,21 @@ func TestFindDbs(t *testing.T) {
{
name: "",
dbs: defaultDbs,
err: suggestionNotFoundErr{
err: errDBNotFound{
suggestions: nil,
},
},
{
name: "endo",
dbs: defaultDbs,
err: suggestionNotFoundErr{
err: errDBNotFound{
suggestions: nil,
},
},
{
name: "@endo",
dbs: defaultDbs,
err: suggestionNotFoundErr{
err: errDBNotFound{
suggestions: nil,
},
},
Expand All @@ -78,12 +78,12 @@ func TestFindDbs(t *testing.T) {
if err == nil {
t.Fatalf("expected an error, got: %v", err)
}
var perr suggestionNotFoundErr
var perr errDBNotFound
if !errors.As(err, &perr) {
t.Fatalf("something went wrong! got: %v", err)
}
if len(err.(suggestionNotFoundErr).suggestions) !=
len(tc.err.(suggestionNotFoundErr).suggestions) {
if len(err.(errDBNotFound).suggestions) !=
len(tc.err.(errDBNotFound).suggestions) {
t.Fatalf("got != want. got: %v, want: %v", err, tc.err)
}
}
Expand Down

0 comments on commit 390eef1

Please sign in to comment.