Remove xerrors dependency (#600)
* Remove xerrors dependency * Update main.go
This commit is contained in:
parent
3b4d4a64ff
commit
1bb6724020
|
@ -2,6 +2,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"expvar"
|
||||
"fmt"
|
||||
"io"
|
||||
|
@ -22,7 +23,6 @@ import (
|
|||
"github.com/anacrolix/torrent/version"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/dustin/go-humanize"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/anacrolix/log"
|
||||
|
||||
|
@ -100,23 +100,23 @@ func addTorrents(client *torrent.Client) error {
|
|||
if strings.HasPrefix(arg, "magnet:") {
|
||||
t, err := client.AddMagnet(arg)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("error adding magnet: %w", err)
|
||||
return nil, fmt.Errorf("error adding magnet: %w", err)
|
||||
}
|
||||
return t, nil
|
||||
} else if strings.HasPrefix(arg, "http://") || strings.HasPrefix(arg, "https://") {
|
||||
response, err := http.Get(arg)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("Error downloading torrent file: %s", err)
|
||||
return nil, fmt.Errorf("Error downloading torrent file: %s", err)
|
||||
}
|
||||
|
||||
metaInfo, err := metainfo.Load(response.Body)
|
||||
defer response.Body.Close()
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("error loading torrent file %q: %s\n", arg, err)
|
||||
return nil, fmt.Errorf("error loading torrent file %q: %s\n", arg, err)
|
||||
}
|
||||
t, err := client.AddTorrent(metaInfo)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("adding torrent: %w", err)
|
||||
return nil, fmt.Errorf("adding torrent: %w", err)
|
||||
}
|
||||
return t, nil
|
||||
} else if strings.HasPrefix(arg, "infohash:") {
|
||||
|
@ -125,17 +125,17 @@ func addTorrents(client *torrent.Client) error {
|
|||
} else {
|
||||
metaInfo, err := metainfo.LoadFromFile(arg)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("error loading torrent file %q: %s\n", arg, err)
|
||||
return nil, fmt.Errorf("error loading torrent file %q: %s\n", arg, err)
|
||||
}
|
||||
t, err := client.AddTorrent(metaInfo)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("adding torrent: %w", err)
|
||||
return nil, fmt.Errorf("adding torrent: %w", err)
|
||||
}
|
||||
return t, nil
|
||||
}
|
||||
}()
|
||||
if err != nil {
|
||||
return xerrors.Errorf("adding torrent for %q: %w", arg, err)
|
||||
return fmt.Errorf("adding torrent for %q: %w", arg, err)
|
||||
}
|
||||
if flags.Progress {
|
||||
torrentBar(t, flags.PieceStates)
|
||||
|
@ -302,7 +302,7 @@ func downloadErr() error {
|
|||
if flags.PackedBlocklist != "" {
|
||||
blocklist, err := iplist.MMapPackedFile(flags.PackedBlocklist)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("loading blocklist: %v", err)
|
||||
return fmt.Errorf("loading blocklist: %v", err)
|
||||
}
|
||||
defer blocklist.Close()
|
||||
clientConfig.IPBlocklist = blocklist
|
||||
|
@ -331,7 +331,7 @@ func downloadErr() error {
|
|||
|
||||
client, err := torrent.NewClient(clientConfig)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("creating client: %v", err)
|
||||
return fmt.Errorf("creating client: %v", err)
|
||||
}
|
||||
var clientClose sync.Once //In certain situations, close was being called more than once.
|
||||
defer clientClose.Do(client.Close)
|
||||
|
@ -354,7 +354,7 @@ func downloadErr() error {
|
|||
if client.WaitAll() {
|
||||
log.Print("downloaded ALL the torrents")
|
||||
} else {
|
||||
return xerrors.New("y u no complete torrents?!")
|
||||
return errors.New("y u no complete torrents?!")
|
||||
}
|
||||
if flags.Seed {
|
||||
if len(client.Torrents()) == 0 {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
|
@ -8,8 +9,6 @@ import (
|
|||
"sync"
|
||||
|
||||
"github.com/alexflint/go-arg"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/anacrolix/torrent/mse"
|
||||
)
|
||||
|
||||
|
@ -41,25 +40,25 @@ func mainErr() error {
|
|||
if args.Dial != nil {
|
||||
cn, err := net.Dial(args.Dial.Network, args.Dial.Address)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("dialing: %w", err)
|
||||
return fmt.Errorf("dialing: %w", err)
|
||||
}
|
||||
defer cn.Close()
|
||||
rw, _, err := mse.InitiateHandshake(cn, []byte(args.Dial.SecretKey), args.Dial.InitialPayload, args.CryptoMethod)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("initiating handshake: %w", err)
|
||||
return fmt.Errorf("initiating handshake: %w", err)
|
||||
}
|
||||
doStreaming(rw)
|
||||
}
|
||||
if args.Listen != nil {
|
||||
l, err := net.Listen(args.Listen.Network, args.Listen.Address)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("listening: %w", err)
|
||||
return fmt.Errorf("listening: %w", err)
|
||||
}
|
||||
defer l.Close()
|
||||
cn, err := l.Accept()
|
||||
l.Close()
|
||||
if err != nil {
|
||||
return xerrors.Errorf("accepting: %w", err)
|
||||
return fmt.Errorf("accepting: %w", err)
|
||||
}
|
||||
defer cn.Close()
|
||||
rw, _, err := mse.ReceiveHandshake(cn, func(f func([]byte) bool) {
|
||||
|
|
Loading…
Reference in New Issue