mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-03-17 20:47:50 +02:00
fix: improve docker error handling (#3942)
refs https://github.com/goreleaser/goreleaser/pull/3940#issuecomment-1507149519
This commit is contained in:
parent
f6b5e9abb8
commit
e872e45b44
@ -199,7 +199,7 @@ func process(ctx *context.Context, docker config.Docker, artifacts []*artifact.A
|
||||
|
||||
log.Info("building docker image")
|
||||
if err := imagers[docker.Use].Build(ctx, tmp, images, buildFlags); err != nil {
|
||||
if strings.Contains(err.Error(), "file not found") || strings.Contains(err.Error(), "not found: not found") {
|
||||
if isFileNotFoundError(err.Error()) {
|
||||
var files []string
|
||||
_ = filepath.Walk(tmp, func(path string, info fs.FileInfo, err error) error {
|
||||
if info.IsDir() {
|
||||
@ -238,6 +238,14 @@ Previous error:
|
||||
return nil
|
||||
}
|
||||
|
||||
func isFileNotFoundError(out string) bool {
|
||||
if strings.Contains(out, `executable file not found in $PATH`) {
|
||||
return false
|
||||
}
|
||||
return strings.Contains(out, "file not found") ||
|
||||
strings.Contains(out, "not found: not found")
|
||||
}
|
||||
|
||||
func processImageTemplates(ctx *context.Context, docker config.Docker) ([]string, error) {
|
||||
// nolint:prealloc
|
||||
var images []string
|
||||
|
@ -1428,3 +1428,14 @@ func TestDependencies(t *testing.T) {
|
||||
require.Equal(t, []string{"docker", "docker"}, Pipe{}.Dependencies(ctx))
|
||||
require.Equal(t, []string{"docker", "docker"}, ManifestPipe{}.Dependencies(ctx))
|
||||
}
|
||||
|
||||
func TestIsFileNotFoundError(t *testing.T) {
|
||||
t.Run("executable not in path", func(t *testing.T) {
|
||||
require.False(t, isFileNotFoundError(`error getting credentials - err: exec: "docker-credential-desktop": executable file not found in $PATH, out:`))
|
||||
})
|
||||
|
||||
t.Run("file not found", func(t *testing.T) {
|
||||
require.True(t, isFileNotFoundError(`./foo: file not found`))
|
||||
require.True(t, isFileNotFoundError(`./foo: not found: not found`))
|
||||
})
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user