Skip to content

Commit

Permalink
refactor: rename errors
Browse files Browse the repository at this point in the history
Signed-off-by: Ruslan Semagin <[email protected]>
  • Loading branch information
pixel365 committed Feb 17, 2025
1 parent b50dfbc commit 08473b0
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion cmd/account/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func lsCmd() *cobra.Command {
}

if len(conf.GetAccounts()) == 0 {
internal.ResultMessage(internal.NoAccountsFound.Error())
internal.ResultMessage(internal.NoAccountsFoundError.Error())
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/account/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func moduleCmd() *cobra.Command {
}

if j == 0 {
internal.ResultMessage(internal.NoModulesFound.Error())
internal.ResultMessage(internal.NoModulesFoundError.Error())
return nil
}

Expand Down
8 changes: 4 additions & 4 deletions cmd/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestAccountAdd(t *testing.T) {
t.Error("invalid result")
}

if !errors.Is(err, internal.AccountAlreadyExists) {
if !errors.Is(err, internal.AccountAlreadyExistsError) {
t.Errorf("invalid result: %v", err)
}
})
Expand Down Expand Up @@ -161,7 +161,7 @@ func TestAccountRmAccountNotFound(t *testing.T) {
t.Error("invalid result")
}

if err.Error() != internal.NoAccountFound.Error() {
if err.Error() != internal.NoAccountFoundError.Error() {
t.Error(err)
}
})
Expand Down Expand Up @@ -192,7 +192,7 @@ func TestAccountNoModules(t *testing.T) {
}
})

if output != fmt.Sprintf("%s\n", internal.NoModulesFound.Error()) {
if output != fmt.Sprintf("%s\n", internal.NoModulesFoundError.Error()) {
t.Error("invalid result")
}
})
Expand Down Expand Up @@ -221,7 +221,7 @@ func TestAccountNoModulesNoAccount(t *testing.T) {
t.Error("invalid result")
}

if err.Error() != internal.NoAccountFound.Error() {
if err.Error() != internal.NoAccountFoundError.Error() {
t.Error(err)
}
})
Expand Down
4 changes: 2 additions & 2 deletions cmd/module/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func lsCmd() *cobra.Command {
}

if len(conf.GetModules()) == 0 {
internal.ResultMessage(internal.NoModulesFound.Error())
internal.ResultMessage(internal.NoModulesFoundError.Error())
return nil
}

Expand Down Expand Up @@ -55,7 +55,7 @@ func lsCmd() *cobra.Command {
}

if j == 0 {
internal.ResultMessage(internal.NoModulesFound.Error())
internal.ResultMessage(internal.NoModulesFoundError.Error())
}
}

Expand Down
18 changes: 9 additions & 9 deletions internal/err.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package internal
import "errors"

var (
NoConfigError = errors.New("no config found in context")
NoAccountFound = errors.New("account not found")
NoAccountsFound = errors.New("no accounts found")
NoItemsFound = errors.New("item not found")
EmptyLogin = errors.New("login is empty")
AccountAlreadyExists = errors.New("account already exists")
EmptyPassword = errors.New("password is empty")
PasswordTooShort = errors.New("password is too short")
NoModulesFound = errors.New("no modules found")
NoConfigError = errors.New("no config found in context")
NoAccountFoundError = errors.New("account not found")
NoAccountsFoundError = errors.New("no accounts found")
NoItemsFoundError = errors.New("item not found")
EmptyLoginError = errors.New("login is empty")
AccountAlreadyExistsError = errors.New("account already exists")
EmptyPasswordError = errors.New("password is empty")
PasswordTooShortError = errors.New("password is too short")
NoModulesFoundError = errors.New("no modules found")
)
10 changes: 5 additions & 5 deletions internal/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type ConfigManager interface {

func AccountIndexByLogin(accounts []model.Account, login string) (int, error) {
if len(accounts) == 0 {
return 0, NoAccountsFound
return 0, NoAccountsFoundError
}

for i, account := range accounts {
Expand All @@ -49,7 +49,7 @@ func AccountIndexByLogin(accounts []model.Account, login string) (int, error) {
}
}

return 0, NoAccountFound
return 0, NoAccountFoundError
}

func Confirmation(flag *bool, title string) error {
Expand All @@ -69,11 +69,11 @@ func Choose[T OptionProvider](items []T, value *string, title string) error {
if len(items) == 0 {
switch any(items).(type) {
case []model.Account:
return NoAccountsFound
return NoAccountsFoundError
case []model.Module:
return NoModulesFound
return NoModulesFoundError
default:
return NoItemsFound
return NoItemsFoundError
}
}

Expand Down
8 changes: 4 additions & 4 deletions internal/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import (
func ValidateAccountLogin(login string, conf ConfigManager) error {
value := strings.TrimSpace(login)
if value == "" {
return EmptyLogin
return EmptyLoginError
}

if len(conf.GetAccounts()) > 0 {
for _, account := range conf.GetAccounts() {
if account.Login == value {
return AccountAlreadyExists
return AccountAlreadyExistsError
}
}
}
Expand All @@ -24,11 +24,11 @@ func ValidateAccountLogin(login string, conf ConfigManager) error {
func ValidatePassword(password string) error {
value := strings.TrimSpace(password)
if value == "" {
return EmptyPassword
return EmptyPasswordError
}

if len(value) < 6 {
return PasswordTooShort
return PasswordTooShortError
}

return nil
Expand Down

0 comments on commit 08473b0

Please sign in to comment.