-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecution.go
More file actions
55 lines (44 loc) · 1.04 KB
/
execution.go
File metadata and controls
55 lines (44 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package commander
import (
"context"
"errors"
"log/slog"
"os/exec"
commonerrors "github.com/psyb0t/common-go/errors"
"github.com/psyb0t/ctxerrors"
)
type executionContext struct {
ctx context.Context //nolint:containedctx
cmd *exec.Cmd
name string
args []string
}
func (c *commander) newExecutionContext(
ctx context.Context,
name string,
args []string,
opts *Options,
) *executionContext {
cmd := c.createCmd(ctx, name, args, opts)
return &executionContext{
ctx: ctx,
cmd: cmd,
name: name,
args: args,
}
}
func (ec *executionContext) handleExecutionError(err error) error {
if err == nil {
slog.Debug("command completed successfully", "name", ec.name, "args", ec.args)
return nil
}
slog.Debug("command execution failed", "name", ec.name, "args", ec.args, "error", err)
if errors.Is(err, context.DeadlineExceeded) {
return commonerrors.ErrTimeout
}
if errors.Is(ec.ctx.Err(), context.DeadlineExceeded) &&
isKilledBySignal(err) {
return commonerrors.ErrTimeout
}
return ctxerrors.Wrap(err, "command failed")
}