Skip to content

Commit 2f1c0e2

Browse files
authored
Fix update-release swallowing release source errors (#644)
## Summary - When a release source returned a non-not-found error (e.g. a 401 auth failure), `update-release` discarded the underlying error and returned a generic `couldn't find "X" VERSION in any release source` message - Both the `GetMatchedRelease` and `FindReleaseVersion` paths had this bug - Now wraps the underlying error with `%w` so the actual failure (source ID, HTTP status, etc.) is surfaced to the user Closes #520 ## Test plan - [x] Added two new test cases covering auth-style errors for both the download and no-download paths — both previously failed and now pass - [x] All existing `UpdateRelease` tests continue to pass (`go test ./internal/commands/`) Made with [Cursor](https://cursor.com)
2 parents fa37efc + f21ad3e commit 2f1c0e2

2 files changed

Lines changed: 35 additions & 8 deletions

File tree

internal/commands/update_release.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,7 @@ func (u UpdateRelease) Execute(args []string) error {
7979
GitHubRepository: releaseSpec.GitHubRepository,
8080
}, false)
8181
if err != nil {
82-
if component.IsErrNotFound(err) {
83-
return fmt.Errorf("error finding the release: %w", err)
84-
}
85-
return fmt.Errorf("couldn't find %q %s in any release source", u.Options.Name, u.Options.Version)
82+
return fmt.Errorf("couldn't find %q %s in any release source: %w", u.Options.Name, u.Options.Version, err)
8683
}
8784

8885
newVersion = remoteRelease.Version
@@ -98,10 +95,7 @@ func (u UpdateRelease) Execute(args []string) error {
9895
GitHubRepository: releaseSpec.GitHubRepository,
9996
})
10097
if err != nil {
101-
if component.IsErrNotFound(err) {
102-
return fmt.Errorf("error finding the release: %w", err)
103-
}
104-
return fmt.Errorf("couldn't find %q %s in any release source", u.Options.Name, u.Options.Version)
98+
return fmt.Errorf("couldn't find %q %s in any release source: %w", u.Options.Name, u.Options.Version, err)
10599
}
106100

107101
localRelease, err = releaseSource.DownloadRelease(u.Options.ReleasesDir, remoteRelease)

internal/commands/update_release_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,39 @@ var _ = Describe("UpdateRelease", func() {
342342
})
343343
})
344344

345+
When("a release source returns an unexpected error (e.g. auth failure) during GetMatchedRelease", func() {
346+
BeforeEach(func() {
347+
releaseSource.GetMatchedReleaseReturns(cargo.BOSHReleaseTarballLock{}, errors.New("401 Unauthorized"))
348+
})
349+
350+
It("includes the underlying error in the returned error", func() {
351+
err := updateReleaseCommand.Execute([]string{
352+
"--kilnfile", "Kilnfile",
353+
"--name", releaseName,
354+
"--version", newReleaseVersion,
355+
"--releases-directory", releasesDir,
356+
})
357+
Expect(err).To(MatchError(ContainSubstring("401 Unauthorized")))
358+
})
359+
})
360+
361+
When("a release source returns an unexpected error (e.g. auth failure) during FindReleaseVersion", func() {
362+
BeforeEach(func() {
363+
releaseSource.FindReleaseVersionReturns(cargo.BOSHReleaseTarballLock{}, errors.New("401 Unauthorized"))
364+
})
365+
366+
It("includes the underlying error in the returned error", func() {
367+
err := updateReleaseCommand.Execute([]string{
368+
"--kilnfile", "Kilnfile",
369+
"--name", releaseName,
370+
"--version", newReleaseVersion,
371+
"--releases-directory", releasesDir,
372+
"--without-download",
373+
})
374+
Expect(err).To(MatchError(ContainSubstring("401 Unauthorized")))
375+
})
376+
})
377+
345378
When("downloading the release fails", func() {
346379
BeforeEach(func() {
347380
releaseSource.DownloadReleaseReturns(component.Local{}, errors.New("bad stuff"))

0 commit comments

Comments
 (0)