Skip to content

Commit

Permalink
adding stack to errors
Browse files Browse the repository at this point in the history
Signed-off-by: Ruslan Bayandinov <wazsone@ya.ru>
  • Loading branch information
wazsone committed Jan 25, 2023
1 parent 637ce70 commit ef0c48e
Show file tree
Hide file tree
Showing 150 changed files with 709 additions and 483 deletions.
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ require (
go.opentelemetry.io/otel/trace v1.9.0
go.uber.org/atomic v1.7.0
go.uber.org/goleak v1.1.12
golang.org/x/net v0.4.0
golang.org/x/net v0.5.0
gonum.org/v1/gonum v0.6.2
google.golang.org/grpc v1.49.0
google.golang.org/protobuf v1.28.1
Expand Down Expand Up @@ -91,10 +91,10 @@ require (
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90 // indirect
golang.org/x/mod v0.7.0 // indirect
golang.org/x/sys v0.3.0 // indirect
golang.org/x/text v0.5.0 // indirect
golang.org/x/sys v0.4.0 // indirect
golang.org/x/text v0.6.0 // indirect
golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11 // indirect
golang.org/x/tools v0.3.0 // indirect
golang.org/x/tools v0.5.0 // indirect
google.golang.org/genproto v0.0.0-20220908141613-51c1cc9bc6d0 // indirect
gopkg.in/square/go-jose.v2 v2.5.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,8 @@ golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT
golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20210917221730-978cfadd31cf/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.4.0 h1:Q5QPcMlvfxFTAPV0+07Xz/MpK9NTXu2VDUuy0FeMfaU=
golang.org/x/net v0.4.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE=
golang.org/x/net v0.5.0 h1:GyT4nK/YDHSqa1c4753ouYCDajOYKTja9Xb/OHtgvSw=
golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -571,8 +571,8 @@ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220111092808-5a964db01320/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18=
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand All @@ -582,8 +582,8 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.5.0 h1:OLmvp0KP+FVG99Ct/qFiL/Fhk4zp4QQnZ7b2U+5piUM=
golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.6.0 h1:3XmdazWV+ubf7QgHSTWeykHOci5oeekaGJBLkrkaw4k=
golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down Expand Up @@ -638,8 +638,8 @@ golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4f
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.6-0.20210726203631-07bc1bf47fb2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.3.0 h1:SrNbZl6ECOS1qFzgTdQfWXZM9XBkiA6tkFrH9YSTPHM=
golang.org/x/tools v0.3.0/go.mod h1:/rWhSS2+zyEVwoJf8YAX6L2f0ntZ7Kn/mGgAWcipA5k=
golang.org/x/tools v0.5.0 h1:+bSpV5HIeWkuvgaMfI3UmKRThoTA5ODJTUd8T17NO+4=
golang.org/x/tools v0.5.0/go.mod h1:N+Kgy78s5I24c24dU8OfWNEotWjutIs8SnJvn5IDq+k=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
4 changes: 2 additions & 2 deletions pkg/ipam/vl3ipam/server.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022 Cisco and/or its affiliates.
// Copyright (c) 2022-2023 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -123,5 +123,5 @@ func (s *vl3IPAMServer) ManagePrefixes(prefixServer ipam.IPAM_ManagePrefixesServ
return nil
}

return err
return errors.WithStack(err)
}
8 changes: 5 additions & 3 deletions pkg/networkservice/chains/endpoint/combine_monitor_server.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) 2021 Doc.ai and/or its affiliates.
//
// Copyright (c) 2023 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -53,7 +55,7 @@ func (m *combineMonitorServer) MonitorConnections(selector *networkservice.Monit
if rv := monitorErr.Load(); rv != nil {
err = rv.(error)
}
return err
return errors.WithStack(err)
}

