Skip to content

Commit

Permalink
feat(pipe/build): Report hook error in addition to stdout (#1430)
Browse files Browse the repository at this point in the history
This helps in situations where hook couldn't run at all,
e.g. because of insufficient permissions.

Previously such failure would only be reported as
empty stdout/stderr output - this allows exposure
of the real root cause.
  • Loading branch information
radeksimko committed Apr 12, 2020
1 parent e580a18 commit cfa0cc2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion internal/pipe/build/build.go
Expand Up @@ -162,7 +162,7 @@ func run(ctx *context.Context, command, env []string) error {
log.Debug("running")
if out, err := cmd.CombinedOutput(); err != nil {
log.WithError(err).Debug("failed")
return errors.New(string(out))
return errors.Wrapf(err, "%q", string(out))
}
return nil
}
4 changes: 2 additions & 2 deletions internal/pipe/build/build_test.go
Expand Up @@ -182,14 +182,14 @@ func TestRunPipeFailingHooks(t *testing.T) {
ctx.Git.CurrentTag = "2.3.4"
ctx.Config.Builds[0].Hooks.Pre = "exit 1"
ctx.Config.Builds[0].Hooks.Post = "echo post"
assert.EqualError(t, Pipe{}.Run(ctx), `pre hook failed: `)
assert.EqualError(t, Pipe{}.Run(ctx), `pre hook failed: "": exec: "exit": executable file not found in $PATH`)
})
t.Run("post-hook", func(t *testing.T) {
var ctx = context.New(config)
ctx.Git.CurrentTag = "2.3.4"
ctx.Config.Builds[0].Hooks.Pre = "echo pre"
ctx.Config.Builds[0].Hooks.Post = "exit 1"
assert.EqualError(t, Pipe{}.Run(ctx), `post hook failed: `)
assert.EqualError(t, Pipe{}.Run(ctx), `post hook failed: "": exec: "exit": executable file not found in $PATH`)
})
}

Expand Down

0 comments on commit cfa0cc2

Please sign in to comment.