@@ -3,12 +3,13 @@ package ssh
33import (
44 "bufio"
55 "bytes"
6+ "errors"
7+ "fmt"
68 "os"
79 "os/exec"
810 "strconv"
911 "strings"
1012
11- "github.com/pkg/errors"
1213 "github.com/sirupsen/logrus"
1314)
1415
@@ -54,7 +55,7 @@ func ExitMaster(host string, port int, c *SSHConfig) error {
5455 logrus .Debugf ("executing ssh for exiting the master: %s %v" , cmd .Path , cmd .Args )
5556 out , err := cmd .CombinedOutput ()
5657 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 )
5859 }
5960 return nil
6061}
@@ -65,17 +66,17 @@ func ParseScriptInterpreter(script string) (string, error) {
6566 r := bufio .NewReader (strings .NewReader (script ))
6667 firstLine , partial , err := r .ReadLine ()
6768 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 )
6970 }
7071 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 )
7273 }
7374 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 )
7576 }
7677 interp := strings .TrimPrefix (string (firstLine ), "#!" )
7778 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 )
7980 }
8081 return interp , nil
8182}
@@ -105,8 +106,7 @@ func ExecuteScript(host string, port int, c *SSHConfig, script, scriptName strin
105106 logrus .Debugf ("executing ssh for script %q: %s %v" , scriptName , sshCmd .Path , sshCmd .Args )
106107 out , err := sshCmd .Output ()
107108 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 )
110110 }
111111 return string (out ), stderr .String (), nil
112112}
0 commit comments