func startMonitorConnectionsServer(
Expand Down Expand Up @@ -130,10 +132,10 @@ func (m *combineMonitorConnectionsServer) Send(event *networkservice.ConnectionE
m.initCh <- event
err = <-m.errCh
})
return err
return errors.WithStack(err)
default:
m.initWg.Wait()
return m.MonitorConnection_MonitorConnectionsServer.Send(event)
return errors.WithStack(m.MonitorConnection_MonitorConnectionsServer.Send(event))
}
}

Expand Down
10 changes: 5 additions & 5 deletions pkg/networkservice/common/authorize/client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2020-2022 Doc.ai and/or its affiliates.
//
// Copyright (c) 2020-2022 Cisco Systems, Inc.
// Copyright (c) 2020-2023 Cisco Systems, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -75,7 +75,7 @@ func (a *authorizeClient) Request(ctx context.Context, request *networkservice.N

conn, err := next.Client(ctx).Request(ctx, request, opts...)
if err != nil {
return nil, err
return nil, errors.WithStack(err)
}

if p != (peer.Peer{}) {
Expand All @@ -88,13 +88,13 @@ func (a *authorizeClient) Request(ctx context.Context, request *networkservice.N
defer cancelClose()

if _, closeErr := next.Client(ctx).Close(closeCtx, conn, opts...); closeErr != nil {
err = errors.Wrapf(err, "connection closed with error: %s", closeErr.Error())
err = errors.WithStack(errors.Wrapf(err, "connection closed with error: %s", closeErr.Error()))
}

return nil, err
}

return conn, err
return conn, nil
}

func (a *authorizeClient) Close(ctx context.Context, conn *networkservice.Connection, opts ...grpc.CallOption) (*empty.Empty, error) {
Expand All @@ -103,7 +103,7 @@ func (a *authorizeClient) Close(ctx context.Context, conn *networkservice.Connec
ctx = peer.NewContext(ctx, p)
}
if err := a.policies.check(ctx, conn.GetPath()); err != nil {
return nil, err
return nil, errors.WithStack(err)
}

return next.Client(ctx).Close(ctx, conn, opts...)
Expand Down
5 changes: 4 additions & 1 deletion pkg/networkservice/common/authorize/common.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) 2020-2021 Doc.ai and/or its affiliates.
//
// Copyright (c) 2023 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -20,6 +22,7 @@ import (
"context"

"github.com/networkservicemesh/api/pkg/api/networkservice"
"github.com/pkg/errors"
)

// Policy represents authorization policy for network service.
Expand All @@ -39,7 +42,7 @@ func (l *policiesList) check(ctx context.Context, p *networkservice.Path) error
continue
}
if err := policy.Check(ctx, p); err != nil {
return err
return errors.WithStack(err)
}
}
return nil
Expand Down
8 changes: 4 additions & 4 deletions pkg/networkservice/common/begin/client.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021-2022 Cisco and/or its affiliates.
// Copyright (c) 2021-2023 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -41,7 +41,7 @@ func NewClient() networkservice.NetworkServiceClient {
func (b *beginClient) Request(ctx context.Context, request *networkservice.NetworkServiceRequest, opts ...grpc.CallOption) (conn *networkservice.Connection, err error) {
// No connection.ID, no service
if request.GetConnection().GetId() == "" {
return nil, errors.New("request.EventFactory.Id must not be zero valued")
return nil, errors.WithStack(errors.New("request.EventFactory.Id must not be zero valued"))
}
// If some other EventFactory is already in the ctx... we are already running in an executor, and can just execute normally
if fromContext(ctx) != nil {
Expand Down Expand Up @@ -84,7 +84,7 @@ func (b *beginClient) Request(ctx context.Context, request *networkservice.Netwo
eventFactoryClient.returnedConnection = conn.Clone()
eventFactoryClient.updateContext(ctx)
})
return conn, err
return conn, errors.WithStack(err)
}

