From 271a94e0c7eac348197770e08490f714fbe1f533 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Sun, 3 Dec 2023 18:32:14 -0500 Subject: [PATCH] engine: resources: Improve logging on resource errors When a subcommand errors, it's helpful to see what it was. --- engine/resources/exec.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/engine/resources/exec.go b/engine/resources/exec.go index f880d4f79..dab50e353 100644 --- a/engine/resources/exec.go +++ b/engine/resources/exec.go @@ -202,6 +202,7 @@ func (obj *ExecRes) Watch(ctx context.Context) error { ioChan := make(chan *cmdOutput) defer obj.wg.Wait() + var watchCmd *exec.Cmd if obj.WatchCmd != "" { var cmdName string var cmdArgs []string @@ -227,6 +228,7 @@ func (obj *ExecRes) Watch(ctx context.Context) error { Setpgid: true, Pgid: 0, } + watchCmd = cmd // store for errors // if we have a user and group, use them var err error @@ -268,6 +270,7 @@ func (obj *ExecRes) Watch(ctx context.Context) error { return errwrap.Wrapf(err, "unexpected watchcmd exit status of zero") } + obj.init.Logf("watchcmd: %s", strings.Join(watchCmd.Args, " ")) obj.init.Logf("watchcmd exited with: %d", exitStatus) return errwrap.Wrapf(err, "watchcmd errored") } @@ -354,6 +357,7 @@ func (obj *ExecRes) CheckApply(ctx context.Context, apply bool) (bool, error) { return false, errwrap.Wrapf(err, "unexpected ifcmd exit status of zero") } + obj.init.Logf("ifcmd: %s", strings.Join(cmd.Args, " ")) obj.init.Logf("ifcmd exited with: %d", exitStatus) if s := out.String(); s == "" { obj.init.Logf("ifcmd out empty!") @@ -569,6 +573,7 @@ func (obj *ExecRes) CheckApply(ctx context.Context, apply bool) (bool, error) { return false, errwrap.Wrapf(err, "unexpected donecmd exit status of zero") } + obj.init.Logf("donecmd: %s", strings.Join(cmd.Args, " ")) if s := out.String(); s == "" { obj.init.Logf("donecmd exit status %d", exitStatus) } else {