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 <eric@munsonfam.org>
This commit is contained in:
Eric Munson
2026-03-11 16:37:53 +00:00
committed by GitHub
parent 9473ec7539
commit 192ee10b3f
+7 -7
View File
@@ -516,6 +516,13 @@ func (p *Podcasts) doPodcastDownload(podcast *db.Podcast, podcastEpisode *db.Pod
} }
defer resp.Body.Close() defer resp.Body.Close()
defer func() {
if err != nil {
podcastEpisode.Status = db.PodcastEpisodeStatusError
_ = p.db.Save(podcastEpisode).Error
}
}()
if resp.StatusCode/100 != 2 { if resp.StatusCode/100 != 2 {
return fmt.Errorf("fetch podcast audio: unexpected status %s", resp.Status) 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 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 { if _, err := io.Copy(file, resp.Body); err != nil {
return fmt.Errorf("writing podcast episode: %w", err) return fmt.Errorf("writing podcast episode: %w", err)
} }