func (b *beginClient) Close(ctx context.Context, conn *networkservice.Connection, opts ...grpc.CallOption) (emp *emptypb.Empty, err error) {
Expand Down Expand Up @@ -115,5 +115,5 @@ func (b *beginClient) Close(ctx context.Context, conn *networkservice.Connection
// afterCloseFunc() is used to cleanup things like the entry in the Map for EventFactories
eventFactoryClient.afterCloseFunc()
})
return emp, err
return emp, errors.WithStack(err)
}
2 changes: 2 additions & 0 deletions pkg/networkservice/common/begin/client_map.gen.go

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

8 changes: 4 additions & 4 deletions pkg/networkservice/common/begin/server.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021-2022 Cisco and/or its affiliates.
// Copyright (c) 2021-2023 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -40,7 +40,7 @@ func NewServer() networkservice.NetworkServiceServer {
func (b *beginServer) Request(ctx context.Context, request *networkservice.NetworkServiceRequest) (conn *networkservice.Connection, err error) {
// No connection.ID, no service
if request.GetConnection().GetId() == "" {
return nil, errors.New("request.EventFactory.Id must not be zero valued")
return nil, errors.WithStack(errors.New("request.EventFactory.Id must not be zero valued"))
}
// If some other EventFactory is already in the ctx... we are already running in an executor, and can just execute normally
if fromContext(ctx) != nil {
Expand Down Expand Up @@ -78,7 +78,7 @@ func (b *beginServer) Request(ctx context.Context, request *networkservice.Netwo
eventFactoryServer.returnedConnection = conn.Clone()
eventFactoryServer.updateContext(ctx)
})
return conn, err
return conn, errors.WithStack(err)
}

func (b *beginServer) Close(ctx context.Context, conn *networkservice.Connection) (emp *emptypb.Empty, err error) {
Expand All @@ -105,5 +105,5 @@ func (b *beginServer) Close(ctx context.Context, conn *networkservice.Connection
emp, err = next.Server(withEventFactoryCtx).Close(withEventFactoryCtx, conn)
eventFactoryServer.afterCloseFunc()
})
return &emptypb.Empty{}, err
return &emptypb.Empty{}, errors.WithStack(err)
}
2 changes: 2 additions & 0 deletions pkg/networkservice/common/begin/server_map.gen.go

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

5 changes: 3 additions & 2 deletions pkg/networkservice/common/cleanup/client.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022 Cisco and/or its affiliates.
// Copyright (c) 2022-2023 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand All @@ -22,6 +22,7 @@ import (

"github.com/edwarnicke/serialize"
"github.com/golang/protobuf/ptypes/empty"
"github.com/pkg/errors"
"google.golang.org/grpc"

"github.com/networkservicemesh/api/pkg/api/networkservice"
Expand Down Expand Up @@ -69,7 +70,7 @@ func NewClient(ctx context.Context, opts ...Option) networkservice.NetworkServic
func (c *cleanupClient) Request(ctx context.Context, request *networkservice.NetworkServiceRequest, opts ...grpc.CallOption) (*networkservice.Connection, error) {
conn, err := next.Client(ctx).Request(ctx, request, opts...)
if err != nil {
return nil, err
return nil, errors.WithStack(err)
}
// Update active connections counter. Needed for a cleanup done notification.
atomic.AddInt32(&c.activeConns, 1)
Expand Down
5 changes: 4 additions & 1 deletion pkg/networkservice/common/clientconn/client.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) 2021 Cisco and/or its affiliates.
//
// Copyright (c) 2023 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -21,6 +23,7 @@ import (
"context"

"github.com/networkservicemesh/api/pkg/api/networkservice"
"github.com/pkg/errors"
"google.golang.org/grpc"
"google.golang.org/protobuf/types/known/emptypb"

