mirror of https://github.com/pkg/sftp.git
statusFromError: improve support for error wrapping
This commit is contained in:
parent
707787e8bc
commit
08880975fb
12
server.go
12
server.go
|
@ -615,13 +615,15 @@ func statusFromError(id uint32, err error) *sshFxpStatusPacket {
|
|||
return ret
|
||||
}
|
||||
|
||||
switch e := err.(type) {
|
||||
case fxerr:
|
||||
ret.StatusError.Code = uint32(e)
|
||||
default:
|
||||
if e == io.EOF {
|
||||
if errors.Is(err, io.EOF) {
|
||||
ret.StatusError.Code = sshFxEOF
|
||||
return ret
|
||||
}
|
||||
|
||||
var e fxerr
|
||||
if errors.As(err, &e) {
|
||||
ret.StatusError.Code = uint32(e)
|
||||
return ret
|
||||
}
|
||||
|
||||
return ret
|
||||
|
|
|
@ -2,6 +2,7 @@ package sftp
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"syscall"
|
||||
"testing"
|
||||
|
@ -19,6 +20,8 @@ func TestErrFxCode(t *testing.T) {
|
|||
{err: syscall.ENOENT, fx: ErrSSHFxNoSuchFile},
|
||||
{err: syscall.EPERM, fx: ErrSSHFxPermissionDenied},
|
||||
{err: io.EOF, fx: ErrSSHFxEOF},
|
||||
{err: fmt.Errorf("wrapped permission denied error: %w", ErrSSHFxPermissionDenied), fx: ErrSSHFxPermissionDenied},
|
||||
{err: fmt.Errorf("wrapped op unsupported error: %w", ErrSSHFxOpUnsupported), fx: ErrSSHFxOpUnsupported},
|
||||
}
|
||||
for _, tt := range table {
|
||||
statusErr := statusFromError(1, tt.err).StatusError
|
||||
|
|
Loading…
Reference in New Issue