Skip to content

Commit 147c2ca

Browse files
committed
only print process logs if it exited with a non-zero exit code
1 parent b720ee3 commit 147c2ca

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

cmd/server/server.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package server
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"log/slog"
78
"net/http"
@@ -95,7 +96,11 @@ func runServer(ctx context.Context, logger *slog.Logger, argsToPass []string) er
9596
go func() {
9697
defer close(processExitCh)
9798
if err := process.Wait(); err != nil {
98-
processExitCh <- xerrors.Errorf("========\n%s\n========\n: %w", strings.TrimSpace(process.ReadScreen()), err)
99+
if errors.Is(err, termexec.ErrNonZeroExitCode) {
100+
processExitCh <- xerrors.Errorf("========\n%s\n========\n: %w", strings.TrimSpace(process.ReadScreen()), err)
101+
} else {
102+
processExitCh <- xerrors.Errorf("failed to wait for process: %w", err)
103+
}
99104
}
100105
if err := srv.Stop(ctx); err != nil {
101106
logger.Error("Failed to stop server", "error", err)

lib/termexec/termexec.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,16 @@ func (p *Process) Close(logger *slog.Logger, timeout time.Duration) error {
111111
return exitErr
112112
}
113113

114+
var ErrNonZeroExitCode = xerrors.New("non-zero exit code")
115+
114116
// Wait waits for the process to exit.
115117
func (p *Process) Wait() error {
116118
state, err := p.execCmd.Process.Wait()
117119
if err != nil {
118120
return xerrors.Errorf("process exited with error: %w", err)
119121
}
120122
if state.ExitCode() != 0 {
121-
return xerrors.Errorf("non-zero exit code: %d", state.ExitCode())
123+
return ErrNonZeroExitCode
122124
}
123125
return nil
124126
}

0 commit comments

Comments
 (0)