From 80adf6214ec5b4879fdba5b013e5d14142da84c3 Mon Sep 17 00:00:00 2001 From: Steve Date: Mon, 20 Mar 2023 11:40:07 -0400 Subject: [PATCH] extra error checking --- reddit.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/reddit.go b/reddit.go index 2cb5938..2af9b32 100644 --- a/reddit.go +++ b/reddit.go @@ -51,7 +51,11 @@ func getNewestPost(subreddit string) (post, error) { if len(resp.Data.Children) < 1 { return post{}, errors.New("bad data from reddit") } - numS := re.FindStringSubmatch(resp.Data.Children[0].Data.Title)[0] + reSearch := re.FindStringSubmatch(resp.Data.Children[0].Data.Title) + if len(reSearch) == 0 { + return post{}, fmt.Errorf("Something strange in data from reddit") + } + numS := reSearch[0] num, err := strconv.Atoi(numS) if err != nil || numS == "" { num = -1