You've already forked torrent-client
mirror of
https://github.com/veggiedefender/torrent-client.git
synced 2025-11-06 09:29:16 +02:00
Only use fmt.Errorf
This commit is contained in:
@@ -2,7 +2,7 @@ package handshake
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
@@ -45,7 +45,7 @@ func Read(r *bufio.Reader) (*Handshake, error) {
|
||||
pstrlen := int(lengthBuf[0])
|
||||
|
||||
if pstrlen == 0 {
|
||||
err := errors.New("pstrlen cannot be 0")
|
||||
err := fmt.Errorf("pstrlen cannot be 0")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package message
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
@@ -52,7 +51,7 @@ func ParsePiece(index int, buf []byte, msg *Message) (int, error) {
|
||||
return 0, fmt.Errorf("Expected PIECE (ID %d), got ID %d", MsgPiece, msg.ID)
|
||||
}
|
||||
if len(msg.Payload) < 8 {
|
||||
return 0, errors.New("Payload too short")
|
||||
return 0, fmt.Errorf("Payload too short. %d < 8", len(msg.Payload))
|
||||
}
|
||||
parsedIndex := int(binary.BigEndian.Uint32(msg.Payload[0:4]))
|
||||
if parsedIndex != index {
|
||||
|
||||
@@ -2,7 +2,7 @@ package torrentfile
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -21,7 +21,7 @@ func parsePeers(peersBin string) ([]p2p.Peer, error) {
|
||||
const peerSize = 6 // 4 for IP, 2 for port
|
||||
numPeers := len(peersBin) / peerSize
|
||||
if len(peersBin)%peerSize != 0 {
|
||||
err := errors.New("Received malformed peers")
|
||||
err := fmt.Errorf("Received malformed peers")
|
||||
return nil, err
|
||||
}
|
||||
peers := make([]p2p.Peer, numPeers)
|
||||
|
||||
Reference in New Issue
Block a user