From 9199f202bee1955af97cf20f6f263059ae41b180 Mon Sep 17 00:00:00 2001 From: Jason Streifling Date: Fri, 24 Jan 2025 17:42:05 +0100 Subject: [PATCH] Check atom feed for nil returns --- cmd/backend/atom.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/cmd/backend/atom.go b/cmd/backend/atom.go index 0f344c7..25d22e0 100644 --- a/cmd/backend/atom.go +++ b/cmd/backend/atom.go @@ -1,6 +1,7 @@ package backend import ( + "errors" "fmt" "io" "os" @@ -12,6 +13,9 @@ func GenerateAtomFeed(c *Config, db *DB) (*string, error) { feed := atom.NewFeed(c.Title) feed.ID = atom.NewID("urn:feed:1") feed.Subtitle = atom.NewText("text", c.Description) + if feed.Subtitle == nil { + return nil, errors.New("feed subtitle was not created") + } linkID := feed.AddLink(atom.NewLink(c.Link)) feed.Links[linkID].Rel = "self" @@ -34,15 +38,24 @@ func GenerateAtomFeed(c *Config, db *DB) (*string, error) { entry.ID = atom.NewID(fmt.Sprint("urn:entry:", article.ID)) entry.Published = atom.NewDate(article.Created) entry.Content = atom.NewContent(atom.OutOfLine, "text/html", fmt.Sprint(c.Domain, "/article/serve/", article.UUID)) + if entry.Content == nil { + return nil, errors.New("entry content was not created") + } if article.AutoGenerated { entry.Summary = atom.NewText("text", "automatically generated") + if entry.Summary == nil { + return nil, errors.New("entry summary was not created") + } } else { articleSummary, err := ConvertToPlain(article.Summary) if err != nil { return nil, fmt.Errorf("error converting description to plain text for Atom feed: %v", err) } entry.Summary = atom.NewText("text", articleSummary) + if entry.Summary == nil { + return nil, errors.New("entry summary was not created") + } } if len(article.BannerLink) > 0 {