Skip to content

Commit

Permalink
Fix not showing error log when helm command failed (#136)
Browse files Browse the repository at this point in the history
Close #115
  • Loading branch information
jlandowner committed Aug 16, 2024
1 parent 989b4bb commit 72a8a30
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/k0kubun/pp/v3 v3.2.0 // indirect
github.com/m-mizutani/clog v0.0.7 // indirect
github.com/m-mizutani/goerr v0.1.11 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,18 @@ github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8Hm
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/k0kubun/pp/v3 v3.2.0 h1:h33hNTZ9nVFNP3u2Fsgz8JXiF5JINoZfFq4SvKJwNcs=
github.com/k0kubun/pp/v3 v3.2.0/go.mod h1:ODtJQbQcIRfAD3N+theGCV1m/CBxweERz2dapdz1EwA=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/m-mizutani/clog v0.0.7 h1:yZstkXZ44gM1MqXeO30e0E0SCzoiKmO5uUDcmBfhha8=
github.com/m-mizutani/clog v0.0.7/go.mod h1:7/axE2EjIqJ3X7gA+sNMnyvtEw4Qsr9u5Z+rWlUsW7U=
github.com/m-mizutani/goerr v0.1.11 h1:noTEk8jNOVl/ST/Qfn0q7lMA13/ygzyl1PxaD4hHti4=
github.com/m-mizutani/goerr v0.1.11/go.mod h1:64HHjaK/ZjCy3VMaqrcZvinirVZkIBUxU21ml3WgMU4=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
Expand Down
11 changes: 7 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"sync"

"github.com/fatih/color"
"github.com/m-mizutani/clog"
"github.com/spf13/cobra"
"golang.org/x/sync/errgroup"

Expand Down Expand Up @@ -202,14 +203,16 @@ func main() {
}

func slogHandler() slog.Handler {
return slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{
Level: func() slog.Leveler {
return clog.New(
clog.WithColor(true),
clog.WithSource(true),
clog.WithLevel(func() slog.Leveler {
if o.Debug() {
return slog.LevelDebug
}
return slog.LevelInfo
}(),
})
}()),
)
}

func loadSnapshotConfig(file string, cfg *v1alpha1.SnapshotConfig) error {
Expand Down
2 changes: 1 addition & 1 deletion pkg/charts/snap.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (o *ChartSnapshotter) Snap(ctx context.Context) (result *SnapshotResult, er
if o.FailHelmError {
return nil, fmt.Errorf("'helm template' command failed: %w: %s", err, out)
} else {
log().Debug("helm template command failed", "err", err, "output", string(out))
log().Error("helm command failed but snapshot it anyway. use --fail-helm-error if you want error exit code", "err", err, "output", string(out))
}
}
log().Debug("helm template output", "output", string(out), "path", o.SnapshotFile)
Expand Down

0 comments on commit 72a8a30

Please sign in to comment.