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

Replace pkg/errors wrapping with fmt.Errorf #2070

Merged
merged 1 commit into from
Feb 17, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 4 additions & 5 deletions cmd/agent/app/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"strconv"

"github.com/apache/thrift/lib/go/thrift"
"github.com/pkg/errors"
"github.com/uber/jaeger-lib/metrics"
"go.uber.org/zap"

Expand Down Expand Up @@ -110,7 +109,7 @@ func (b *Builder) CreateAgent(primaryProxy CollectorProxy, logger *zap.Logger, m
r := b.getReporter(primaryProxy)
processors, err := b.getProcessors(r, mFactory, logger)
if err != nil {
return nil, errors.Wrap(err, "cannot create processors")
return nil, fmt.Errorf("cannot create processors: %w", err)
}
server := b.HTTPServer.getHTTPServer(primaryProxy.GetManager(), mFactory)
return NewAgent(processors, server, logger), nil
Expand Down Expand Up @@ -150,7 +149,7 @@ func (b *Builder) getProcessors(rep reporter.Reporter, mFactory metrics.Factory,
}})
processor, err := cfg.GetThriftProcessor(metrics, protoFactory, handler, logger)
if err != nil {
return nil, errors.Wrap(err, "cannot create Thrift Processor")
return nil, fmt.Errorf("cannot create Thrift Processor: %w", err)
}
retMe[idx] = processor
}
Expand All @@ -176,7 +175,7 @@ func (c *ProcessorConfiguration) GetThriftProcessor(

server, err := c.Server.getUDPServer(mFactory)
if err != nil {
return nil, errors.Wrap(err, "cannot create UDP Server")
return nil, fmt.Errorf("cannot create UDP Server: %w", err)
}

return processors.NewThriftProcessor(server, c.Workers, mFactory, factory, handler, logger)
Expand All @@ -200,7 +199,7 @@ func (c *ServerConfiguration) getUDPServer(mFactory metrics.Factory) (servers.Se
}
transport, err := thriftudp.NewTUDPServerTransport(c.HostPort)
if err != nil {
return nil, errors.Wrap(err, "cannot create UDPServerTransport")
return nil, fmt.Errorf("cannot create UDPServerTransport: %w", err)
}

return servers.NewTBufferedServer(transport, c.QueueSize, c.MaxPacketSize, mFactory)
Expand Down
5 changes: 3 additions & 2 deletions cmd/agent/app/reporter/grpc/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
package grpc

import (
"errors"
"fmt"
"strings"

grpc_retry "github.com/grpc-ecosystem/go-grpc-middleware/retry"
"github.com/pkg/errors"
"go.uber.org/zap"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
Expand Down Expand Up @@ -56,7 +57,7 @@ func (b *ConnBuilder) CreateConnection(logger *zap.Logger) (*grpc.ClientConn, er
logger.Info("Agent requested secure grpc connection to collector(s)")
tlsConf, err := b.TLS.Config()
if err != nil {
return nil, errors.Wrap(err, "failed to load TLS config")
return nil, fmt.Errorf("failed to load TLS config: %w", err)
}

creds := credentials.NewTLS(tlsConf)
Expand Down
3 changes: 1 addition & 2 deletions cmd/agent/app/reporter/grpc/collector_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/jaegertracing/jaeger/cmd/agent/app/configmanager"
grpcManager "github.com/jaegertracing/jaeger/cmd/agent/app/configmanager/grpc"
"github.com/jaegertracing/jaeger/cmd/agent/app/reporter"
aReporter "github.com/jaegertracing/jaeger/cmd/agent/app/reporter"
)

// ProxyBuilder holds objects communicating with collector
Expand Down Expand Up @@ -59,7 +58,7 @@ func (b ProxyBuilder) GetConn() *grpc.ClientConn {
}

// GetReporter returns Reporter
func (b ProxyBuilder) GetReporter() aReporter.Reporter {
func (b ProxyBuilder) GetReporter() reporter.Reporter {
return b.reporter
}

Expand Down
5 changes: 3 additions & 2 deletions cmd/agent/app/reporter/tchannel/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
package tchannel

import (
"errors"
"fmt"
"time"

"github.com/pkg/errors"
tchannel "github.com/uber/tchannel-go"
"go.uber.org/zap"

Expand Down Expand Up @@ -129,7 +130,7 @@ func (b *Builder) CreateReporter(logger *zap.Logger) (*Reporter, error) {

peerListMgr, err := b.enableDiscovery(b.channel, logger)
if err != nil {
return nil, errors.Wrap(err, "cannot enable service discovery")
return nil, fmt.Errorf("cannot enable service discovery: %w", err)
}
return New(b.CollectorServiceName, b.channel, b.ReportTimeout, peerListMgr, logger), nil
}
Expand Down
5 changes: 2 additions & 3 deletions cmd/agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"io"
"os"

"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/uber/jaeger-lib/metrics"
Expand Down Expand Up @@ -69,12 +68,12 @@ func main() {
builder := new(app.Builder).InitFromViper(v)
agent, err := builder.CreateAgent(cp, logger, mFactory)
if err != nil {
return errors.Wrap(err, "unable to initialize Jaeger Agent")
return fmt.Errorf("unable to initialize Jaeger Agent: %w", err)
}

logger.Info("Starting agent")
if err := agent.Run(); err != nil {
return errors.Wrap(err, "failed to run the agent")
return fmt.Errorf("failed to run the agent: %w", err)
}
svc.RunAndThen(func() {
if closer, ok := cp.(io.Closer); ok {
Expand Down
4 changes: 2 additions & 2 deletions cmd/collector/app/server/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
package server

import (
"fmt"
"io/ioutil"
"net"
"os"
"strconv"

"github.com/pkg/errors"
"go.uber.org/zap"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
Expand Down Expand Up @@ -65,7 +65,7 @@ func StartGRPCServer(params *GRPCServerParams) (*grpc.Server, error) {
grpcPortStr := ":" + strconv.Itoa(params.Port)
listener, err := net.Listen("tcp", grpcPortStr)
if err != nil {
return nil, errors.Wrap(err, "failed to listen on gRPC port")
return nil, fmt.Errorf("failed to listen on gRPC port: %w", err)
}

if err := serveGRPC(server, listener, params); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ package flags

import (
"flag"
"fmt"
"os"
"strings"

"github.com/pkg/errors"
"github.com/spf13/viper"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
Expand All @@ -43,7 +43,7 @@ func TryLoadConfigFile(v *viper.Viper) error {
v.SetConfigFile(file)
err := v.ReadInConfig()
if err != nil {
return errors.Wrapf(err, "cannot load config file %s", file)
return fmt.Errorf("cannot load config file %s: %w", file, err)
}
}
return nil
Expand Down
10 changes: 5 additions & 5 deletions cmd/flags/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ package flags

import (
"flag"
"fmt"
"os"
"os/signal"
"syscall"

grpcZap "github.com/grpc-ecosystem/go-grpc-middleware/logging/zap"
"github.com/pkg/errors"
"github.com/spf13/viper"
"github.com/uber/jaeger-lib/metrics"
"go.uber.org/zap"
Expand Down Expand Up @@ -85,7 +85,7 @@ func (s *Service) SetHealthCheckStatus(status healthcheck.Status) {
// Start bootstraps the service and starts the admin server.
func (s *Service) Start(v *viper.Viper) error {
if err := TryLoadConfigFile(v); err != nil {
return errors.Wrap(err, "cannot load config file")
return fmt.Errorf("cannot load config file: %w", err)
}

sFlags := new(SharedFlags).InitFromViper(v)
Expand All @@ -99,13 +99,13 @@ func (s *Service) Start(v *viper.Viper) error {
zap.AddCallerSkip(3),
))
} else {
return errors.Wrap(err, "cannot create logger")
return fmt.Errorf("cannot create logger: %w", err)
}

metricsBuilder := new(pMetrics.Builder).InitFromViper(v)
metricsFactory, err := metricsBuilder.CreateMetricsFactory("")
if err != nil {
return errors.Wrap(err, "cannot create metrics factory")
return fmt.Errorf("cannot create metrics factory: %w", err)
}
s.MetricsFactory = metricsFactory

Expand All @@ -116,7 +116,7 @@ func (s *Service) Start(v *viper.Viper) error {
s.Admin.Handle(route, h)
}
if err := s.Admin.Serve(); err != nil {
return errors.Wrap(err, "cannot start the admin server")
return fmt.Errorf("cannot start the admin server: %w", err)
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions cmd/ingester/app/consumer/consumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
package consumer

import (
"errors"
"fmt"
"sync"
"testing"
"time"

"github.com/Shopify/sarama"
smocks "github.com/Shopify/sarama/mocks"
"github.com/bsm/sarama-cluster"
"github.com/pkg/errors"
cluster "github.com/bsm/sarama-cluster"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
Expand Down
2 changes: 1 addition & 1 deletion cmd/ingester/app/processor/metrics_decorator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
package processor_test

import (
"errors"
"testing"

"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/uber/jaeger-lib/metrics/metricstest"

Expand Down
5 changes: 2 additions & 3 deletions cmd/ingester/app/processor/span_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
package processor

import (
"fmt"
"io"

"github.com/pkg/errors"

"github.com/jaegertracing/jaeger/plugin/storage/kafka"
"github.com/jaegertracing/jaeger/storage/spanstore"
)
Expand Down Expand Up @@ -61,7 +60,7 @@ func NewSpanProcessor(params SpanProcessorParams) *KafkaSpanProcessor {
func (s KafkaSpanProcessor) Process(message Message) error {
mSpan, err := s.unmarshaller.Unmarshal(message.Value())
if err != nil {
return errors.Wrap(err, "cannot unmarshall byte array into span")
return fmt.Errorf("cannot unmarshall byte array into span: %w", err)
}
return s.writer.WriteSpan(mSpan)
}
2 changes: 1 addition & 1 deletion cmd/ingester/app/processor/span_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
package processor

import (
"errors"
"testing"

"github.com/pkg/errors"
"github.com/stretchr/testify/assert"

cmocks "github.com/jaegertracing/jaeger/cmd/ingester/app/consumer/mocks"
Expand Down
15 changes: 10 additions & 5 deletions cmd/query/app/http_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"github.com/gorilla/mux"
"github.com/opentracing-contrib/go-stdlib/nethttp"
"github.com/opentracing/opentracing-go"
"github.com/pkg/errors"
"go.uber.org/zap"

"github.com/jaegertracing/jaeger/cmd/query/app/querysvc"
Expand Down Expand Up @@ -263,14 +262,20 @@ func (aH *APIHandler) tracesByIDs(ctx context.Context, traceIDs []model.TraceID)

func (aH *APIHandler) dependencies(w http.ResponseWriter, r *http.Request) {
endTsMillis, err := strconv.ParseInt(r.FormValue(endTsParam), 10, 64)
if aH.handleError(w, errors.Wrapf(err, "unable to parse %s", endTimeParam), http.StatusBadRequest) {
return
if err != nil {
err = fmt.Errorf("unable to parse %s: %w", endTimeParam, err)
if aH.handleError(w, err, http.StatusBadRequest) {
return
}
}
var lookback time.Duration
if formValue := r.FormValue(lookbackParam); len(formValue) > 0 {
lookback, err = time.ParseDuration(formValue + "ms")
if aH.handleError(w, errors.Wrapf(err, "unable to parse %s", lookbackParam), http.StatusBadRequest) {
return
if err != nil {
err = fmt.Errorf("unable to parse %s: %w", lookbackParam, err)
if aH.handleError(w, err, http.StatusBadRequest) {
return
}
}
}
service := r.FormValue(serviceParam)
Expand Down
6 changes: 2 additions & 4 deletions cmd/query/app/query_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import (
"strings"
"time"

"github.com/pkg/errors"

"github.com/jaegertracing/jaeger/model"
"github.com/jaegertracing/jaeger/storage/spanstore"
)
Expand Down Expand Up @@ -121,7 +119,7 @@ func (p *queryParser) parse(r *http.Request) (*traceQueryParameters, error) {
if traceID, err := model.TraceIDFromString(id); err == nil {
traceIDs = append(traceIDs, traceID)
} else {
return nil, errors.Wrap(err, "cannot parse traceID param")
return nil, fmt.Errorf("cannot parse traceID param: %w", err)
}
}

Expand Down Expand Up @@ -165,7 +163,7 @@ func (p *queryParser) parseDuration(durationParam string, r *http.Request) (time
if len(durationInput) > 0 {
duration, err := time.ParseDuration(durationInput)
if err != nil {
return 0, errors.Wrapf(err, "cannot not parse %s", durationParam)
return 0, fmt.Errorf("cannot not parse %s: %w", durationParam, err)
}
return duration, nil
}
Expand Down
11 changes: 5 additions & 6 deletions cmd/query/app/static_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (

"github.com/fsnotify/fsnotify"
"github.com/gorilla/mux"
"github.com/pkg/errors"
"go.uber.org/zap"

"github.com/jaegertracing/jaeger/cmd/query/app/ui"
Expand Down Expand Up @@ -101,7 +100,7 @@ func NewStaticAssetsHandler(staticAssetsRoot string, options StaticAssetsHandler
func loadIndexBytes(open func(string) (http.File, error), options StaticAssetsHandlerOptions) ([]byte, error) {
indexBytes, err := loadIndexHTML(open)
if err != nil {
return nil, errors.Wrap(err, "cannot load index.html")
return nil, fmt.Errorf("cannot load index.html: %w", err)
}
configString := "JAEGER_CONFIG = DEFAULT_CONFIG"
if config, err := loadUIConfig(options.UIConfigPath); err != nil {
Expand Down Expand Up @@ -188,12 +187,12 @@ func (sH *StaticAssetsHandler) watch() {
func loadIndexHTML(open func(string) (http.File, error)) ([]byte, error) {
indexFile, err := open("/index.html")
if err != nil {
return nil, errors.Wrap(err, "cannot open index.html")
return nil, fmt.Errorf("cannot open index.html: %w", err)
}
defer indexFile.Close()
indexBytes, err := ioutil.ReadAll(indexFile)
if err != nil {
return nil, errors.Wrap(err, "cannot read from index.html")
return nil, fmt.Errorf("cannot read from index.html: %w", err)
}
return indexBytes, nil
}
Expand All @@ -205,7 +204,7 @@ func loadUIConfig(uiConfig string) (map[string]interface{}, error) {
ext := filepath.Ext(uiConfig)
bytes, err := ioutil.ReadFile(uiConfig) /* nolint #nosec , this comes from an admin, not user */
if err != nil {
return nil, errors.Wrapf(err, "cannot read UI config file %v", uiConfig)
return nil, fmt.Errorf("cannot read UI config file %v: %w", uiConfig, err)
}

var c map[string]interface{}
Expand All @@ -219,7 +218,7 @@ func loadUIConfig(uiConfig string) (map[string]interface{}, error) {
}

if err := unmarshal(bytes, &c); err != nil {
return nil, errors.Wrapf(err, "cannot parse UI config file %v", uiConfig)
return nil, fmt.Errorf("cannot parse UI config file %v: %w", uiConfig, err)
}
return c, nil
}
Expand Down
Loading