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