mirror of https://github.com/pkg/sftp.git
rework recv debug messages to be context-added errors
This commit is contained in:
parent
d9ce3caa72
commit
c7176b3c6e
24
packet.go
24
packet.go
|
@ -313,12 +313,11 @@ func recvPacket(r io.Reader, alloc *allocator, orderID uint32) (fxp, []byte, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if n, err := io.ReadFull(r, b[:4]); err != nil {
|
if n, err := io.ReadFull(r, b[:4]); err != nil {
|
||||||
debug("recv length %d of %d bytes: err %v", n, 4, err)
|
if err == io.EOF {
|
||||||
if n > 0 {
|
return 0, nil, err
|
||||||
debug("recv length error: bytes %x", b[:n])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0, nil, err
|
return 0, nil, fmt.Errorf("error reading packet length: %d of 4: %w", n, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
length, _ := unmarshalUint32(b)
|
length, _ := unmarshalUint32(b)
|
||||||
|
@ -335,9 +334,11 @@ func recvPacket(r io.Reader, alloc *allocator, orderID uint32) (fxp, []byte, err
|
||||||
b = make([]byte, length)
|
b = make([]byte, length)
|
||||||
}
|
}
|
||||||
|
|
||||||
if n, err := io.ReadFull(r, b[:length]); err != nil {
|
n, err := io.ReadFull(r, b[:length])
|
||||||
// Log this error message _before_ we potentially override it.
|
b = b[:n]
|
||||||
debug("recv packet %d of %d bytes: err %v", n, length, err)
|
|
||||||
|
if err != nil {
|
||||||
|
debug("recv packet error: %d of %d bytes: %x", n, length, b)
|
||||||
|
|
||||||
// ReadFull only returns EOF if it has read no bytes.
|
// ReadFull only returns EOF if it has read no bytes.
|
||||||
// In this case, that means a partial packet, and thus unexpected.
|
// In this case, that means a partial packet, and thus unexpected.
|
||||||
|
@ -345,15 +346,14 @@ func recvPacket(r io.Reader, alloc *allocator, orderID uint32) (fxp, []byte, err
|
||||||
err = io.ErrUnexpectedEOF
|
err = io.ErrUnexpectedEOF
|
||||||
}
|
}
|
||||||
|
|
||||||
if n > 0 {
|
if n == 0 {
|
||||||
n := min(32, n) // limit bytes dump to 32-bytes.
|
return 0, nil, fmt.Errorf("error reading packet body: %d of %d: %w", n, length, err)
|
||||||
debug("recv packet error: bytes %x", b[:n])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0, nil, err
|
return 0, nil, fmt.Errorf("error reading packet body: %d of %d: (%s) %w", n, length, fxp(b[0]), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
typ, payload := fxp(b[0]), b[1:length]
|
typ, payload := fxp(b[0]), b[1:n]
|
||||||
|
|
||||||
if debugDumpRxPacketBytes {
|
if debugDumpRxPacketBytes {
|
||||||
debug("recv packet: %s %d bytes %x", typ, length, payload)
|
debug("recv packet: %s %d bytes %x", typ, length, payload)
|
||||||
|
|
Loading…
Reference in New Issue