From 5c00f390ad78d35ba6a056b407360a3831dc4ab7 Mon Sep 17 00:00:00 2001 From: Corentin Barreau Date: Sun, 29 Sep 2024 00:47:40 +0200 Subject: [PATCH] fix: handle empty reddit.com API post body --- internal/pkg/crawl/sitespecific/reddit/post.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/pkg/crawl/sitespecific/reddit/post.go b/internal/pkg/crawl/sitespecific/reddit/post.go index f4241db9..1ffc5280 100644 --- a/internal/pkg/crawl/sitespecific/reddit/post.go +++ b/internal/pkg/crawl/sitespecific/reddit/post.go @@ -195,6 +195,10 @@ func ExtractPost(body []byte) (permalinks []string, assets []string, err error) return permalinks, assets, err } + if len(data.Data.Children) == 0 { + return permalinks, assets, fmt.Errorf("no children found in post") + } + permalinks = append(permalinks, fmt.Sprintf("https://www.reddit.com%s", data.Data.Children[0].Data.Permalink), fmt.Sprintf("https://old.reddit.com%s", data.Data.Children[0].Data.Permalink)) assets, err = extractor.GetURLsFromJSON(body)