Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch from juju/errors to pkg/errors #1210

Merged
merged 4 commits into from
Aug 24, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@
[[constraint]]
name = "github.com/etcd-io/gofail"
branch = "master"

[[constraint]]
name = "github.com/pkg/errors"
version = "0.8.0"
15 changes: 8 additions & 7 deletions cmd/pd-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ package main
import (
"context"
"flag"
"fmt"
"os"
"os/signal"
"syscall"

"github.com/grpc-ecosystem/go-grpc-prometheus"
"github.com/juju/errors"
"github.com/pingcap/pd/pkg/logutil"
"github.com/pingcap/pd/pkg/metricutil"
"github.com/pingcap/pd/server"
"github.com/pingcap/pd/server/api"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"

// Register schedulers.
Expand All @@ -50,12 +51,12 @@ func main() {
case flag.ErrHelp:
os.Exit(0)
default:
log.Fatalf("parse cmd flags error: %s\n", errors.ErrorStack(err))
log.Fatalf("parse cmd flags error: %s\n", fmt.Sprintf("%+v", err))
}

err = logutil.InitLogger(&cfg.Log)
if err != nil {
log.Fatalf("initialize logger error: %s\n", errors.ErrorStack(err))
log.Fatalf("initialize logger error: %s\n", fmt.Sprintf("%+v", err))
}

server.LogPDInfo()
Expand All @@ -71,15 +72,15 @@ func main() {

err = server.PrepareJoinCluster(cfg)
if err != nil {
log.Fatal("join error ", errors.ErrorStack(err))
log.Fatal("join error ", fmt.Sprintf("%+v", err))
}
svr, err := server.CreateServer(cfg, api.NewHandler)
if err != nil {
log.Fatalf("create server failed: %v", errors.ErrorStack(err))
log.Fatalf("create server failed: %v", fmt.Sprintf("%+v", err))
}

if err = server.InitHTTPClient(svr); err != nil {
log.Fatalf("initial http client for api handler failed: %v", errors.ErrorStack(err))
log.Fatalf("initial http client for api handler failed: %v", fmt.Sprintf("%+v", err))
}

sc := make(chan os.Signal, 1)
Expand All @@ -97,7 +98,7 @@ func main() {
}()

if err := svr.Run(ctx); err != nil {
log.Fatalf("run server failed: %v", errors.ErrorStack(err))
log.Fatalf("run server failed: %v", fmt.Sprintf("%+v", err))
}

<-ctx.Done()
Expand Down
2 changes: 1 addition & 1 deletion cmd/pd-tso-bench/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
"syscall"
"time"

"github.com/juju/errors"
"github.com/pingcap/pd/pd-client"
"github.com/pkg/errors"
)

var (
Expand Down
48 changes: 24 additions & 24 deletions pd-client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import (
"sync"
"time"

"github.com/juju/errors"
"github.com/opentracing/opentracing-go"
"github.com/pingcap/kvproto/pkg/metapb"
"github.com/pingcap/kvproto/pkg/pdpb"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"golang.org/x/net/context"
"google.golang.org/grpc"
Expand Down Expand Up @@ -131,10 +131,10 @@ func NewClient(pdAddrs []string, security SecurityOption) (Client, error) {
c.connMu.clientConns = make(map[string]*grpc.ClientConn)

if err := c.initClusterID(); err != nil {
return nil, errors.Trace(err)
return nil, errors.WithStack(err)
}
if err := c.updateLeader(); err != nil {
return nil, errors.Trace(err)
return nil, errors.WithStack(err)
}
log.Infof("[pd] init cluster id %v", c.clusterID)

Expand Down Expand Up @@ -171,7 +171,7 @@ func (c *client) initClusterID() error {
time.Sleep(time.Second)
}

return errors.Trace(errFailInitClusterID)
return errors.WithStack(errFailInitClusterID)
}

func (c *client) updateLeader() error {
Expand All @@ -182,14 +182,14 @@ func (c *client) updateLeader() error {
if err != nil || members.GetLeader() == nil || len(members.GetLeader().GetClientUrls()) == 0 {
select {
case <-c.ctx.Done():
return errors.Trace(err)
return errors.WithStack(err)
default:
continue
}
}
c.updateURLs(members.GetMembers())
if err = c.switchLeader(members.GetLeader().GetClientUrls()); err != nil {
return errors.Trace(err)
return errors.WithStack(err)
}
return nil
}
Expand All @@ -199,11 +199,11 @@ func (c *client) updateLeader() error {
func (c *client) getMembers(ctx context.Context, url string) (*pdpb.GetMembersResponse, error) {
cc, err := c.getOrCreateGRPCConn(url)
if err != nil {
return nil, errors.Trace(err)
return nil, errors.WithStack(err)
}
members, err := pdpb.NewPDClient(cc).GetMembers(ctx, &pdpb.GetMembersRequest{})
if err != nil {
return nil, errors.Trace(err)
return nil, errors.WithStack(err)
}
return members, nil
}
Expand All @@ -222,7 +222,7 @@ func (c *client) switchLeader(addrs []string) error {

log.Infof("[pd] leader switches to: %v, previous: %v", addr, oldLeader)
if _, err := c.getOrCreateGRPCConn(addr); err != nil {
return errors.Trace(err)
return errors.WithStack(err)
}

c.connMu.Lock()
Expand Down Expand Up @@ -273,11 +273,11 @@ func (c *client) getOrCreateGRPCConn(addr string) (*grpc.ClientConn, error) {
}
u, err := url.Parse(addr)
if err != nil {
return nil, errors.Trace(err)
return nil, errors.WithStack(err)
}
cc, err := grpc.Dial(u.Host, opt)
if err != nil {
return nil, errors.Trace(err)
return nil, errors.WithStack(err)
}
c.connMu.Lock()
defer c.connMu.Unlock()
Expand Down Expand Up @@ -440,20 +440,20 @@ func (c *client) processTSORequests(stream pdpb.PD_TsoClient, requests []*tsoReq

if err := stream.Send(req); err != nil {
c.finishTSORequest(requests, 0, 0, err)
return errors.Trace(err)
return errors.WithStack(err)
}
resp, err := stream.Recv()
if err != nil {
c.finishTSORequest(requests, 0, 0, errors.Trace(err))
return errors.Trace(err)
c.finishTSORequest(requests, 0, 0, errors.WithStack(err))
return errors.WithStack(err)
}
requestDuration.WithLabelValues("tso").Observe(time.Since(start).Seconds())
if err == nil && resp.GetCount() != uint32(len(requests)) {
err = errTSOLength
}
if err != nil {
c.finishTSORequest(requests, 0, 0, errors.Trace(err))
return errors.Trace(err)
c.finishTSORequest(requests, 0, 0, errors.WithStack(err))
return errors.WithStack(err)
}

physical, logical := resp.GetTimestamp().GetPhysical(), resp.GetTimestamp().GetLogical()
Expand All @@ -477,7 +477,7 @@ func (c *client) revokeTSORequest(err error) {
n := len(c.tsoRequests)
for i := 0; i < n; i++ {
req := <-c.tsoRequests
req.done <- errors.Trace(err)
req.done <- errors.WithStack(err)
}
}

Expand Down Expand Up @@ -564,13 +564,13 @@ func (req *tsoRequest) Wait() (int64, int64, error) {
defer tsoReqPool.Put(req)
if err != nil {
cmdFailedDuration.WithLabelValues("tso").Observe(time.Since(req.start).Seconds())
return 0, 0, errors.Trace(err)
return 0, 0, errors.WithStack(err)
}
physical, logical := req.physical, req.logical
cmdDuration.WithLabelValues("tso").Observe(time.Since(req.start).Seconds())
return physical, logical, err
case <-req.ctx.Done():
return 0, 0, errors.Trace(req.ctx.Err())
return 0, 0, errors.WithStack(req.ctx.Err())
}
}

Expand All @@ -597,7 +597,7 @@ func (c *client) GetRegion(ctx context.Context, key []byte) (*metapb.Region, *me
if err != nil {
cmdFailedDuration.WithLabelValues("get_region").Observe(time.Since(start).Seconds())
c.ScheduleCheckLeader()
return nil, nil, errors.Trace(err)
return nil, nil, errors.WithStack(err)
}
return resp.GetRegion(), resp.GetLeader(), nil
}
Expand All @@ -620,7 +620,7 @@ func (c *client) GetPrevRegion(ctx context.Context, key []byte) (*metapb.Region,
if err != nil {
cmdFailedDuration.WithLabelValues("get_prev_region").Observe(time.Since(start).Seconds())
c.ScheduleCheckLeader()
return nil, nil, errors.Trace(err)
return nil, nil, errors.WithStack(err)
}
return resp.GetRegion(), resp.GetLeader(), nil
}
Expand All @@ -643,7 +643,7 @@ func (c *client) GetRegionByID(ctx context.Context, regionID uint64) (*metapb.Re
if err != nil {
cmdFailedDuration.WithLabelValues("get_region_byid").Observe(time.Since(start).Seconds())
c.ScheduleCheckLeader()
return nil, nil, errors.Trace(err)
return nil, nil, errors.WithStack(err)
}
return resp.GetRegion(), resp.GetLeader(), nil
}
Expand All @@ -666,7 +666,7 @@ func (c *client) GetStore(ctx context.Context, storeID uint64) (*metapb.Store, e
if err != nil {
cmdFailedDuration.WithLabelValues("get_store").Observe(time.Since(start).Seconds())
c.ScheduleCheckLeader()
return nil, errors.Trace(err)
return nil, errors.WithStack(err)
}
store := resp.GetStore()
if store == nil {
Expand Down Expand Up @@ -696,7 +696,7 @@ func (c *client) UpdateGCSafePoint(ctx context.Context, safePoint uint64) (uint6
if err != nil {
cmdFailedDuration.WithLabelValues("update_gc_safe_point").Observe(time.Since(start).Seconds())
c.ScheduleCheckLeader()
return 0, errors.Trace(err)
return 0, errors.WithStack(err)
}
return resp.GetNewSafePoint(), nil
}
Expand Down
4 changes: 2 additions & 2 deletions pdctl/command/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"os"

"github.com/coreos/etcd/pkg/transport"
"github.com/juju/errors"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

Expand All @@ -43,7 +43,7 @@ func InitHTTPSClient(CAPath, CertPath, KeyPath string) error {
}
tlsConfig, err := tlsInfo.ClientConfig()
if err != nil {
return errors.Trace(err)
return errors.WithStack(err)
}

dialClient = &http.Client{Transport: &http.Transport{
Expand Down
4 changes: 2 additions & 2 deletions pdctl/command/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"net/http"
"strconv"

"github.com/juju/errors"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -355,7 +355,7 @@ func parseUint64s(args []string) ([]uint64, error) {
for _, arg := range args {
v, err := strconv.ParseUint(arg, 10, 64)
if err != nil {
return nil, errors.Trace(err)
return nil, errors.WithStack(err)
}
results = append(results, v)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/apiutil/apiutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ import (
"io/ioutil"
"strconv"

"github.com/juju/errors"
"github.com/pkg/errors"
)

// DeferClose captures the error returned from closing (if an error occurs).
// This is designed to be used in a defer statement.
func DeferClose(c io.Closer, err *error) {
if cerr := c.Close(); cerr != nil && *err == nil {
*err = errors.Trace(cerr)
*err = errors.WithStack(cerr)
}
}

Expand Down Expand Up @@ -55,7 +55,7 @@ func ReadJSON(r io.ReadCloser, data interface{}) error {
defer DeferClose(r, &err)
b, err := ioutil.ReadAll(r)
if err != nil {
return errors.Trace(err)
return errors.WithStack(err)
}

err = json.Unmarshal(b, data)
Expand Down
Loading