Skip to content

Commit

Permalink
Merge pull request #352 from zerok/feature/verbose-archive-error
Browse files Browse the repository at this point in the history
Print a more verbose error message if archiving fails
  • Loading branch information
caarlos0 committed Sep 9, 2017
2 parents be4f43a + b1b382c commit 272bd93
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions pipeline/archive/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package archive

import (
"fmt"
"os"
"path/filepath"

Expand Down Expand Up @@ -42,9 +43,10 @@ func (Pipe) Run(ctx *context.Context) error {
func create(ctx *context.Context, platform string, groups map[string][]context.Binary) error {
for folder, binaries := range groups {
var format = archiveformat.For(ctx, platform)
file, err := os.Create(filepath.Join(ctx.Config.Dist, folder+"."+format))
targetFolder := filepath.Join(ctx.Config.Dist, folder+"."+format)
file, err := os.Create(targetFolder)
if err != nil {
return err
return fmt.Errorf("failed to create directory %s: %s", targetFolder, err.Error())
}
defer func() { _ = file.Close() }()
log.WithField("archive", file.Name()).Info("creating")
Expand All @@ -53,16 +55,16 @@ func create(ctx *context.Context, platform string, groups map[string][]context.B

files, err := findFiles(ctx)
if err != nil {
return err
return fmt.Errorf("failed to find files to archive: %s", err.Error())
}
for _, f := range files {
if err = archive.Add(f, f); err != nil {
return err
return fmt.Errorf("failed to add %s to the archive: %s", f, err.Error())
}
}
for _, binary := range binaries {
if err := archive.Add(binary.Name, binary.Path); err != nil {
return err
return fmt.Errorf("failed to add %s -> %s to the archive: %s", binary.Path, binary.Name, err.Error())
}
}
ctx.AddArtifact(file.Name())
Expand All @@ -84,7 +86,7 @@ func findFiles(ctx *context.Context) (result []string, err error) {
for _, glob := range ctx.Config.Archive.Files {
files, err := zglob.Glob(glob)
if err != nil {
return result, err
return result, fmt.Errorf("globbing failed for pattern %s: %s", glob, err.Error())
}
result = append(result, files...)
}
Expand Down

0 comments on commit 272bd93

Please sign in to comment.