1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-26 04:22:05 +02:00
Carlos Alexandro Becker 47ce9a9b33
fix: only fail announcing phase in the end (#3666)
This prevents one announce failure to skip all other announcers.

The release will still report a failure in the end, but will not fail in
the first failure.

Also improved errors messages a little bit.

closes #3663

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
2022-12-28 12:24:21 -03:00

54 lines
1.3 KiB
Go

package errhandler
import (
"github.com/caarlos0/log"
"github.com/goreleaser/goreleaser/internal/middleware"
"github.com/goreleaser/goreleaser/internal/pipe"
"github.com/goreleaser/goreleaser/pkg/context"
"github.com/hashicorp/go-multierror"
)
// Handle handles an action error, ignoring and logging pipe skipped
// errors.
func Handle(action middleware.Action) middleware.Action {
return func(ctx *context.Context) error {
err := action(ctx)
if err == nil {
return nil
}
if pipe.IsSkip(err) {
log.WithField("reason", err.Error()).Warn("pipe skipped")
return nil
}
return err
}
}
// Memo is a handler that memorizes errors, so you can grab them all in the end
// instead of returning each of them.
type Memo struct {
err error
}
// Error returns the underlying error.
func (m *Memo) Error() error {
return m.err
}
// Wrap the given action, memorizing its errors.
// The resulting action will always return a nil error.
func (m *Memo) Wrap(action middleware.Action) middleware.Action {
return func(ctx *context.Context) error {
err := action(ctx)
if err == nil {
return nil
}
if pipe.IsSkip(err) {
log.WithField("reason", err.Error()).Warn("pipe skipped")
return nil
}
m.err = multierror.Append(m.err, err)
return nil
}
}