Skip to content

Commit

Permalink
Log target and command on failure in connection manager (#271)
Browse files Browse the repository at this point in the history
Co-authored-by: Oliver Geiselhardt-Herms <[email protected]>
  • Loading branch information
taktv6 and Oliver Geiselhardt-Herms authored Dec 18, 2024
1 parent d36550f commit 6cdaa0c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions pkg/connector/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package connector

import (
"bytes"
"fmt"
"net"
"sync"
"time"
Expand Down Expand Up @@ -31,12 +32,12 @@ func (c *SSHConnection) RunCommand(cmd string) ([]byte, error) {
c.lastUsed = time.Now()

if c.client == nil {
return nil, errors.New("not connected")
return nil, errors.New(fmt.Sprintf("not connected with %s", c.conn.RemoteAddr().String()))
}

session, err := c.client.NewSession()
if err != nil {
return nil, errors.Wrap(err, "could not open session")
return nil, errors.Wrapf(err, "could not open session with %s", c.conn.RemoteAddr().String())
}
defer session.Close()

Expand All @@ -45,7 +46,7 @@ func (c *SSHConnection) RunCommand(cmd string) ([]byte, error) {

err = session.Run(cmd)
if err != nil {
return nil, errors.Wrap(err, "could not run command")
return nil, errors.Wrapf(err, "could not run command %q on %s", cmd, c.conn.RemoteAddr().String())
}

return b.Bytes(), nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/connector/connection_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"sync"
"time"

log "github.com/sirupsen/logrus"

"github.com/pkg/errors"
"golang.org/x/crypto/ssh"

log "github.com/sirupsen/logrus"
)

const timeoutInSeconds = 5
Expand Down

0 comments on commit 6cdaa0c

Please sign in to comment.