add error message to failing commands *facepalm*

This commit is contained in:
Shane C 2024-09-19 11:03:10 -04:00
parent 0466a423ec
commit 5827a7434b
Signed by: shane
GPG key ID: E46B5FEA35B22FF9

View file

@ -2,9 +2,11 @@ package linux
import (
"bufio"
"bytes"
"errors"
"fmt"
"golang.org/x/sys/unix"
"io"
"os"
"os/exec"
"os/signal"
@ -192,7 +194,11 @@ func (cmd *LinuxCommand) Run() error {
}
exitInfo.HasSucceeded = false
exitInfo.ExitCode = exitErr.ExitCode()
exitInfo.Error = exitErr.String()
var stdoutData bytes.Buffer
if _, err := io.Copy(&stdoutData, cmd.stdout); err != nil {
return err
}
exitInfo.Error = stdoutData.String()
err := h.(func(data EventExitData) error)(*exitInfo)
if err != nil {
return fmt.Errorf("%s: %w", ErrRunningEvt.Error(), err)
@ -206,7 +212,11 @@ func (cmd *LinuxCommand) Run() error {
}
exitInfo.HasSucceeded = false
exitInfo.ExitCode = exitErr.ExitCode()
exitInfo.Error = exitErr.String()
var stdoutData bytes.Buffer
if _, err := io.Copy(&stdoutData, cmd.stdout); err != nil {
return err
}
exitInfo.Error = stdoutData.String()
err := h.(func(data EventExitData) error)(*exitInfo)
if err != nil {
return fmt.Errorf("%s: %w", ErrRunningEvt.Error(), err)