From 1bb67240205327be2e46744e64a260a0c4eb3ab7 Mon Sep 17 00:00:00 2001 From: YenForYang Date: Sun, 12 Sep 2021 20:38:08 -0500 Subject: [PATCH] Remove xerrors dependency (#600) * Remove xerrors dependency * Update main.go --- cmd/torrent/main.go | 22 +++++++++++----------- mse/cmd/mse/main.go | 11 +++++------ 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/cmd/torrent/main.go b/cmd/torrent/main.go index c24310bd..95b99e5c 100644 --- a/cmd/torrent/main.go +++ b/cmd/torrent/main.go @@ -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 { diff --git a/mse/cmd/mse/main.go b/mse/cmd/mse/main.go index 9485fc2a..756f07e6 100644 --- a/mse/cmd/mse/main.go +++ b/mse/cmd/mse/main.go @@ -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) {