Expand Down Expand Up @@ -53,5 +56,5 @@ func (c *clientConnClient) Close(ctx context.Context, conn *networkservice.Conne
Store(ctx, cc)
}
}
return &emptypb.Empty{}, err
return &emptypb.Empty{}, errors.WithStack(err)
}
8 changes: 5 additions & 3 deletions pkg/networkservice/common/connect/client.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) 2021 Cisco and/or its affiliates.
//
// Copyright (c) 2023 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -37,16 +39,16 @@ func NewClient() networkservice.NetworkServiceClient {
func (c *connectClient) Request(ctx context.Context, request *networkservice.NetworkServiceRequest, opts ...grpc.CallOption) (*networkservice.Connection, error) {
cc, loaded := clientconn.Load(ctx)
if !loaded {
return nil, errors.New("no grpc.ClientConnInterface provided")
return nil, errors.WithStack(errors.New("no grpc.ClientConnInterface provided"))
}
conn, err := networkservice.NewNetworkServiceClient(cc).Request(ctx, request, opts...)
return conn, err
return conn, errors.WithStack(err)
}

func (c *connectClient) Close(ctx context.Context, conn *networkservice.Connection, opts ...grpc.CallOption) (*emptypb.Empty, error) {
cc, loaded := clientconn.Load(ctx)
if !loaded {
return nil, errors.New("no grpc.ClientConnInterface provided")
return nil, errors.WithStack(errors.New("no grpc.ClientConnInterface provided"))
}
return networkservice.NewNetworkServiceClient(cc).Close(ctx, conn, opts...)
}
12 changes: 7 additions & 5 deletions pkg/networkservice/common/connect/server.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) 2021 Cisco and/or its affiliates.
//
// Copyright (c) 2023 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -48,7 +50,7 @@ func (c *connectServer) Request(ctx context.Context, request *networkservice.Net
closeCtxFunc := postpone.ContextWithValues(ctx)
clientConn, clientErr := c.client.Request(ctx, request, c.callOptions...)
if clientErr != nil {
return nil, clientErr
return nil, errors.WithStack(clientErr)
}
request.Connection = clientConn
serverConn, serverErr := next.Server(ctx).Request(ctx, request)
Expand All @@ -57,17 +59,17 @@ func (c *connectServer) Request(ctx context.Context, request *networkservice.Net
defer closeCancel()
_, _ = c.client.Close(closeCtx, clientConn, c.callOptions...)
}
return serverConn, serverErr
return serverConn, errors.WithStack(serverErr)
}

func (c *connectServer) Close(ctx context.Context, conn *networkservice.Connection) (*emptypb.Empty, error) {
_, clientErr := c.client.Close(ctx, conn, c.callOptions...)
_, serverErr := next.Server(ctx).Close(ctx, conn)
if clientErr != nil && serverErr != nil {
return nil, errors.Wrapf(serverErr, "errors during client close: %v", clientErr)
return nil, errors.WithStack(errors.Wrapf(serverErr, "errors during client close: %v", clientErr))
}
if clientErr != nil {
return nil, errors.Wrap(clientErr, "errors during client close")
return nil, errors.WithStack(errors.Wrap(clientErr, "errors during client close"))
}
return &empty.Empty{}, serverErr
return &empty.Empty{}, errors.WithStack(serverErr)
}
5 changes: 4 additions & 1 deletion pkg/networkservice/common/dial/client.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) 2021 Cisco and/or its affiliates.
//
// Copyright (c) 2023 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -24,6 +26,7 @@ import (
"time"

"github.com/networkservicemesh/api/pkg/api/networkservice"
"github.com/pkg/errors"
"google.golang.org/grpc"
"google.golang.org/protobuf/types/known/emptypb"

Expand Down Expand Up @@ -95,7 +98,7 @@ func (d *dialClient) Request(ctx context.Context, request *networkservice.Networ
conn, err := next.Client(ctx).Request(ctx, request, opts...)
if err != nil {
_ = di.Close()
return nil, err
return nil, errors.WithStack(err)
}
return conn, nil
}
Expand Down
Loading

0 comments on commit ef0c48e

Please sign in to comment.