Skip to content

Commit 214b978

Browse files
returning an error (#144)
1 parent 57bf0df commit 214b978

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

cmd/ability/ability.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"strings"
1414
)
1515

16-
func AbilityCommand() string {
16+
func AbilityCommand() (string, error) {
1717
var output strings.Builder
1818

1919
flag.Usage = func() {
@@ -38,12 +38,12 @@ func AbilityCommand() string {
3838

3939
if len(os.Args) == 3 && (os.Args[2] == "-h" || os.Args[2] == "--help") {
4040
flag.Usage()
41-
return output.String()
41+
return output.String(), nil
4242
}
4343

4444
if err := utils.ValidateAbilityArgs(args); err != nil {
4545
output.WriteString(err.Error())
46-
return output.String()
46+
return output.String(), err
4747
}
4848

4949
endpoint := strings.ToLower(args[1])
@@ -55,7 +55,7 @@ func AbilityCommand() string {
5555
if os.Getenv("GO_TESTING") != "1" {
5656
os.Exit(1)
5757
}
58-
return output.String()
58+
return output.String(), err
5959
}
6060

6161
abilitiesStruct, abilityName, err := connections.AbilityApiCall(endpoint, abilityName, connections.APIURL)
@@ -64,7 +64,7 @@ func AbilityCommand() string {
6464
fmt.Fprintln(os.Stderr, err)
6565
os.Exit(1)
6666
}
67-
return err.Error()
67+
return err.Error(), nil
6868
}
6969

7070
// Extract English short_effect
@@ -108,11 +108,9 @@ func AbilityCommand() string {
108108
if *pokemonFlag || *shortPokemonFlag {
109109
if err := flags.PokemonAbilitiesFlag(&output, endpoint, abilityName); err != nil {
110110
output.WriteString(fmt.Sprintf("error parsing flags: %v\n", err))
111-
if os.Getenv("GO_TESTING") != "1" {
112-
os.Exit(1)
113-
}
111+
return "", fmt.Errorf("error parsing flags: %w", err)
114112
}
115113
}
116114

117-
return output.String()
115+
return output.String(), nil
118116
}

0 commit comments

Comments
 (0)