feat(podcast): ensure that any error path out of doPodcastDownload sets status (#672)
Release / Lint and test (push) Successful in 2m44s
Release / Run Release Please (push) Failing after 15s
Release / Notify IRC (push) Has been skipped
Release / Build binaries (386, linux) (push) Has been skipped
Release / Build binaries (386, windows) (push) Has been skipped
Release / Build binaries (amd64, darwin) (push) Has been skipped
Release / Build binaries (amd64, linux) (push) Has been skipped
Release / Build binaries (amd64, windows) (push) Has been skipped
Release / Build binaries (arm64, darwin) (push) Has been skipped
Release / Build binaries (arm64, linux) (push) Has been skipped
Release / Build, tag, and publish Docker image (push) Has been skipped

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-04-26 03:00:56 +02:00
committed by yaemiku
parent 8df5f95a3d
commit f79af9c6a8
+7 -7
View File
@@ -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)
}