@@ -3,12 +3,13 @@ package ssh
3
3
import (
4
4
"bufio"
5
5
"bytes"
6
+ "errors"
7
+ "fmt"
6
8
"os"
7
9
"os/exec"
8
10
"strconv"
9
11
"strings"
10
12
11
- "github.com/pkg/errors"
12
13
"github.com/sirupsen/logrus"
13
14
)
14
15
@@ -54,7 +55,7 @@ func ExitMaster(host string, port int, c *SSHConfig) error {
54
55
logrus .Debugf ("executing ssh for exiting the master: %s %v" , cmd .Path , cmd .Args )
55
56
out , err := cmd .CombinedOutput ()
56
57
if err != nil {
57
- return errors . Wrapf ( err , "failed to execute `%s -O exit -p %d %s`, out=%q" , c .Binary (), port , host , string (out ))
58
+ return fmt . Errorf ( "failed to execute `%s -O exit -p %d %s`, out=%q: %w " , c .Binary (), port , host , string (out ), err )
58
59
}
59
60
return nil
60
61
}
@@ -65,17 +66,17 @@ func ParseScriptInterpreter(script string) (string, error) {
65
66
r := bufio .NewReader (strings .NewReader (script ))
66
67
firstLine , partial , err := r .ReadLine ()
67
68
if err != nil {
68
- return "" , errors . Wrapf ( err , "cannot determine interpreter from script %q" , script )
69
+ return "" , fmt . Errorf ( "cannot determine interpreter from script %q: %w " , script , err )
69
70
}
70
71
if partial {
71
- return "" , errors .Errorf ("cannot determine interpreter from script %q: cannot read the first line" , script )
72
+ return "" , fmt .Errorf ("cannot determine interpreter from script %q: cannot read the first line" , script )
72
73
}
73
74
if ! strings .HasPrefix (string (firstLine ), "#!" ) {
74
- return "" , errors .Errorf ("cannot determine interpreter from script %q: the first line lacks `#!`" , script )
75
+ return "" , fmt .Errorf ("cannot determine interpreter from script %q: the first line lacks `#!`" , script )
75
76
}
76
77
interp := strings .TrimPrefix (string (firstLine ), "#!" )
77
78
if interp == "" {
78
- return "" , errors .Errorf ("cannot determine interpreter from script %q: empty?" , script )
79
+ return "" , fmt .Errorf ("cannot determine interpreter from script %q: empty?" , script )
79
80
}
80
81
return interp , nil
81
82
}
@@ -105,8 +106,7 @@ func ExecuteScript(host string, port int, c *SSHConfig, script, scriptName strin
105
106
logrus .Debugf ("executing ssh for script %q: %s %v" , scriptName , sshCmd .Path , sshCmd .Args )
106
107
out , err := sshCmd .Output ()
107
108
if err != nil {
108
- return string (out ), stderr .String (), errors .Wrapf (err , "failed to execute script %q: stdout=%q, stderr=%q" ,
109
- scriptName , string (out ), stderr .String ())
109
+ return string (out ), stderr .String (), fmt .Errorf ("failed to execute script %q: stdout=%q, stderr=%q: %w" , scriptName , string (out ), stderr .String (), err )
110
110
}
111
111
return string (out ), stderr .String (), nil
112
112
}
0 commit comments