Skip to content

Commit

Permalink
*: add missing colon to errorf messages to improve readability (#5911)
Browse files Browse the repository at this point in the history
  • Loading branch information
ash2k authored Jan 18, 2023
1 parent cde2edc commit 379a2f6
Show file tree
Hide file tree
Showing 29 changed files with 58 additions and 55 deletions.
2 changes: 1 addition & 1 deletion balancer/grpclb/grpclb_remote_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ func (ccw *remoteBalancerCCWrapper) callRemoteBalancer(ctx context.Context) (bac
lbClient := &loadBalancerClient{cc: ccw.cc}
stream, err := lbClient.BalanceLoad(ctx, grpc.WaitForReady(true))
if err != nil {
return true, fmt.Errorf("grpclb: failed to perform RPC to the remote balancer %v", err)
return true, fmt.Errorf("grpclb: failed to perform RPC to the remote balancer: %v", err)
}
ccw.lb.mu.Lock()
ccw.lb.remoteBalancerConnected = true
Expand Down
2 changes: 1 addition & 1 deletion benchmark/benchmain/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ func (nopCompressor) Do(w io.Writer, p []byte) error {
return err
}
if n != len(p) {
return fmt.Errorf("nopCompressor.Write: wrote %v bytes; want %v", n, len(p))
return fmt.Errorf("nopCompressor.Write: wrote %d bytes; want %d", n, len(p))
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion benchmark/benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func NewClientConn(addr string, opts ...grpc.DialOption) *grpc.ClientConn {
func NewClientConnWithContext(ctx context.Context, addr string, opts ...grpc.DialOption) *grpc.ClientConn {
conn, err := grpc.DialContext(ctx, addr, opts...)
if err != nil {
logger.Fatalf("NewClientConn(%q) failed to create a ClientConn %v", addr, err)
logger.Fatalf("NewClientConn(%q) failed to create a ClientConn: %v", addr, err)
}
return conn
}
2 changes: 1 addition & 1 deletion benchmark/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ var (
func main() {
flag.Parse()
if *testName == "" {
logger.Fatalf("test_name not set")
logger.Fatal("-test_name not set")
}
req := &testpb.SimpleRequest{
ResponseType: testpb.PayloadType_COMPRESSABLE,
Expand Down
2 changes: 1 addition & 1 deletion benchmark/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ var (
func main() {
flag.Parse()
if *testName == "" {
logger.Fatalf("test name not set")
logger.Fatal("-test_name not set")
}
lis, err := net.Listen("tcp", ":"+*port)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion benchmark/worker/benchmark_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func createConns(config *testpb.ClientConfig) ([]*grpc.ClientConn, func(), error
}
creds, err := credentials.NewClientTLSFromFile(*caFile, config.SecurityParams.ServerHostOverride)
if err != nil {
return nil, nil, status.Errorf(codes.InvalidArgument, "failed to create TLS credentials %v", err)
return nil, nil, status.Errorf(codes.InvalidArgument, "failed to create TLS credentials: %v", err)
}
opts = append(opts, grpc.WithTransportCredentials(creds))
} else {
Expand Down
2 changes: 1 addition & 1 deletion benchmark/worker/benchmark_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func startBenchmarkServer(config *testpb.ServerConfig, serverPort int) (*benchma
}
creds, err := credentials.NewServerTLSFromFile(*certFile, *keyFile)
if err != nil {
logger.Fatalf("failed to generate credentials %v", err)
logger.Fatalf("failed to generate credentials: %v", err)
}
opts = append(opts, grpc.Creds(creds))
}
Expand Down
2 changes: 1 addition & 1 deletion clientconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -1376,7 +1376,7 @@ func (ac *addrConn) startHealthCheck(ctx context.Context) {
if status.Code(err) == codes.Unimplemented {
channelz.Error(logger, ac.channelzID, "Subchannel health check is unimplemented at server side, thus health check is disabled")
} else {
channelz.Errorf(logger, ac.channelzID, "HealthCheckFunc exits with unexpected error %v", err)
channelz.Errorf(logger, ac.channelzID, "Health checking failed: %v", err)
}
}
}()
Expand Down
2 changes: 1 addition & 1 deletion examples/features/health/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func main() {

conn, err := grpc.Dial(address, options...)
if err != nil {
log.Fatalf("did not connect %v", err)
log.Fatalf("grpc.Dial(%q): %v", address, err)
}
defer conn.Close()

Expand Down
4 changes: 2 additions & 2 deletions examples/features/interceptor/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func unaryInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServ
}
m, err := handler(ctx, req)
if err != nil {
logger("RPC failed with error %v", err)
logger("RPC failed with error: %v", err)
}
return m, err
}
Expand Down Expand Up @@ -135,7 +135,7 @@ func streamInterceptor(srv interface{}, ss grpc.ServerStream, info *grpc.StreamS

err := handler(srv, newWrappedStream(ss))
if err != nil {
logger("RPC failed with error %v", err)
logger("RPC failed with error: %v", err)
}
return err
}
Expand Down
4 changes: 2 additions & 2 deletions examples/features/metadata_interceptor/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ var addr = flag.String("addr", "localhost:50051", "the address to connect to")
func callUnaryEcho(ctx context.Context, client pb.EchoClient) {
resp, err := client.UnaryEcho(ctx, &pb.EchoRequest{Message: "hello world"})
if err != nil {
log.Fatalf("UnaryEcho %v", err)
log.Fatalf("UnaryEcho: %v", err)
}
fmt.Println("UnaryEcho: ", resp.Message)
}

func callBidiStreamingEcho(ctx context.Context, client pb.EchoClient) {
c, err := client.BidirectionalStreamingEcho(ctx)
if err != nil {
log.Fatalf("BidiStreamingEcho %v", err)
log.Fatalf("BidiStreamingEcho: %v", err)
}

if err := c.Send(&pb.EchoRequest{Message: "hello world"}); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion examples/route_guide/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func main() {
}
creds, err := credentials.NewClientTLSFromFile(*caFile, *serverHostOverride)
if err != nil {
log.Fatalf("Failed to create TLS credentials %v", err)
log.Fatalf("Failed to create TLS credentials: %v", err)
}
opts = append(opts, grpc.WithTransportCredentials(creds))
} else {
Expand Down
2 changes: 1 addition & 1 deletion examples/route_guide/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func main() {
}
creds, err := credentials.NewServerTLSFromFile(*certFile, *keyFile)
if err != nil {
log.Fatalf("Failed to generate credentials %v", err)
log.Fatalf("Failed to generate credentials: %v", err)
}
opts = []grpc.ServerOption{grpc.Creds(creds)}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/transport/http2_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func newHTTP2Client(connectCtx, ctx context.Context, addr resolver.Address, opts
if opts.FailOnNonTempDialError {
return nil, connectionErrorf(isTemporary(err), err, "transport: error while dialing: %v", err)
}
return nil, connectionErrorf(true, err, "transport: Error while dialing %v", err)
return nil, connectionErrorf(true, err, "transport: Error while dialing: %v", err)
}

// Any further errors will close the underlying connection
Expand Down Expand Up @@ -1182,7 +1182,7 @@ func (t *http2Client) handleRSTStream(f *http2.RSTStreamFrame) {
statusCode, ok := http2ErrConvTab[f.ErrCode]
if !ok {
if logger.V(logLevel) {
logger.Warningf("transport: http2Client.handleRSTStream found no mapped gRPC status for the received http2 error %v", f.ErrCode)
logger.Warningf("transport: http2Client.handleRSTStream found no mapped gRPC status for the received http2 error: %v", f.ErrCode)
}
statusCode = codes.Unknown
}
Expand Down
2 changes: 1 addition & 1 deletion interop/fake_grpclb/fake_grpclb.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func main() {
keyFile := testdata.Path("server1.key")
creds, err := credentials.NewServerTLSFromFile(certFile, keyFile)
if err != nil {
logger.Fatalf("Failed to generate credentials %v", err)
logger.Fatalf("Failed to generate credentials: %v", err)
}
opts = append(opts, grpc.Creds(creds))
} else if *useALTS {
Expand Down
6 changes: 3 additions & 3 deletions interop/http2/negative_http2_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func rstAfterHeader(tc testgrpc.TestServiceClient) {
req := largeSimpleRequest()
reply, err := tc.UnaryCall(context.Background(), req)
if reply != nil {
logger.Fatalf("Client received reply despite server sending rst stream after header")
logger.Fatal("Client received reply despite server sending rst stream after header")
}
if status.Code(err) != codes.Internal {
logger.Fatalf("%v.UnaryCall() = _, %v, want _, %v", tc, status.Code(err), codes.Internal)
Expand All @@ -92,7 +92,7 @@ func rstDuringData(tc testgrpc.TestServiceClient) {
req := largeSimpleRequest()
reply, err := tc.UnaryCall(context.Background(), req)
if reply != nil {
logger.Fatalf("Client received reply despite server sending rst stream during data")
logger.Fatal("Client received reply despite server sending rst stream during data")
}
if status.Code(err) != codes.Unknown {
logger.Fatalf("%v.UnaryCall() = _, %v, want _, %v", tc, status.Code(err), codes.Unknown)
Expand All @@ -103,7 +103,7 @@ func rstAfterData(tc testgrpc.TestServiceClient) {
req := largeSimpleRequest()
reply, err := tc.UnaryCall(context.Background(), req)
if reply != nil {
logger.Fatalf("Client received reply despite server sending rst stream after data")
logger.Fatal("Client received reply despite server sending rst stream after data")
}
if status.Code(err) != codes.Internal {
logger.Fatalf("%v.UnaryCall() = _, %v, want _, %v", tc, status.Code(err), codes.Internal)
Expand Down
4 changes: 2 additions & 2 deletions interop/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var (
func main() {
flag.Parse()
if *useTLS && *useALTS {
logger.Fatalf("use_tls and use_alts cannot be both set to true")
logger.Fatal("-use_tls and -use_alts cannot be both set to true")
}
p := strconv.Itoa(*port)
lis, err := net.Listen("tcp", ":"+p)
Expand All @@ -66,7 +66,7 @@ func main() {
}
creds, err := credentials.NewServerTLSFromFile(*certFile, *keyFile)
if err != nil {
logger.Fatalf("Failed to generate credentials %v", err)
logger.Fatalf("Failed to generate credentials: %v", err)
}
opts = append(opts, grpc.Creds(creds))
} else if *useALTS {
Expand Down
15 changes: 9 additions & 6 deletions interop/xds/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,10 @@ func main() {
// If -secure_mode is not set, expose all services on -port with a regular
// gRPC server.
if !*secureMode {
lis, err := net.Listen("tcp4", fmt.Sprintf(":%d", *port))
addr := fmt.Sprintf(":%d", *port)
lis, err := net.Listen("tcp4", addr)
if err != nil {
logger.Fatalf("net.Listen(%s) failed: %v", fmt.Sprintf(":%d", *port), err)
logger.Fatalf("net.Listen(%s) failed: %v", addr, err)
}

server := grpc.NewServer()
Expand All @@ -141,9 +142,10 @@ func main() {
}

// Create a listener on -port to expose the test service.
testLis, err := net.Listen("tcp4", fmt.Sprintf(":%d", *port))
addr := fmt.Sprintf(":%d", *port)
testLis, err := net.Listen("tcp4", addr)
if err != nil {
logger.Fatalf("net.Listen(%s) failed: %v", fmt.Sprintf(":%d", *port), err)
logger.Fatalf("net.Listen(%s) failed: %v", addr, err)
}

// Create server-side xDS credentials with a plaintext fallback.
Expand All @@ -164,9 +166,10 @@ func main() {
defer testServer.Stop()

// Create a listener on -maintenance_port to expose other services.
maintenanceLis, err := net.Listen("tcp4", fmt.Sprintf(":%d", *maintenancePort))
addr = fmt.Sprintf(":%d", *maintenancePort)
maintenanceLis, err := net.Listen("tcp4", addr)
if err != nil {
logger.Fatalf("net.Listen(%s) failed: %v", fmt.Sprintf(":%d", *maintenancePort), err)
logger.Fatalf("net.Listen(%s) failed: %v", addr, err)
}

// Create a regular gRPC server and register the maintenance services on
Expand Down
2 changes: 1 addition & 1 deletion pickfirst.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type pickfirstBalancer struct {

func (b *pickfirstBalancer) ResolverError(err error) {
if logger.V(2) {
logger.Infof("pickfirstBalancer: ResolverError called with error %v", err)
logger.Infof("pickfirstBalancer: ResolverError called with error: %v", err)
}
if b.subConn == nil {
b.state = connectivity.TransientFailure
Expand Down
4 changes: 2 additions & 2 deletions rpc_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ func recvAndDecompress(p *parser, s *transport.Stream, dc Decompressor, maxRecei
d, size, err = decompress(compressor, d, maxReceiveMessageSize)
}
if err != nil {
return nil, status.Errorf(codes.Internal, "grpc: failed to decompress the received message %v", err)
return nil, status.Errorf(codes.Internal, "grpc: failed to decompress the received message: %v", err)
}
if size > maxReceiveMessageSize {
// TODO: Revisit the error code. Currently keep it consistent with java
Expand Down Expand Up @@ -760,7 +760,7 @@ func recv(p *parser, c baseCodec, s *transport.Stream, dc Decompressor, m interf
return err
}
if err := c.Unmarshal(d, m); err != nil {
return status.Errorf(codes.Internal, "grpc: failed to unmarshal the received message %v", err)
return status.Errorf(codes.Internal, "grpc: failed to unmarshal the received message: %v", err)
}
if payInfo != nil {
payInfo.uncompressedBytes = d
Expand Down
18 changes: 9 additions & 9 deletions security/advancedtls/crl.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,11 @@ func fetchIssuerCRL(rawIssuer []byte, crlVerifyCrt []*x509.Certificate, cfg Revo

crl, err := fetchCRL(rawIssuer, cfg)
if err != nil {
return nil, fmt.Errorf("fetchCRL() failed err = %v", err)
return nil, fmt.Errorf("fetchCRL() failed: %v", err)
}

if err := verifyCRL(crl, rawIssuer, crlVerifyCrt); err != nil {
return nil, fmt.Errorf("verifyCRL() failed err = %v", err)
return nil, fmt.Errorf("verifyCRL() failed: %v", err)
}
if cfg.Cache != nil {
cfg.Cache.Add(hex.EncodeToString(rawIssuer), crl)
Expand All @@ -264,7 +264,7 @@ func checkCert(c *x509.Certificate, crlVerifyCrt []*x509.Certificate, cfg Revoca
}
revocation, err := checkCertRevocation(c, crl)
if err != nil {
grpclogLogger.Warningf("checkCertRevocation(CRL %v) failed %v", crl.CertList.TBSCertList.Issuer, err)
grpclogLogger.Warningf("checkCertRevocation(CRL %v) failed: %v", crl.CertList.TBSCertList.Issuer, err)
// We couldn't check the CRL file for some reason, so we don't know if it's RevocationUnrevoked or not.
return RevocationUndetermined
}
Expand Down Expand Up @@ -317,7 +317,7 @@ func parseCertIssuerExt(ext pkix.Extension) ([]byte, error) {
// GeneralNames ::= SEQUENCE SIZE (1..MAX) OF GeneralName
var generalNames []asn1.RawValue
if rest, err := asn1.Unmarshal(ext.Value, &generalNames); err != nil || len(rest) != 0 {
return nil, fmt.Errorf("asn1.Unmarshal failed err = %v", err)
return nil, fmt.Errorf("asn1.Unmarshal failed: %v", err)
}

for _, generalName := range generalNames {
Expand Down Expand Up @@ -386,7 +386,7 @@ func parseCRLExtensions(c *pkix.CertificateList) (*certificateListExt, error) {
case oidAuthorityKeyIdentifier.Equal(ext.Id):
var a authKeyID
if rest, err := asn1.Unmarshal(ext.Value, &a); err != nil {
return nil, fmt.Errorf("asn1.Unmarshal failed. err = %v", err)
return nil, fmt.Errorf("asn1.Unmarshal failed: %v", err)
} else if len(rest) != 0 {
return nil, errors.New("trailing data after AKID extension")
}
Expand All @@ -395,7 +395,7 @@ func parseCRLExtensions(c *pkix.CertificateList) (*certificateListExt, error) {
case oidIssuingDistributionPoint.Equal(ext.Id):
var dp issuingDistributionPoint
if rest, err := asn1.Unmarshal(ext.Value, &dp); err != nil {
return nil, fmt.Errorf("asn1.Unmarshal failed. err = %v", err)
return nil, fmt.Errorf("asn1.Unmarshal failed: %v", err)
} else if len(rest) != 0 {
return nil, errors.New("trailing data after IssuingDistributionPoint extension")
}
Expand Down Expand Up @@ -431,7 +431,7 @@ func fetchCRL(rawIssuer []byte, cfg RevocationConfig) (*certificateListExt, erro
var r pkix.RDNSequence
rest, err := asn1.Unmarshal(rawIssuer, &r)
if len(rest) != 0 || err != nil {
return nil, fmt.Errorf("asn1.Unmarshal(Issuer) len(rest) = %v, err = %v", len(rest), err)
return nil, fmt.Errorf("asn1.Unmarshal(Issuer) len(rest) = %d failed: %v", len(rest), err)
}
crlPath := fmt.Sprintf("%s.r%d", filepath.Join(cfg.RootDir, x509NameHash(r)), i)
crlBytes, err := os.ReadFile(crlPath)
Expand All @@ -444,11 +444,11 @@ func fetchCRL(rawIssuer []byte, cfg RevocationConfig) (*certificateListExt, erro
crl, err := x509.ParseCRL(crlBytes)
if err != nil {
// Parsing errors for a CRL shouldn't happen so fail.
return nil, fmt.Errorf("x509.ParseCrl(%v) failed err = %v", crlPath, err)
return nil, fmt.Errorf("x509.ParseCrl(%v) failed: %v", crlPath, err)
}
var certList *certificateListExt
if certList, err = parseCRLExtensions(crl); err != nil {
grpclogLogger.Infof("fetchCRL: unsupported crl %v, err = %v", crlPath, err)
grpclogLogger.Infof("fetchCRL: unsupported crl %v: %v", crlPath, err)
// Continue to find a supported CRL
continue
}
Expand Down
2 changes: 1 addition & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1299,7 +1299,7 @@ func (s *Server) processUnaryRPC(t transport.ServerTransport, stream *transport.
d, err := recvAndDecompress(&parser{r: stream}, stream, dc, s.opts.maxReceiveMessageSize, payInfo, decomp)
if err != nil {
if e := t.WriteStatus(stream, status.Convert(err)); e != nil {
channelz.Warningf(logger, s.channelzID, "grpc: Server.processUnaryRPC failed to write status %v", e)
channelz.Warningf(logger, s.channelzID, "grpc: Server.processUnaryRPC failed to write status: %v", e)
}
return err
}
Expand Down
10 changes: 5 additions & 5 deletions service_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func parseServiceConfig(js string) *serviceconfig.ParseResult {
var rsc jsonSC
err := json.Unmarshal([]byte(js), &rsc)
if err != nil {
logger.Warningf("grpc: parseServiceConfig error unmarshaling %s due to %v", js, err)
logger.Warningf("grpc: unmarshaling service config %s: %v", js, err)
return &serviceconfig.ParseResult{Err: err}
}
sc := ServiceConfig{
Expand Down Expand Up @@ -254,7 +254,7 @@ func parseServiceConfig(js string) *serviceconfig.ParseResult {
}
d, err := parseDuration(m.Timeout)
if err != nil {
logger.Warningf("grpc: parseServiceConfig error unmarshaling %s due to %v", js, err)
logger.Warningf("grpc: unmarshaling service config %s: %v", js, err)
return &serviceconfig.ParseResult{Err: err}
}

Expand All @@ -263,7 +263,7 @@ func parseServiceConfig(js string) *serviceconfig.ParseResult {
Timeout: d,
}
if mc.RetryPolicy, err = convertRetryPolicy(m.RetryPolicy); err != nil {
logger.Warningf("grpc: parseServiceConfig error unmarshaling %s due to %v", js, err)
logger.Warningf("grpc: unmarshaling service config %s: %v", js, err)
return &serviceconfig.ParseResult{Err: err}
}
if m.MaxRequestMessageBytes != nil {
Expand All @@ -283,13 +283,13 @@ func parseServiceConfig(js string) *serviceconfig.ParseResult {
for i, n := range *m.Name {
path, err := n.generatePath()
if err != nil {
logger.Warningf("grpc: parseServiceConfig error unmarshaling %s due to methodConfig[%d]: %v", js, i, err)
logger.Warningf("grpc: error unmarshaling service config %s due to methodConfig[%d]: %v", js, i, err)
return &serviceconfig.ParseResult{Err: err}
}

if _, ok := paths[path]; ok {
err = errDuplicatedName
logger.Warningf("grpc: parseServiceConfig error unmarshaling %s due to methodConfig[%d]: %v", js, i, err)
logger.Warningf("grpc: error unmarshaling service config %s due to methodConfig[%d]: %v", js, i, err)
return &serviceconfig.ParseResult{Err: err}
}
paths[path] = struct{}{}
Expand Down
Loading

0 comments on commit 379a2f6

Please sign in to comment.