Skip to content

Commit 65b98be

Browse files
differentiate actual error and non-zero exit code (#112)
* differentiate actual error and non-zero exit code * handle non-zero exit code on parent level * increase timeout * SSH session * comment out SSH session * decrease timeout
1 parent 2d6bc28 commit 65b98be

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ jobs:
107107
- name: Run unit tests
108108
run: make unit-test
109109

110+
# - name: Start SSH session
111+
# uses: mxschmitt/action-tmate@v3
112+
110113
- name: Run e2e tests
111114
run: make e2e-test
112115
if: matrix.os == 'ubuntu-latest'

app/child.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package app
33
import (
44
"context"
55
"fmt"
6-
"log"
76
"log/slog"
87
"os"
98
"os/exec"
@@ -85,9 +84,22 @@ func RunChild(logger *slog.Logger, args []string) error {
8584
cmd.Stderr = os.Stderr
8685
err = cmd.Run()
8786
if err != nil {
88-
log.Printf("failed to run %s: %v", bin, err)
87+
// Check if this is a normal exit with non-zero status code
88+
if exitError, ok := err.(*exec.ExitError); ok {
89+
exitCode := exitError.ExitCode()
90+
// Log at debug level for non-zero exits (normal behavior)
91+
logger.Debug("Command exited with non-zero status", "exit_code", exitCode)
92+
// Exit with the same code as the command - don't log as error
93+
// This is normal behavior (commands can exit with any code)
94+
os.Exit(exitCode)
95+
}
96+
// This is an unexpected error (not just a non-zero exit)
97+
// Only log actual errors like "command not found" or "permission denied"
98+
logger.Error("Command execution failed", "error", err)
8999
return err
90100
}
91101

102+
// Command exited successfully
103+
logger.Debug("Command completed successfully")
92104
return nil
93105
}

app/parent.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"log/slog"
77
"os"
8+
"os/exec"
89
"os/signal"
910
"strings"
1011
"syscall"
@@ -139,9 +140,18 @@ func RunParent(ctx context.Context, logger *slog.Logger, args []string, config C
139140
logger.Debug("waiting on a child process to finish")
140141
err = cmd.Wait()
141142
if err != nil {
142-
logger.Error("Command execution failed", "error", err)
143+
// Check if this is a normal exit with non-zero status code
144+
if exitError, ok := err.(*exec.ExitError); ok {
145+
exitCode := exitError.ExitCode()
146+
// Log at debug level for non-zero exits (normal behavior)
147+
logger.Debug("Command exited with non-zero status", "exit_code", exitCode)
148+
} else {
149+
// This is an unexpected error (not just a non-zero exit)
150+
logger.Error("Command execution failed", "error", err)
151+
}
143152
return
144153
}
154+
logger.Debug("Command completed successfully")
145155
}()
146156

147157
// Wait for signal or context cancellation

0 commit comments

Comments
 (0)