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