Skip to content

Commit

Permalink
fix: lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
caarlos0 committed Dec 18, 2024
1 parent 88cbc96 commit 16c942c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions pty.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"bytes"
"context"
"fmt"
"io"
"os"
"os/exec"
Expand All @@ -15,7 +16,7 @@ import (
func executeCommand(config Config) (string, error) {
args, err := shellwords.Parse(config.Execute)
if err != nil {
return "", err //nolint: wrapcheck
return "", fmt.Errorf("could not execute: %w", err)
}

ctx, cancel := context.WithTimeout(context.Background(), config.ExecuteTimeout)
Expand All @@ -29,13 +30,13 @@ func executeCommand(config Config) (string, error) {

pty, err := xpty.NewPty(width, height)
if err != nil {
return "", err
return "", fmt.Errorf("could not execute: %w", err)
}
defer func() { _ = pty.Close() }()

cmd := exec.CommandContext(ctx, args[0], args[1:]...) //nolint: gosec
if err := pty.Start(cmd); err != nil {
return "", err
return "", fmt.Errorf("could not execute: %w", err)
}

var out bytes.Buffer
Expand All @@ -46,7 +47,7 @@ func executeCommand(config Config) (string, error) {
}()

if err := xpty.WaitProcess(ctx, cmd); err != nil {
return errorOut.String(), err //nolint: wrapcheck
return errorOut.String(), fmt.Errorf("could not execute: %w", err)
}
return out.String(), nil
}

0 comments on commit 16c942c

Please sign in to comment.