Skip to content

Commit

Permalink
engine: resources: Improve logging on resource errors
Browse files Browse the repository at this point in the history
When a subcommand errors, it's helpful to see what it was.
  • Loading branch information
purpleidea committed Dec 4, 2023
1 parent c3f34db commit 271a94e
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions engine/resources/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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!")
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 271a94e

Please sign in to comment.