From e36eb6a0e1a4d5a81dd8fb279d05ed1b5500744d Mon Sep 17 00:00:00 2001 From: Tom McKeesick Date: Tue, 22 Mar 2022 11:46:02 +1100 Subject: [PATCH] Log an error if a name token has no matches --- pokesay.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pokesay.go b/pokesay.go index e9e8f710..be810014 100644 --- a/pokesay.go +++ b/pokesay.go @@ -159,8 +159,12 @@ func main() { } if args.NameToken != "" { + matches := collectPokemonWithToken(pokemon, args.NameToken) + if len(matches) == 0 { + log.Fatal(fmt.Sprintf("Not a valid name: '%s'", args.NameToken)) + } printSpeechBubble(bufio.NewScanner(os.Stdin), args) - printPokemon(chooseRandomPokemon(collectPokemonWithToken(pokemon, args.NameToken))) + printPokemon(chooseRandomPokemon(matches)) os.Exit(0) }