From f79af9c6a8de8582f948aaefb6e62b2ae407f917 Mon Sep 17 00:00:00 2001 From: Eric Munson Date: Wed, 11 Mar 2026 12:37:53 -0400 Subject: [PATCH] feat(podcast): ensure that any error path out of doPodcastDownload sets status (#672) Some error paths out of this function are not setting the podcast status to 'error'. Move the deferred error checking earlier to ensure the status is set. Signed-off-by: Eric B Munson --- podcast/podcast.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/podcast/podcast.go b/podcast/podcast.go index 49b357c..d488a66 100644 --- a/podcast/podcast.go +++ b/podcast/podcast.go @@ -516,6 +516,13 @@ func (p *Podcasts) doPodcastDownload(podcast *db.Podcast, podcastEpisode *db.Pod } defer resp.Body.Close() + defer func() { + if err != nil { + podcastEpisode.Status = db.PodcastEpisodeStatusError + _ = p.db.Save(podcastEpisode).Error + } + }() + if resp.StatusCode/100 != 2 { return fmt.Errorf("fetch podcast audio: unexpected status %s", resp.Status) } @@ -537,13 +544,6 @@ func (p *Podcasts) doPodcastDownload(podcast *db.Podcast, podcastEpisode *db.Pod } defer file.Close() - defer func() { - if err != nil { - podcastEpisode.Status = db.PodcastEpisodeStatusError - _ = p.db.Save(podcastEpisode).Error - } - }() - if _, err := io.Copy(file, resp.Body); err != nil { return fmt.Errorf("writing podcast episode: %w", err) }