diff --git a/internal/am/upload_transfer_test.go b/internal/am/upload_transfer_test.go index d50cb8512..125fe967c 100644 --- a/internal/am/upload_transfer_test.go +++ b/internal/am/upload_transfer_test.go @@ -94,12 +94,12 @@ func TestUploadTransferActivity(t *testing.T) { ).Return( 0, "", - sftp.NewAuthError( - errors.New("ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain"), - ), + &sftp.AuthError{ + Message: "ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain", + }, ) }, - wantErr: "activity error (type: UploadTransferActivity, scheduledEventID: 0, startedEventID: 0, identity: ): UploadTransferActivity: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain", + wantErr: "activity error (type: UploadTransferActivity, scheduledEventID: 0, startedEventID: 0, identity: ): UploadTransferActivity: auth: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain", wantNonRetryErr: true, }, } { diff --git a/internal/sftp/client.go b/internal/sftp/client.go index a74d5aa03..159700d41 100644 --- a/internal/sftp/client.go +++ b/internal/sftp/client.go @@ -2,23 +2,20 @@ package sftp import ( "context" + "fmt" "io" ) type AuthError struct { - err error + Message string } func (e *AuthError) Error() string { - return e.err.Error() + return fmt.Sprintf("auth: %s", e.Message) } -func (e *AuthError) Unwrap() error { - return e.err -} - -func NewAuthError(e error) *AuthError { - return &AuthError{err: e} +func NewAuthError(e error) error { + return &AuthError{Message: e.Error()} } // A Client manages the transmission of data over SFTP. diff --git a/internal/sftp/goclient_test.go b/internal/sftp/goclient_test.go index f6f0bcd3b..1f559ba9c 100644 --- a/internal/sftp/goclient_test.go +++ b/internal/sftp/goclient_test.go @@ -4,7 +4,6 @@ import ( "bufio" "bytes" "context" - "errors" "fmt" "io" "log" @@ -233,9 +232,9 @@ func TestUpload(t *testing.T) { src: strings.NewReader("Testing 1-2-3"), dest: "test.txt", }, - wantErr: sftp.NewAuthError( - errors.New("ssh: parse private key with passphrase: x509: decryption password incorrect"), - ), + wantErr: &sftp.AuthError{ + Message: "ssh: parse private key with passphrase: x509: decryption password incorrect", + }, }, { name: "Errors when the SFTP server isn't there", @@ -266,9 +265,9 @@ func TestUpload(t *testing.T) { Path: "./testdata/clientkeys/test_unk_ed25519", }, }, - wantErr: sftp.NewAuthError( - errors.New("ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain"), - ), + wantErr: &sftp.AuthError{ + Message: "ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain", + }, }, { name: "Errors when the host key is not in known_hosts", @@ -280,9 +279,9 @@ func TestUpload(t *testing.T) { Path: "./testdata/clientkeys/test_ed25519", }, }, - wantErr: sftp.NewAuthError( - errors.New("ssh: handshake failed: knownhosts: key is unknown"), - ), + wantErr: &sftp.AuthError{ + Message: "ssh: handshake failed: knownhosts: key is unknown", + }, }, { name: "Errors when the known_hosts file doesn't exist", @@ -294,9 +293,9 @@ func TestUpload(t *testing.T) { Path: "./testdata/clientkeys/test_ed25519", }, }, - wantErr: sftp.NewAuthError( - errors.New("ssh: parse known_hosts: open testdata/missing: no such file or directory"), - ), + wantErr: &sftp.AuthError{ + Message: "ssh: parse known_hosts: open testdata/missing: no such file or directory", + }, }, } { tc := tc