Skip to content

feat: return error object from executed command #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type ExecTask struct {
type ExecResult struct {
Stdout string
Stderr string
Error error
ExitCode int
Cancelled bool
}
Expand Down Expand Up @@ -187,6 +188,7 @@ func (et ExecTask) Execute(ctx context.Context) (ExecResult, error) {
return ExecResult{
Stdout: stdoutBuff.String(),
Stderr: stderrBuff.String(),
Error: execErr,
ExitCode: exitCode,
Cancelled: ctx.Err() == context.Canceled,
}, ctx.Err()
Expand Down
15 changes: 15 additions & 0 deletions exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ func TestExec_ReturnErrorForUnknownCommand(t *testing.T) {
if res.Cancelled != false {
t.Fatalf("want not cancelled, but got true")
}
if res.Error != nil {
t.Fatalf("want nil error, but got %s", err.Error())
}
if res.ExitCode != 0 {
t.Fatalf("want exit code 0, but got %d", res.ExitCode)
}
Expand Down Expand Up @@ -56,6 +59,10 @@ func TestExec_ContextAlreadyCancelled(t *testing.T) {
t.Fatalf("want cancelled, but got false")
}

if res.Error == nil {
t.Fatalf("want non-nil error, but got nil")
}

if res.ExitCode != -1 {
t.Fatalf("want exit code -1, but got %d", res.ExitCode)
}
Expand All @@ -81,6 +88,10 @@ func TestExec_ContextCancelledDuringExecution(t *testing.T) {
t.Fatalf("want cancelled, but got false")
}

if res.Error == nil {
t.Fatalf("want non-nil error, but got nil")
}

if res.ExitCode != -1 {
t.Fatalf("want exit code -1, but got %d", res.ExitCode)
}
Expand All @@ -106,6 +117,10 @@ func TestExecShell_ContextCancelledDuringExecution(t *testing.T) {
t.Fatalf("want cancelled, but got false")
}

if res.Error == nil {
t.Fatalf("want non-nil error, but got nil")
}

if res.ExitCode != -1 {
t.Fatalf("want exit code -1, but got %d", res.ExitCode)
}
Expand Down