1
0
mirror of https://github.com/google/gops.git synced 2024-11-24 08:22:25 +02:00

remove dependencies to github.com/pkg/errors

This commit is contained in:
Jaana Burcu Dogan 2017-03-18 17:29:31 -07:00
parent b0c5c02b30
commit 62f833fc9f

11
cmd.go
View File

@ -1,6 +1,7 @@
package main
import (
"errors"
"fmt"
"io"
"io/ioutil"
@ -12,7 +13,6 @@ import (
"github.com/google/gops/internal"
"github.com/google/gops/signal"
"github.com/pkg/errors"
)
var cmds = map[string](func(addr net.TCPAddr) error){
@ -102,10 +102,9 @@ func pprof(addr net.TCPAddr, p byte) error {
return err
}
{
out, err := cmd(addr, signal.BinaryDump)
if err != nil {
return errors.New("couldn't retrieve running binary's dump")
return fmt.Errorf("failed to read the binary: %v", err)
}
if len(out) == 0 {
return errors.New("failed to read the binary")
@ -144,14 +143,14 @@ func targetToAddr(target string) (*net.TCPAddr, error) {
var err error
addr, err := net.ResolveTCPAddr("tcp", target)
if err != nil {
return nil, errors.Wrap(err, "couldn't parse dst address")
return nil, fmt.Errorf("couldn't parse dst address: %v", err)
}
return addr, nil
}
// try to find port by pid then, connect to local
pid, err := strconv.Atoi(target)
if err != nil {
return nil, errors.Wrap(err, "couldn't parse PID")
return nil, fmt.Errorf("couldn't parse PID: %v", err)
}
port, err := internal.GetPort(pid)
addr, _ := net.ResolveTCPAddr("tcp", "127.0.0.1:"+port)
@ -161,7 +160,7 @@ func targetToAddr(target string) (*net.TCPAddr, error) {
func cmd(addr net.TCPAddr, c byte) ([]byte, error) {
conn, err := cmdLazy(addr, c)
if err != nil {
return nil, errors.Wrap(err, "couldn't get port by PID")
return nil, fmt.Errorf("couldn't get port by PID: %v", err)
}
all, err := ioutil.ReadAll(conn)