From 70ff94a128c9a5c312f24881fd0aa1b0f89347ec Mon Sep 17 00:00:00 2001 From: Ruslan Bayandinov Date: Tue, 24 Jan 2023 13:09:45 +0000 Subject: [PATCH] adding stack to errors Signed-off-by: Ruslan Bayandinov --- go.mod | 8 ++--- go.sum | 16 +++++----- pkg/ipam/vl3ipam/server.go | 4 +-- .../chains/endpoint/combine_monitor_server.go | 8 +++-- pkg/networkservice/common/authorize/client.go | 10 +++--- pkg/networkservice/common/authorize/common.go | 5 ++- pkg/networkservice/common/begin/client.go | 8 ++--- .../common/begin/client_map.gen.go | 2 ++ pkg/networkservice/common/begin/server.go | 8 ++--- .../common/begin/server_map.gen.go | 2 ++ pkg/networkservice/common/cleanup/client.go | 5 +-- .../common/clientconn/client.go | 5 ++- pkg/networkservice/common/connect/client.go | 8 +++-- pkg/networkservice/common/connect/server.go | 12 ++++--- pkg/networkservice/common/dial/client.go | 5 ++- pkg/networkservice/common/dial/dialer.go | 12 ++++--- pkg/networkservice/common/discover/server.go | 12 +++---- .../common/discoverforwarder/server.go | 16 ++++++---- .../common/excludedprefixes/client.go | 14 ++++---- .../common/externalips/server.go | 4 ++- .../common/externalips/string_map.gen.go | 2 ++ pkg/networkservice/common/heal/client.go | 6 ++-- .../common/heal/client_filter.go | 5 +-- .../common/interdomainbypass/server.go | 7 ++-- pkg/networkservice/common/journal/server.go | 12 ++++--- .../common/mechanisms/client.go | 6 ++-- .../common/mechanisms/recvfd/client.go | 11 ++++--- .../common/mechanisms/recvfd/common.go | 4 +-- .../recvfd/per_connection_file_map.gen.go | 2 ++ .../common/mechanisms/recvfd/server.go | 7 ++-- .../common/mechanisms/sendfd/client.go | 7 ++-- .../common/mechanisms/sendfd/server.go | 7 ++-- .../common/mechanisms/server.go | 6 ++-- .../common/mechanisms/vxlan/vni/server.go | 9 ++++-- .../mechanisms/vxlan/vni/vni_map.gen.go | 2 ++ .../mechanismtranslation/mechanism_map.gen.go | 2 ++ .../connectioncontext/dnscontext/client.go | 13 +++++--- .../dnscontext/resolvconf.go | 6 ++-- .../dnscontext/vl3dns/server.go | 5 +-- .../connectioncontext/ipcontext/vl3/ipam.go | 6 ++-- .../connectioncontext/mtu/vl3mtu/server.go | 4 +-- .../core/adapters/monitor_client_to_server.go | 9 +++--- .../eventchannel/monitor_connection_client.go | 6 ++-- .../eventchannel/monitor_connection_server.go | 4 +-- .../core/eventchannel/monitor_server.go | 6 ++-- .../point2pointipam/connectionInfoMap.gen.go | 2 ++ .../ipam/point2pointipam/server.go | 10 +++--- .../singlepointipam/connectionInfoMap.gen.go | 2 ++ .../ipam/singlepointipam/server.go | 11 ++++--- .../utils/checks/checkconnection/client.go | 5 +-- .../checks/checkcontextonreturn/client.go | 7 ++-- .../utils/checks/checkerror/client.go | 11 ++++--- .../utils/checks/checkerror/server.go | 11 ++++--- .../utils/checks/checkresponse/client.go | 7 ++-- .../utils/checks/checkresponse/server.go | 5 +-- .../inject/injecterror/error_supplier.go | 6 +++- pkg/networkservice/utils/metadata/client.go | 5 +-- .../utils/metadata/meta_data_map.gen.go | 2 ++ pkg/networkservice/utils/metadata/server.go | 5 +-- pkg/registry/common/authorize/common.go | 5 +-- pkg/registry/common/authorize/ns_client.go | 8 ++--- pkg/registry/common/authorize/nse_client.go | 8 ++--- pkg/registry/common/authorize/sync_map.gen.go | 2 ++ pkg/registry/common/begin/ns_client.go | 8 ++--- .../common/begin/ns_client_map.gen.go | 2 ++ pkg/registry/common/begin/ns_server.go | 8 ++--- .../common/begin/ns_server_map.gen.go | 2 ++ pkg/registry/common/begin/nse_client.go | 8 ++--- .../common/begin/nse_client_map.gen.go | 2 ++ pkg/registry/common/begin/nse_server.go | 8 ++--- .../common/begin/nse_server_map.gen.go | 2 ++ pkg/registry/common/clientconn/map.gen.go | 2 ++ pkg/registry/common/connect/ns_client.go | 9 +++--- pkg/registry/common/connect/ns_server.go | 16 +++++----- pkg/registry/common/connect/nse_client.go | 8 ++--- pkg/registry/common/connect/nse_server.go | 14 ++++---- pkg/registry/common/dial/dialer.go | 10 +++--- pkg/registry/common/dial/ns_client.go | 9 +++--- pkg/registry/common/dial/nse_client.go | 9 +++--- pkg/registry/common/dnsresolve/common.go | 16 +++++++--- pkg/registry/common/dnsresolve/ns_client.go | 16 +++++----- pkg/registry/common/dnsresolve/nse_client.go | 13 ++++---- .../common/endpointurls/sync_map.gen.go | 2 ++ pkg/registry/common/expire/nse_server.go | 5 ++- pkg/registry/common/expire/sync_map.gen.go | 2 ++ pkg/registry/common/grpcmetadata/common.go | 16 +++++----- pkg/registry/common/grpcmetadata/ns_client.go | 7 ++-- pkg/registry/common/grpcmetadata/ns_server.go | 7 ++-- .../common/grpcmetadata/nse_client.go | 7 ++-- .../common/grpcmetadata/nse_server.go | 7 ++-- pkg/registry/common/heal/ns_client.go | 11 ++++--- pkg/registry/common/heal/ns_find_client.go | 9 ++++-- pkg/registry/common/heal/nse_client.go | 11 ++++--- pkg/registry/common/heal/nse_find_client.go | 9 ++++-- pkg/registry/common/heal/sync_map.gen.go | 2 ++ .../common/interdomainbypass/server.go | 9 +++--- pkg/registry/common/localbypass/server.go | 10 +++--- pkg/registry/common/memory/ns_server.go | 15 +++++---- pkg/registry/common/memory/ns_sync_map.gen.go | 2 ++ pkg/registry/common/memory/nse_server.go | 19 ++++++----- .../common/memory/nse_sync_map.gen.go | 2 ++ .../common/querycache/cache_entry_map.gen.go | 2 ++ pkg/registry/common/querycache/nse_client.go | 5 ++- pkg/registry/common/recvfd/client.go | 9 +++--- .../recvfd/per_endpoint_file_map.gen.go | 2 ++ pkg/registry/common/recvfd/server.go | 4 +-- .../common/refresh/nse_registry_client.go | 7 ++-- pkg/registry/common/refresh/sync_map.gen.go | 2 ++ pkg/registry/common/retry/ns_client.go | 29 +++++++++-------- pkg/registry/common/retry/nse_client.go | 11 ++++--- pkg/registry/common/sendfd/client_linux.go | 8 ++--- pkg/registry/common/swapip/nse_registry.go | 5 ++- pkg/registry/common/updatepath/common.go | 14 ++++---- pkg/registry/common/updatepath/ns_server.go | 12 +++---- pkg/registry/core/adapters/ns_next_client.go | 6 +++- pkg/registry/core/adapters/ns_registry.go | 12 ++++--- pkg/registry/core/adapters/nse_registry.go | 12 ++++--- .../ns_registry_stream_channel.go | 8 +++-- .../nse_registry_stream_channel.go | 6 ++-- pkg/registry/core/trace/common.go | 6 ++-- pkg/registry/core/trace/ns_registry.go | 20 ++++++------ pkg/registry/core/trace/nse_registry.go | 20 ++++++------ .../inject/injecterror/error_supplier.go | 6 +++- pkg/tools/awarenessgroups/config_decoder.go | 20 ++++++------ pkg/tools/cidr/group.go | 18 +++++------ pkg/tools/clientmap/clientmap.gen.go | 2 ++ pkg/tools/debug/self.go | 14 ++++---- pkg/tools/dnsconfig/config_decoder.go | 5 +-- pkg/tools/dnsconfig/sync_map.gen.go | 2 ++ pkg/tools/dnsutils/cache/sync_map.gen.go | 2 ++ pkg/tools/dnsutils/memory/sync_map.gen.go | 2 ++ pkg/tools/fs/inode.go | 6 ++-- pkg/tools/fs/inode_windows_amd64.go | 6 ++-- pkg/tools/grpcfdutils/transceiver.go | 8 +++-- pkg/tools/ippool/ippool.go | 15 +++++---- pkg/tools/ippool/prefixpool.go | 12 +++++-- pkg/tools/matchutils/utils.go | 4 ++- .../monitorconnection/authorize/common.go | 6 ++-- pkg/tools/opa/opainput.go | 8 +++-- pkg/tools/opa/policies.go | 6 ++-- pkg/tools/opa/policy.go | 20 ++++++------ pkg/tools/prefixpool/prefixpool.go | 32 +++++++++---------- pkg/tools/spiffejwt/token.go | 8 +++-- .../spire/spiffe_id_connection_map.gen.go | 5 +-- pkg/tools/spire/start.go | 23 ++++++------- pkg/tools/stringset/gen.go | 3 +- pkg/tools/stringset/sync_map.gen.go | 2 ++ pkg/tools/stringurl/sync_map.gen.go | 2 ++ pkg/tools/token/context.go | 4 ++- pkg/tools/token/creds.go | 7 ++-- 150 files changed, 709 insertions(+), 483 deletions(-) diff --git a/go.mod b/go.mod index 39476f7297..abae259fc2 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 diff --git a/go.sum b/go.sum index 2283bd8034..e423f3980d 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= @@ -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= @@ -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= diff --git a/pkg/ipam/vl3ipam/server.go b/pkg/ipam/vl3ipam/server.go index d8bcb946b5..1f319d05a4 100644 --- a/pkg/ipam/vl3ipam/server.go +++ b/pkg/ipam/vl3ipam/server.go @@ -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 // @@ -123,5 +123,5 @@ func (s *vl3IPAMServer) ManagePrefixes(prefixServer ipam.IPAM_ManagePrefixesServ return nil } - return err + return errors.WithStack(err) } diff --git a/pkg/networkservice/chains/endpoint/combine_monitor_server.go b/pkg/networkservice/chains/endpoint/combine_monitor_server.go index 60098f4c45..177b6bde81 100644 --- a/pkg/networkservice/chains/endpoint/combine_monitor_server.go +++ b/pkg/networkservice/chains/endpoint/combine_monitor_server.go @@ -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"); @@ -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( @@ -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)) } } diff --git a/pkg/networkservice/common/authorize/client.go b/pkg/networkservice/common/authorize/client.go index 61ab450a63..66be395c4c 100644 --- a/pkg/networkservice/common/authorize/client.go +++ b/pkg/networkservice/common/authorize/client.go @@ -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 // @@ -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{}) { @@ -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) { @@ -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...) diff --git a/pkg/networkservice/common/authorize/common.go b/pkg/networkservice/common/authorize/common.go index 49a0f91490..54268bf99b 100644 --- a/pkg/networkservice/common/authorize/common.go +++ b/pkg/networkservice/common/authorize/common.go @@ -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"); @@ -20,6 +22,7 @@ import ( "context" "github.com/networkservicemesh/api/pkg/api/networkservice" + "github.com/pkg/errors" ) // Policy represents authorization policy for network service. @@ -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 diff --git a/pkg/networkservice/common/begin/client.go b/pkg/networkservice/common/begin/client.go index 78c389c3da..039d1ee1d0 100644 --- a/pkg/networkservice/common/begin/client.go +++ b/pkg/networkservice/common/begin/client.go @@ -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 // @@ -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 { @@ -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) { @@ -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) } diff --git a/pkg/networkservice/common/begin/client_map.gen.go b/pkg/networkservice/common/begin/client_map.gen.go index 0a036c54e5..41410c7b00 100644 --- a/pkg/networkservice/common/begin/client_map.gen.go +++ b/pkg/networkservice/common/begin/client_map.gen.go @@ -1,4 +1,6 @@ // Code generated by "-output client_map.gen.go -type clientMap -output client_map.gen.go -type clientMap"; DO NOT EDIT. +// Install -output client_map.gen.go -type clientMap by "go get -u github.com/searKing/golang/tools/-output client_map.gen.go -type clientMap" + package begin import ( diff --git a/pkg/networkservice/common/begin/server.go b/pkg/networkservice/common/begin/server.go index aa465ea1de..3bde11489f 100644 --- a/pkg/networkservice/common/begin/server.go +++ b/pkg/networkservice/common/begin/server.go @@ -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 // @@ -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 { @@ -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) { @@ -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) } diff --git a/pkg/networkservice/common/begin/server_map.gen.go b/pkg/networkservice/common/begin/server_map.gen.go index 3eea2f62bf..40e006cf96 100644 --- a/pkg/networkservice/common/begin/server_map.gen.go +++ b/pkg/networkservice/common/begin/server_map.gen.go @@ -1,4 +1,6 @@ // Code generated by "-output server_map.gen.go -type serverMap -output server_map.gen.go -type serverMap"; DO NOT EDIT. +// Install -output server_map.gen.go -type serverMap by "go get -u github.com/searKing/golang/tools/-output server_map.gen.go -type serverMap" + package begin import ( diff --git a/pkg/networkservice/common/cleanup/client.go b/pkg/networkservice/common/cleanup/client.go index 5a8ed2a7c0..de9a662929 100644 --- a/pkg/networkservice/common/cleanup/client.go +++ b/pkg/networkservice/common/cleanup/client.go @@ -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 // @@ -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" @@ -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) diff --git a/pkg/networkservice/common/clientconn/client.go b/pkg/networkservice/common/clientconn/client.go index de4d9ef6c5..830cdffc7c 100644 --- a/pkg/networkservice/common/clientconn/client.go +++ b/pkg/networkservice/common/clientconn/client.go @@ -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"); @@ -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" @@ -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) } diff --git a/pkg/networkservice/common/connect/client.go b/pkg/networkservice/common/connect/client.go index cb632eca1c..35d19c8429 100644 --- a/pkg/networkservice/common/connect/client.go +++ b/pkg/networkservice/common/connect/client.go @@ -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"); @@ -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...) } diff --git a/pkg/networkservice/common/connect/server.go b/pkg/networkservice/common/connect/server.go index 6f634b2c80..81e19da848 100644 --- a/pkg/networkservice/common/connect/server.go +++ b/pkg/networkservice/common/connect/server.go @@ -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"); @@ -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) @@ -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) } diff --git a/pkg/networkservice/common/dial/client.go b/pkg/networkservice/common/dial/client.go index dc8d746c12..bab18e051a 100644 --- a/pkg/networkservice/common/dial/client.go +++ b/pkg/networkservice/common/dial/client.go @@ -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"); @@ -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" @@ -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 } diff --git a/pkg/networkservice/common/dial/dialer.go b/pkg/networkservice/common/dial/dialer.go index bf988279ea..1dfc1fba65 100644 --- a/pkg/networkservice/common/dial/dialer.go +++ b/pkg/networkservice/common/dial/dialer.go @@ -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"); @@ -49,7 +51,7 @@ func newDialer(ctx context.Context, dialTimeout time.Duration, dialOptions ...gr func (di *dialer) Dial(ctx context.Context, clientURL *url.URL) error { if di == nil { - return errors.New("cannot call dialer.Dial on nil dialer") + return errors.WithStack(errors.New("cannot call dialer.Dial on nil dialer")) } // Cleanup any previous grpc.ClientConn if di.cleanupCancel != nil { @@ -72,7 +74,7 @@ func (di *dialer) Dial(ctx context.Context, clientURL *url.URL) error { if cc != nil { _ = cc.Close() } - return errors.Wrapf(err, "failed to dial %s", target) + return errors.WithStack(errors.Wrapf(err, "failed to dial %s", target)) } di.ClientConn = cc @@ -95,14 +97,14 @@ func (di *dialer) Close() error { func (di *dialer) Invoke(ctx context.Context, method string, args, reply interface{}, opts ...grpc.CallOption) error { if di.ClientConn == nil { - return errors.New("no dialer.ClientConn found") + return errors.WithStack(errors.New("no dialer.ClientConn found")) } - return di.ClientConn.Invoke(ctx, method, args, reply, opts...) + return errors.WithStack(di.ClientConn.Invoke(ctx, method, args, reply, opts...)) } func (di *dialer) NewStream(ctx context.Context, desc *grpc.StreamDesc, method string, opts ...grpc.CallOption) (grpc.ClientStream, error) { if di.ClientConn == nil { - return nil, errors.New("no dialer.ClientConn found") + return nil, errors.WithStack(errors.New("no dialer.ClientConn found")) } return di.ClientConn.NewStream(ctx, desc, method, opts...) } diff --git a/pkg/networkservice/common/discover/server.go b/pkg/networkservice/common/discover/server.go index 46ff375b51..7e6f82103e 100644 --- a/pkg/networkservice/common/discover/server.go +++ b/pkg/networkservice/common/discover/server.go @@ -1,7 +1,7 @@ -// Copyright (c) 2020-2022 Cisco Systems, Inc. -// // Copyright (c) 2021-2022 Doc.ai and/or its affiliates. // +// Copyright (c) 2020-2023 Cisco Systems, Inc. +// // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -90,7 +90,7 @@ func (d *discoverCandidatesServer) Close(ctx context.Context, conn *networkservi nseName := conn.GetNetworkServiceEndpointName() if nseName == "" { // If it's an existing connection, the NSE name should be set. Otherwise, it's probably an API misuse. - return nil, errors.Errorf("network_service_endpoint_name is not set") + return nil, errors.WithStack(errors.Errorf("network_service_endpoint_name is not set")) } var u *url.URL @@ -126,7 +126,7 @@ func (d *discoverCandidatesServer) discoverNetworkServiceEndpoint(ctx context.Co } } - return nil, errors.Errorf("network service endpoint %v not found", nseName) + return nil, errors.WithStack(errors.Errorf("network service endpoint %v not found", nseName)) } func (d *discoverCandidatesServer) discoverNetworkServiceEndpoints(ctx context.Context, ns *registry.NetworkService, nsLabels map[string]string) ([]*registry.NetworkServiceEndpoint, error) { @@ -149,7 +149,7 @@ func (d *discoverCandidatesServer) discoverNetworkServiceEndpoints(ctx context.C return result, nil } - return nil, errors.New("network service endpoint candidates not found") + return nil, errors.WithStack(errors.New("network service endpoint candidates not found")) } func (d *discoverCandidatesServer) discoverNetworkService(ctx context.Context, name, payload string) (*registry.NetworkService, error) { @@ -172,5 +172,5 @@ func (d *discoverCandidatesServer) discoverNetworkService(ctx context.Context, n } } - return nil, errors.Errorf("network service %v is not found", name) + return nil, errors.WithStack(errors.Errorf("network service %v is not found", name)) } diff --git a/pkg/networkservice/common/discoverforwarder/server.go b/pkg/networkservice/common/discoverforwarder/server.go index 68635fae5e..dd69343e48 100644 --- a/pkg/networkservice/common/discoverforwarder/server.go +++ b/pkg/networkservice/common/discoverforwarder/server.go @@ -1,5 +1,7 @@ // Copyright (c) 2021-2022 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"); @@ -90,7 +92,7 @@ func (d *discoverForwarderServer) Request(ctx context.Context, request *networks nses := d.matchForwarders(request.Connection.GetLabels(), ns, registry.ReadNetworkServiceEndpointList(stream)) if len(nses) == 0 { - return nil, errors.New("no candidates found") + return nil, errors.WithStack(errors.New("no candidates found")) } segments := request.Connection.GetPath().GetPathSegments() @@ -126,7 +128,7 @@ func (d *discoverForwarderServer) Request(ctx context.Context, request *networks candidatesErr = errors.Wrapf(candidatesErr, "%v. An error during select forwawrder %v --> %v", i, candidate.Name, err.Error()) } - return nil, candidatesErr + return nil, errors.WithStack(candidatesErr) } stream, err := d.nseClient.Find(ctx, ®istry.NetworkServiceEndpointQuery{ NetworkServiceEndpoint: ®istry.NetworkServiceEndpoint{ @@ -144,7 +146,7 @@ func (d *discoverForwarderServer) Request(ctx context.Context, request *networks if len(nses) == 0 { storeForwarderName(ctx, "") - return nil, errors.New("forwarder not found") + return nil, errors.WithStack(errors.New("forwarder not found")) } u, err := url.Parse(nses[0].Url) @@ -158,7 +160,7 @@ func (d *discoverForwarderServer) Request(ctx context.Context, request *networks if err != nil { storeForwarderName(ctx, "") } - return conn, err + return conn, errors.WithStack(err) } func (d *discoverForwarderServer) Close(ctx context.Context, conn *networkservice.Connection) (*empty.Empty, error) { @@ -166,7 +168,7 @@ func (d *discoverForwarderServer) Close(ctx context.Context, conn *networkservic var logger = log.FromContext(ctx).WithField("discoverForwarderServer", "request") if forwarderName == "" { - return nil, errors.New("forwarder is not selected") + return nil, errors.WithStack(errors.New("forwarder is not selected")) } stream, err := d.nseClient.Find(ctx, ®istry.NetworkServiceEndpointQuery{ @@ -184,7 +186,7 @@ func (d *discoverForwarderServer) Close(ctx context.Context, conn *networkservic nses := registry.ReadNetworkServiceEndpointList(stream) if len(nses) == 0 { - return nil, errors.New("forwarder not found") + return nil, errors.WithStack(errors.New("forwarder not found")) } u, err := url.Parse(nses[0].Url) @@ -257,5 +259,5 @@ func (d *discoverForwarderServer) discoverNetworkService(ctx context.Context, na } } - return nil, errors.Errorf("network service %v is not found", name) + return nil, errors.WithStack(errors.Errorf("network service %v is not found", name)) } diff --git a/pkg/networkservice/common/excludedprefixes/client.go b/pkg/networkservice/common/excludedprefixes/client.go index fb7516f166..d389b181ec 100644 --- a/pkg/networkservice/common/excludedprefixes/client.go +++ b/pkg/networkservice/common/excludedprefixes/client.go @@ -1,5 +1,7 @@ // Copyright (c) 2021-2022 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"); @@ -113,7 +115,7 @@ func (epc *excludedPrefixesClient) Request(ctx context.Context, request *network resp, err := next.Client(ctx).Request(ctx, request, opts...) if err != nil { ipCtx.ExcludedPrefixes = oldExcludedPrefixes - return resp, err + return resp, errors.WithStack(err) } respIPContext := resp.GetContext().GetIpContext() @@ -127,7 +129,7 @@ func (epc *excludedPrefixesClient) Request(ctx context.Context, request *network respIPContext.GetSrcIpAddrs(), respIPContext.GetDstIpAddrs(), newExcludedPrefixes, err.Error()) 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 @@ -158,7 +160,7 @@ func (epc *excludedPrefixesClient) Request(ctx context.Context, request *network ipCtx.ExcludedPrefixes = oldExcludedPrefixes - return resp, err + return resp, errors.WithStack(err) } func (epc *excludedPrefixesClient) Close(ctx context.Context, conn *networkservice.Connection, opts ...grpc.CallOption) (*empty.Empty, error) { @@ -207,7 +209,7 @@ func validateIPs(ipContext *networkservice.IPContext, excludedPrefixes []string) for _, prefix := range excludedPrefixes { _, ipNet, err := net.ParseCIDR(prefix) if err != nil { - return err + return errors.WithStack(err) } // TODO: Think about validating routes with prefixes size less than /32 and /128 if prefixLen, maxLen := ipNet.Mask.Size(); prefixLen != maxLen { @@ -225,11 +227,11 @@ func validateIPs(ipContext *networkservice.IPContext, excludedPrefixes []string) for _, prefix := range prefixes { ip, _, err := net.ParseCIDR(prefix) if err != nil { - return err + return errors.WithStack(err) } if ip4Pool.Contains(ip) || ip6Pool.Contains(ip) { - return errors.Errorf("IP %v is excluded, but it was found in response IPs", ip) + return errors.WithStack(errors.Errorf("IP %v is excluded, but it was found in response IPs", ip)) } } diff --git a/pkg/networkservice/common/externalips/server.go b/pkg/networkservice/common/externalips/server.go index 3c12f61737..f9e892ea47 100644 --- a/pkg/networkservice/common/externalips/server.go +++ b/pkg/networkservice/common/externalips/server.go @@ -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"); @@ -97,7 +99,7 @@ func replaceFunc(v atomic.Value) func(ip net.IP) net.IP { func (e *externalIPsServer) build(ips map[string]string) error { validate := func(s string) error { if ip := net.ParseIP(s); ip == nil { - return errors.Errorf("%v is not IP", ip) + return errors.WithStack(errors.Errorf("%v is not IP", ip)) } return nil } diff --git a/pkg/networkservice/common/externalips/string_map.gen.go b/pkg/networkservice/common/externalips/string_map.gen.go index c561806783..2ac1a810f7 100644 --- a/pkg/networkservice/common/externalips/string_map.gen.go +++ b/pkg/networkservice/common/externalips/string_map.gen.go @@ -1,4 +1,6 @@ // Code generated by "-output string_map.gen.go -type stringMap -output string_map.gen.go -type stringMap"; DO NOT EDIT. +// Install -output string_map.gen.go -type stringMap by "go get -u github.com/searKing/golang/tools/-output string_map.gen.go -type stringMap" + package externalips import ( diff --git a/pkg/networkservice/common/heal/client.go b/pkg/networkservice/common/heal/client.go index f763d0c45a..5e76091b02 100644 --- a/pkg/networkservice/common/heal/client.go +++ b/pkg/networkservice/common/heal/client.go @@ -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 // @@ -64,7 +64,7 @@ func (h *healClient) Request(ctx context.Context, request *networkservice.Networ conn, err := next.Client(ctx).Request(ctx, request, opts...) if err != nil { - return nil, err + return nil, errors.WithStack(err) } cc, ccLoaded := clientconn.Load(ctx) if ccLoaded { @@ -74,7 +74,7 @@ func (h *healClient) Request(ctx context.Context, request *networkservice.Networ closeCtx, closeCancel := closeCtxFunc() defer closeCancel() _, _ = next.Client(closeCtx).Close(closeCtx, conn) - return nil, errors.Wrap(eventLoopErr, "unable to monitor") + return nil, errors.WithStack(errors.Wrap(eventLoopErr, "unable to monitor")) } store(ctx, cancelEventLoop) } diff --git a/pkg/networkservice/common/heal/client_filter.go b/pkg/networkservice/common/heal/client_filter.go index 73f19884e5..c3e5636de8 100644 --- a/pkg/networkservice/common/heal/client_filter.go +++ b/pkg/networkservice/common/heal/client_filter.go @@ -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 // @@ -18,6 +18,7 @@ package heal import ( "github.com/networkservicemesh/api/pkg/api/networkservice" + "github.com/pkg/errors" "github.com/networkservicemesh/sdk/pkg/tools/log" ) @@ -43,7 +44,7 @@ func (c *clientFilter) Recv() (*networkservice.ConnectionEvent, error) { eventIn, err := c.MonitorConnection_MonitorConnectionsClient.Recv() c.logger.Debugf("received eventIn: %v, err: %v", eventIn.String(), err) if err != nil { - return nil, err + return nil, errors.WithStack(err) } eventOut := &networkservice.ConnectionEvent{ Type: networkservice.ConnectionEventType_UPDATE, diff --git a/pkg/networkservice/common/interdomainbypass/server.go b/pkg/networkservice/common/interdomainbypass/server.go index 10d13651d8..56eddff8a0 100644 --- a/pkg/networkservice/common/interdomainbypass/server.go +++ b/pkg/networkservice/common/interdomainbypass/server.go @@ -1,5 +1,7 @@ // Copyright (c) 2021-2022 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"); @@ -24,6 +26,7 @@ import ( "github.com/golang/protobuf/ptypes/empty" "github.com/networkservicemesh/api/pkg/api/networkservice" "github.com/networkservicemesh/api/pkg/api/registry" + "github.com/pkg/errors" "github.com/networkservicemesh/sdk/pkg/networkservice/core/next" "github.com/networkservicemesh/sdk/pkg/registry/common/interdomainbypass" @@ -57,7 +60,7 @@ func (n *interdomainBypassServer) Request(ctx context.Context, request *networks request.GetConnection().NetworkService = interdomain.Target(originalNS) resp, err := next.Server(ctx).Request(ctx, request) if err != nil { - return nil, err + return nil, errors.WithStack(err) } resp.NetworkServiceEndpointName = originalNSEName resp.NetworkService = originalNS @@ -78,7 +81,7 @@ func (n *interdomainBypassServer) Close(ctx context.Context, conn *networkservic conn.NetworkService = interdomain.Target(originalNS) resp, err := next.Server(ctx).Close(ctx, conn) if err != nil { - return nil, err + return nil, errors.WithStack(err) } conn.NetworkServiceEndpointName = originalNSEName conn.NetworkService = originalNS diff --git a/pkg/networkservice/common/journal/server.go b/pkg/networkservice/common/journal/server.go index f6dee3ac58..98c4e165ab 100644 --- a/pkg/networkservice/common/journal/server.go +++ b/pkg/networkservice/common/journal/server.go @@ -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"); @@ -22,13 +24,13 @@ package journal import ( "context" "encoding/json" - "errors" "strings" "time" "github.com/golang/protobuf/ptypes/empty" stan "github.com/nats-io/stan.go" "github.com/networkservicemesh/api/pkg/api/networkservice" + "github.com/pkg/errors" "github.com/networkservicemesh/sdk/pkg/networkservice/core/next" "github.com/networkservicemesh/sdk/pkg/tools/clock" @@ -60,7 +62,7 @@ func (srv *journalServer) Request(ctx context.Context, request *networkservice.N conn, err := next.Server(ctx).Request(ctx, request) if err != nil { - return conn, err + return conn, errors.WithStack(err) } src := conn.GetContext().GetIpContext().GetSrcIpAddrs() @@ -101,12 +103,12 @@ func (srv *journalServer) Close(ctx context.Context, connection *networkservice. func (srv *journalServer) publish(entry *Entry) error { js, err := json.Marshal(entry) if err != nil { - return err + return errors.WithStack(err) } err = srv.nats.Publish(srv.journalID, js) if err != nil { - return err + return errors.WithStack(err) } return nil } @@ -114,7 +116,7 @@ func (srv *journalServer) publish(entry *Entry) error { // NewServer creates a new journaling server with the name journalID using provided streaming NATS connection func NewServer(journalID string, stanConn stan.Conn) (networkservice.NetworkServiceServer, error) { if strings.TrimSpace(journalID) == "" { - return nil, errors.New("journal id is nil") + return nil, errors.WithStack(errors.New("journal id is nil")) } return &journalServer{ journalID: journalID, diff --git a/pkg/networkservice/common/mechanisms/client.go b/pkg/networkservice/common/mechanisms/client.go index fc7ae74465..a5b3683054 100644 --- a/pkg/networkservice/common/mechanisms/client.go +++ b/pkg/networkservice/common/mechanisms/client.go @@ -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"); @@ -49,7 +51,7 @@ func (mc *mechanismsClient) Request(ctx context.Context, request *networkservice if ok { return srv.Request(ctx, request, opts...) } - return nil, errUnsupportedMech + return nil, errors.WithStack(errUnsupportedMech) } var err = errCannotSupportMech for _, mechanism := range request.GetMechanismPreferences() { @@ -64,7 +66,7 @@ func (mc *mechanismsClient) Request(ctx context.Context, request *networkservice err = errors.Wrap(err, respErr.Error()) } } - return nil, err + return nil, errors.WithStack(err) } func (mc *mechanismsClient) Close(ctx context.Context, conn *networkservice.Connection, opts ...grpc.CallOption) (*empty.Empty, error) { diff --git a/pkg/networkservice/common/mechanisms/recvfd/client.go b/pkg/networkservice/common/mechanisms/recvfd/client.go index 494a087a52..99067b9e48 100644 --- a/pkg/networkservice/common/mechanisms/recvfd/client.go +++ b/pkg/networkservice/common/mechanisms/recvfd/client.go @@ -1,7 +1,7 @@ -// Copyright (c) 2020-2022 Cisco and/or its affiliates. -// // Copyright (c) 2021-2022 Doc.ai and/or its affiliates. // +// Copyright (c) 2020-2023 Cisco and/or its affiliates. +// // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -28,6 +28,7 @@ import ( "github.com/golang/protobuf/ptypes/empty" "github.com/networkservicemesh/api/pkg/api/networkservice" + "github.com/pkg/errors" "google.golang.org/grpc" "github.com/edwarnicke/grpcfd" @@ -55,7 +56,7 @@ func (r *recvFDClient) Request(ctx context.Context, request *networkservice.Netw // Call the next Client in the chain conn, err := next.Client(ctx).Request(ctx, request, opts...) if err != nil { - return nil, err + return nil, errors.WithStack(err) } // Get the fileMap @@ -100,13 +101,13 @@ func (r *recvFDClient) Close(ctx context.Context, conn *networkservice.Connectio // Call the next Client in the chain _, err := next.Client(ctx).Close(ctx, conn, opts...) if err != nil { - return nil, err + return nil, errors.WithStack(err) } // Recv the FD and swap theInode to File in the Parameters for the returned connection mechanism err = recvFDAndSwapInodeToFile(ctx, fileMap, conn.GetMechanism().GetParameters(), recv) if err != nil { - return nil, err + return nil, errors.WithStack(err) } return &empty.Empty{}, nil diff --git a/pkg/networkservice/common/mechanisms/recvfd/common.go b/pkg/networkservice/common/mechanisms/recvfd/common.go index bbb3b37138..9598143138 100644 --- a/pkg/networkservice/common/mechanisms/recvfd/common.go +++ b/pkg/networkservice/common/mechanisms/recvfd/common.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020-2022 Cisco and/or its affiliates. +// Copyright (c) 2020-2023 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -84,7 +84,7 @@ func recvFDAndSwapInodeToFile(ctx context.Context, fileMap *perConnectionFileMap // Remember the swap so we can undo it later fileMap.inodeURLbyFilename[file.Name()] = inodeURL }) - return err + return errors.WithStack(err) } func swapFileToInode(fileMap *perConnectionFileMap, parameters map[string]string) error { diff --git a/pkg/networkservice/common/mechanisms/recvfd/per_connection_file_map.gen.go b/pkg/networkservice/common/mechanisms/recvfd/per_connection_file_map.gen.go index b43f44eea4..534ea63e1e 100644 --- a/pkg/networkservice/common/mechanisms/recvfd/per_connection_file_map.gen.go +++ b/pkg/networkservice/common/mechanisms/recvfd/per_connection_file_map.gen.go @@ -1,4 +1,6 @@ // Code generated by "-output per_connection_file_map.gen.go -type perConnectionFileMapMap -output per_connection_file_map.gen.go -type perConnectionFileMapMap"; DO NOT EDIT. +// Install -output per_connection_file_map.gen.go -type perConnectionFileMapMap by "go get -u github.com/searKing/golang/tools/-output per_connection_file_map.gen.go -type perConnectionFileMapMap" + package recvfd import ( diff --git a/pkg/networkservice/common/mechanisms/recvfd/server.go b/pkg/networkservice/common/mechanisms/recvfd/server.go index 8b6001e9d9..9c5069bed2 100644 --- a/pkg/networkservice/common/mechanisms/recvfd/server.go +++ b/pkg/networkservice/common/mechanisms/recvfd/server.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020-2022 Cisco and/or its affiliates. +// Copyright (c) 2020-2023 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -26,6 +26,7 @@ import ( "github.com/golang/protobuf/ptypes/empty" "github.com/networkservicemesh/api/pkg/api/networkservice" + "github.com/pkg/errors" "github.com/edwarnicke/grpcfd" @@ -66,7 +67,7 @@ func (r *recvFDServer) Request(ctx context.Context, request *networkservice.Netw // Call the next server in the chain conn, err := next.Server(ctx).Request(ctx, request) if err != nil { - return nil, err + return nil, errors.WithStack(err) } // Swap back from File to Inode in the InodeURL in the Parameters @@ -103,7 +104,7 @@ func (r *recvFDServer) Close(ctx context.Context, conn *networkservice.Connectio // Call the next server in the chain _, err = next.Server(ctx).Close(ctx, conn) if err != nil { - return nil, err + return nil, errors.WithStack(err) } // Swap back from File to Inode in the InodeURL in the Parameters diff --git a/pkg/networkservice/common/mechanisms/sendfd/client.go b/pkg/networkservice/common/mechanisms/sendfd/client.go index fd4d76d94c..aab5a6bfa3 100644 --- a/pkg/networkservice/common/mechanisms/sendfd/client.go +++ b/pkg/networkservice/common/mechanisms/sendfd/client.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020-2022 Cisco and/or its affiliates. +// Copyright (c) 2020-2023 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -26,6 +26,7 @@ import ( "github.com/golang/protobuf/ptypes/empty" "github.com/networkservicemesh/api/pkg/api/networkservice" "github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/common" + "github.com/pkg/errors" "google.golang.org/grpc" "github.com/networkservicemesh/sdk/pkg/networkservice/core/next" @@ -54,7 +55,7 @@ func (s *sendFDClient) Request(ctx context.Context, request *networkservice.Netw // Call the next Client in the chain conn, err := next.Client(ctx).Request(ctx, request, opts...) if err != nil { - return nil, err + return nil, errors.WithStack(err) } // Is we don't have a InodeURL Parameter on the selected Mechanism... we don't need to translate it back if conn.GetMechanism().GetParameters() == nil || conn.GetMechanism().GetParameters()[common.InodeURL] == "" { @@ -81,7 +82,7 @@ func (s *sendFDClient) Close(ctx context.Context, conn *networkservice.Connectio // Call the next Client in the chain _, err := next.Client(ctx).Close(ctx, conn, opts...) if err != nil { - return nil, err + return nil, errors.WithStack(err) } // Translate the InodeURl mechanism *back to a proper file://${path} url diff --git a/pkg/networkservice/common/mechanisms/sendfd/server.go b/pkg/networkservice/common/mechanisms/sendfd/server.go index f5825f04aa..bb5580df47 100644 --- a/pkg/networkservice/common/mechanisms/sendfd/server.go +++ b/pkg/networkservice/common/mechanisms/sendfd/server.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020-2022 Cisco and/or its affiliates. +// Copyright (c) 2020-2023 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -25,6 +25,7 @@ import ( "github.com/edwarnicke/grpcfd" "github.com/golang/protobuf/ptypes/empty" "github.com/networkservicemesh/api/pkg/api/networkservice" + "github.com/pkg/errors" "github.com/networkservicemesh/sdk/pkg/networkservice/core/next" ) @@ -40,7 +41,7 @@ func (s sendFDServer) Request(ctx context.Context, request *networkservice.Netwo // Call the next server chain element in the chain conn, err := next.Server(ctx).Request(ctx, request) if err != nil { - return nil, err + return nil, errors.WithStack(err) } // Get the grpcfd.FDSender @@ -61,7 +62,7 @@ func (s sendFDServer) Close(ctx context.Context, conn *networkservice.Connection // Call the next server chain element in the chain _, err := next.Server(ctx).Close(ctx, conn) if err != nil { - return nil, err + return nil, errors.WithStack(err) } sender, ok := grpcfd.FromContext(ctx) diff --git a/pkg/networkservice/common/mechanisms/server.go b/pkg/networkservice/common/mechanisms/server.go index 96d786f1b7..23ebe0a391 100644 --- a/pkg/networkservice/common/mechanisms/server.go +++ b/pkg/networkservice/common/mechanisms/server.go @@ -1,6 +1,6 @@ // Copyright (c) 2021 Doc.ai and/or its affiliates. // -// Copyright (c) 2020-2022 Cisco and/or its affiliates. +// Copyright (c) 2020-2023 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -59,7 +59,7 @@ func (ms *mechanismsServer) Request(ctx context.Context, request *networkservice if ok { return srv.Request(ctx, request) } - return nil, errUnsupportedMech + return nil, errors.WithStack(errUnsupportedMech) } var err = errCannotSupportMech for _, mechanism := range request.GetMechanismPreferences() { @@ -75,7 +75,7 @@ func (ms *mechanismsServer) Request(ctx context.Context, request *networkservice err = errors.Wrap(err, respErr.Error()) } } - return nil, err + return nil, errors.WithStack(err) } func (ms *mechanismsServer) Close(ctx context.Context, conn *networkservice.Connection) (*empty.Empty, error) { diff --git a/pkg/networkservice/common/mechanisms/vxlan/vni/server.go b/pkg/networkservice/common/mechanisms/vxlan/vni/server.go index dc373f5fad..112b4ef86c 100644 --- a/pkg/networkservice/common/mechanisms/vxlan/vni/server.go +++ b/pkg/networkservice/common/mechanisms/vxlan/vni/server.go @@ -2,6 +2,8 @@ // // Copyright (c) 2021 Nordix Foundation. // +// Copyright (c) 2023 Cisco and/or its affiliates. +// // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -26,6 +28,7 @@ import ( "github.com/networkservicemesh/sdk/pkg/tools/log" "github.com/golang/protobuf/ptypes/empty" + "github.com/pkg/errors" "github.com/networkservicemesh/api/pkg/api/networkservice" "github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/vxlan" @@ -89,7 +92,7 @@ func (v *vniServer) Request(ctx context.Context, request *networkservice.Network logger.WithField("vni", k.vni).Errorf("error returned from request, deleting vni. err=%v", err.Error()) } - return conn, err + return conn, errors.WithStack(err) } vni, loaded := load(ctx, metadata.IsClient(v)) @@ -102,7 +105,7 @@ func (v *vniServer) Request(ctx context.Context, request *networkservice.Network var err error k.vni, err = mechanism.GenerateRandomVNI() if err != nil { - return nil, err + return nil, errors.WithStack(err) } // If its not one already in use, set it and we are good to go if _, ok := v.Map.LoadOrStore(k, &k); !ok { @@ -121,7 +124,7 @@ func (v *vniServer) Request(ctx context.Context, request *networkservice.Network logger.WithField("vniKey.vni", k.vni).Errorf("error returned from request, deleting vni. err=%v", err.Error()) } - return conn, err + return conn, errors.WithStack(err) } func (v *vniServer) Close(ctx context.Context, conn *networkservice.Connection) (*empty.Empty, error) { diff --git a/pkg/networkservice/common/mechanisms/vxlan/vni/vni_map.gen.go b/pkg/networkservice/common/mechanisms/vxlan/vni/vni_map.gen.go index b4b937e855..489c496e04 100644 --- a/pkg/networkservice/common/mechanisms/vxlan/vni/vni_map.gen.go +++ b/pkg/networkservice/common/mechanisms/vxlan/vni/vni_map.gen.go @@ -1,4 +1,6 @@ // Code generated by "-output vni_map.gen.go -type Map -output vni_map.gen.go -type Map"; DO NOT EDIT. +// Install -output vni_map.gen.go -type Map by "go get -u github.com/searKing/golang/tools/-output vni_map.gen.go -type Map" + package vni import ( diff --git a/pkg/networkservice/common/mechanismtranslation/mechanism_map.gen.go b/pkg/networkservice/common/mechanismtranslation/mechanism_map.gen.go index 7ddde90c08..1d82c20857 100644 --- a/pkg/networkservice/common/mechanismtranslation/mechanism_map.gen.go +++ b/pkg/networkservice/common/mechanismtranslation/mechanism_map.gen.go @@ -1,4 +1,6 @@ // Code generated by "-output mechanism_map.gen.go -type mechanismMap -output mechanism_map.gen.go -type mechanismMap"; DO NOT EDIT. +// Install -output mechanism_map.gen.go -type mechanismMap by "go get -u github.com/searKing/golang/tools/-output mechanism_map.gen.go -type mechanismMap" + package mechanismtranslation import ( diff --git a/pkg/networkservice/connectioncontext/dnscontext/client.go b/pkg/networkservice/connectioncontext/dnscontext/client.go index fc37618373..585c3cee4e 100644 --- a/pkg/networkservice/connectioncontext/dnscontext/client.go +++ b/pkg/networkservice/connectioncontext/dnscontext/client.go @@ -1,6 +1,6 @@ // Copyright (c) 2020-2021 Doc.ai and/or its affiliates. // -// Copyright (c) 2022 Cisco and/or its affiliates. +// Copyright (c) 2022-2023 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -26,6 +26,7 @@ import ( "github.com/golang/protobuf/ptypes/empty" "github.com/miekg/dns" "github.com/networkservicemesh/api/pkg/api/networkservice" + "github.com/pkg/errors" "google.golang.org/grpc" "github.com/networkservicemesh/sdk/pkg/networkservice/core/next" @@ -87,7 +88,7 @@ func (c *dnsContextClient) Request(ctx context.Context, request *networkservice. c.dnsConfigsMap.Store(rv.Id, configs) - return rv, err + return rv, nil } func (c *dnsContextClient) Close(ctx context.Context, conn *networkservice.Connection, opts ...grpc.CallOption) (*empty.Empty, error) { @@ -136,11 +137,15 @@ func (c *dnsContextClient) storeOriginalResolvConf() { func (c *dnsContextClient) appendResolvConf(resolvConf string) error { bytes, err := os.ReadFile(c.resolveConfigPath) if err != nil { - return err + return errors.WithStack(errors.Wrapf(err, "failed to read resolv.conf file: %s", c.resolveConfigPath)) } originalResolvConfig := string(bytes) - return os.WriteFile(c.resolveConfigPath, []byte(originalResolvConfig+resolvConf), os.ModePerm) + err = os.WriteFile(c.resolveConfigPath, []byte(originalResolvConfig+resolvConf), os.ModePerm) + if err != nil { + return errors.WithStack(errors.Wrapf(err, "failed to update resolv.conf file: %s", c.resolveConfigPath)) + } + return nil } func (c *dnsContextClient) initialize() { diff --git a/pkg/networkservice/connectioncontext/dnscontext/resolvconf.go b/pkg/networkservice/connectioncontext/dnscontext/resolvconf.go index 20a919d2d8..64b71754dc 100644 --- a/pkg/networkservice/connectioncontext/dnscontext/resolvconf.go +++ b/pkg/networkservice/connectioncontext/dnscontext/resolvconf.go @@ -1,6 +1,6 @@ // Copyright (c) 2020 Doc.ai and/or its affiliates. // -// Copyright (c) 2022 Cisco and/or its affiliates. +// Copyright (c) 2022-2023 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -21,6 +21,8 @@ package dnscontext import ( "io/ioutil" "strings" + + "github.com/pkg/errors" ) // resolveConfig provides API for editing / reading resolv.conf @@ -44,7 +46,7 @@ func openResolveConfig(p string) (*resolveConfig, error) { func (r *resolveConfig) readProperties() error { b, err := ioutil.ReadFile(r.path) if err != nil { - return err + return errors.WithStack(errors.Wrapf(err, "failed to read resolv.conf file: %s", r.path)) } for _, l := range strings.Split(string(b), "\n") { if !strings.HasPrefix(l, "#") { diff --git a/pkg/networkservice/connectioncontext/dnscontext/vl3dns/server.go b/pkg/networkservice/connectioncontext/dnscontext/vl3dns/server.go index f789745632..352145282a 100644 --- a/pkg/networkservice/connectioncontext/dnscontext/vl3dns/server.go +++ b/pkg/networkservice/connectioncontext/dnscontext/vl3dns/server.go @@ -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 // @@ -26,6 +26,7 @@ import ( "github.com/golang/protobuf/ptypes/empty" "github.com/networkservicemesh/api/pkg/api/networkservice" + "github.com/pkg/errors" "github.com/networkservicemesh/sdk/pkg/networkservice/core/next" "github.com/networkservicemesh/sdk/pkg/networkservice/utils/metadata" @@ -170,7 +171,7 @@ func (n *vl3DNSServer) buildSrcDNSRecords(c *networkservice.Connection) ([]strin for _, templ := range n.domainSchemeTemplates { var recordBuilder = new(strings.Builder) if err := templ.Execute(recordBuilder, c); err != nil { - return nil, err + return nil, errors.WithStack(errors.Wrap(err, "error occurred executing the template or writing its output")) } result = append(result, recordBuilder.String()) } diff --git a/pkg/networkservice/connectioncontext/ipcontext/vl3/ipam.go b/pkg/networkservice/connectioncontext/ipcontext/vl3/ipam.go index 85f6823a35..96f466f480 100644 --- a/pkg/networkservice/connectioncontext/ipcontext/vl3/ipam.go +++ b/pkg/networkservice/connectioncontext/ipcontext/vl3/ipam.go @@ -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 // @@ -21,6 +21,8 @@ import ( "net" "sync" + "github.com/pkg/errors" + "github.com/networkservicemesh/sdk/pkg/tools/ippool" "github.com/networkservicemesh/sdk/pkg/tools/log" ) @@ -76,7 +78,7 @@ func (p *vl3IPAM) allocate() (*net.IPNet, error) { ip, err := p.ipPool.Pull() if err != nil { - return nil, err + return nil, errors.WithStack(err) } r := &net.IPNet{ diff --git a/pkg/networkservice/connectioncontext/mtu/vl3mtu/server.go b/pkg/networkservice/connectioncontext/mtu/vl3mtu/server.go index cae9ebeaac..23c22afb37 100644 --- a/pkg/networkservice/connectioncontext/mtu/vl3mtu/server.go +++ b/pkg/networkservice/connectioncontext/mtu/vl3mtu/server.go @@ -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 // @@ -92,7 +92,7 @@ func (v *vl3MtuServer) Request(ctx context.Context, request *networkservice.Netw v.connections[conn.GetId()] = conn }) - return conn, err + return conn, nil } func (v *vl3MtuServer) Close(ctx context.Context, conn *networkservice.Connection) (*empty.Empty, error) { diff --git a/pkg/networkservice/core/adapters/monitor_client_to_server.go b/pkg/networkservice/core/adapters/monitor_client_to_server.go index dc73de1d34..ff7c7366f7 100644 --- a/pkg/networkservice/core/adapters/monitor_client_to_server.go +++ b/pkg/networkservice/core/adapters/monitor_client_to_server.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020-2022 Cisco and/or its affiliates. +// Copyright (c) 2020-2023 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -18,6 +18,7 @@ package adapters import ( "github.com/networkservicemesh/api/pkg/api/networkservice" + "github.com/pkg/errors" ) type monitorClientToServer struct { @@ -36,16 +37,16 @@ func NewMonitorClientToServer(client networkservice.MonitorConnectionClient) net func (m monitorClientToServer) MonitorConnections(selector *networkservice.MonitorScopeSelector, srv networkservice.MonitorConnection_MonitorConnectionsServer) error { cl, err := m.client.MonitorConnections(srv.Context(), selector) if err != nil { - return err + return errors.WithStack(errors.Wrap(err, "failed to get a monitor connections client")) } for { event, err := cl.Recv() if err != nil { - return err + return errors.WithStack(errors.Wrap(err, "failed to receive a monitor connections event")) } err = srv.Send(event) if err != nil { - return err + return errors.WithStack(errors.Wrap(err, "failed to send a monitor connections event")) } } } diff --git a/pkg/networkservice/core/eventchannel/monitor_connection_client.go b/pkg/networkservice/core/eventchannel/monitor_connection_client.go index 349daf7058..979eef0f24 100644 --- a/pkg/networkservice/core/eventchannel/monitor_connection_client.go +++ b/pkg/networkservice/core/eventchannel/monitor_connection_client.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020-2022 Cisco and/or its affiliates. +// Copyright (c) 2020-2023 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -47,11 +47,11 @@ func NewMonitorConnectionMonitorConnectionsClient(ctx context.Context, eventCh < func (m *monitorConnectionMonitorConnectionsClient) Recv() (*networkservice.ConnectionEvent, error) { select { case <-m.ctx.Done(): - return nil, m.ctx.Err() + return nil, errors.WithStack(m.ctx.Err()) case event, ok := <-m.eventCh: if !ok { m.cancelFunc() - return nil, errors.New("No more events, chan closed by sender") + return nil, errors.WithStack(errors.New("No more events, chan closed by sender")) } return event, nil } diff --git a/pkg/networkservice/core/eventchannel/monitor_connection_server.go b/pkg/networkservice/core/eventchannel/monitor_connection_server.go index 7809a88a1a..255f0b5899 100644 --- a/pkg/networkservice/core/eventchannel/monitor_connection_server.go +++ b/pkg/networkservice/core/eventchannel/monitor_connection_server.go @@ -1,6 +1,6 @@ // Copyright (c) 2021 Doc.ai and/or its affiliates. // -// Copyright (c) 2022 Cisco and/or its affiliates. +// Copyright (c) 2022-2023 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -46,7 +46,7 @@ func NewMonitorConnectionMonitorConnectionsServer(ctx context.Context, eventCh c func (m *monitorConnectionMonitorConnectionsServer) Send(event *networkservice.ConnectionEvent) error { select { case <-m.ctx.Done(): - return m.ctx.Err() + return errors.WithStack(m.ctx.Err()) case m.eventCh <- event: return nil } diff --git a/pkg/networkservice/core/eventchannel/monitor_server.go b/pkg/networkservice/core/eventchannel/monitor_server.go index 0195c58bd9..05bd29ea80 100644 --- a/pkg/networkservice/core/eventchannel/monitor_server.go +++ b/pkg/networkservice/core/eventchannel/monitor_server.go @@ -1,6 +1,6 @@ // Copyright (c) 2020 Doc.ai and/or its affiliates. // -// Copyright (c) 2020-2022 Cisco and/or its affiliates. +// Copyright (c) 2020-2023 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -19,7 +19,7 @@ package eventchannel import ( - "errors" + "github.com/pkg/errors" "github.com/networkservicemesh/api/pkg/api/networkservice" @@ -54,7 +54,7 @@ func NewMonitorServer(eventCh <-chan *networkservice.ConnectionEvent, options .. func (m *monitorConnectionServer) MonitorConnections(selector *networkservice.MonitorScopeSelector, srv networkservice.MonitorConnection_MonitorConnectionsServer) error { select { case <-m.closeCh: - return errors.New("sending is no longer possible") + return errors.WithStack(errors.New("sending is no longer possible")) default: m.executor.AsyncExec(func() { m.servers = append(m.servers, srv) diff --git a/pkg/networkservice/ipam/point2pointipam/connectionInfoMap.gen.go b/pkg/networkservice/ipam/point2pointipam/connectionInfoMap.gen.go index 7612aa0c63..978b0e9c57 100644 --- a/pkg/networkservice/ipam/point2pointipam/connectionInfoMap.gen.go +++ b/pkg/networkservice/ipam/point2pointipam/connectionInfoMap.gen.go @@ -1,4 +1,6 @@ // Code generated by "-output connectionInfoMap.gen.go -type Map -output connectionInfoMap.gen.go -type Map"; DO NOT EDIT. +// Install -output connectionInfoMap.gen.go -type Map by "go get -u github.com/searKing/golang/tools/-output connectionInfoMap.gen.go -type Map" + package point2pointipam import ( diff --git a/pkg/networkservice/ipam/point2pointipam/server.go b/pkg/networkservice/ipam/point2pointipam/server.go index 895f93e9bd..75e99817c0 100644 --- a/pkg/networkservice/ipam/point2pointipam/server.go +++ b/pkg/networkservice/ipam/point2pointipam/server.go @@ -1,6 +1,6 @@ // Copyright (c) 2020-2022 Doc.ai and/or its affiliates. // -// Copyright (c) 2022 Cisco and/or its affiliates. +// Copyright (c) 2022-2023 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -80,7 +80,7 @@ func (s *ipamServer) init() { func (s *ipamServer) Request(ctx context.Context, request *networkservice.NetworkServiceRequest) (*networkservice.Connection, error) { s.once.Do(s.init) if s.initErr != nil { - return nil, s.initErr + return nil, errors.WithStack(errors.Wrap(s.initErr, "failed to init IPAM server")) } conn := request.GetConnection() @@ -134,7 +134,7 @@ func (s *ipamServer) Request(ctx context.Context, request *networkservice.Networ func (s *ipamServer) recoverAddrs(srcAddrs, dstAddrs []string, excludeIP4, excludeIP6 *ippool.IPPool) (connInfo *connectionInfo, err error) { if len(srcAddrs) == 0 || len(dstAddrs) == 0 { - return nil, errors.New("addresses cannot be empty for recovery") + return nil, errors.WithStack(errors.New("addresses cannot be empty for recovery")) } for _, ipPool := range s.ipPools { var srcAddr, dstAddr *net.IPNet @@ -157,7 +157,7 @@ func (s *ipamServer) recoverAddrs(srcAddrs, dstAddrs []string, excludeIP4, exclu } } - return nil, errors.Errorf("unable to recover: %+v, %+v", srcAddrs, dstAddrs) + return nil, errors.WithStack(errors.Errorf("unable to recover: %+v, %+v", srcAddrs, dstAddrs)) } func (s *ipamServer) getP2PAddrs(excludeIP4, excludeIP6 *ippool.IPPool) (connInfo *connectionInfo, err error) { @@ -171,7 +171,7 @@ func (s *ipamServer) getP2PAddrs(excludeIP4, excludeIP6 *ippool.IPPool) (connInf }, nil } } - return nil, err + return nil, errors.WithStack(err) } func deleteRoute(routes *[]*networkservice.Route, prefix string) { diff --git a/pkg/networkservice/ipam/singlepointipam/connectionInfoMap.gen.go b/pkg/networkservice/ipam/singlepointipam/connectionInfoMap.gen.go index ff93da539c..0346117001 100644 --- a/pkg/networkservice/ipam/singlepointipam/connectionInfoMap.gen.go +++ b/pkg/networkservice/ipam/singlepointipam/connectionInfoMap.gen.go @@ -1,4 +1,6 @@ // Code generated by "-output connectionInfoMap.gen.go -type Map -output connectionInfoMap.gen.go -type Map"; DO NOT EDIT. +// Install -output connectionInfoMap.gen.go -type Map by "go get -u github.com/searKing/golang/tools/-output connectionInfoMap.gen.go -type Map" + package singlepointipam import ( diff --git a/pkg/networkservice/ipam/singlepointipam/server.go b/pkg/networkservice/ipam/singlepointipam/server.go index ce288fb3e4..00e54ea978 100644 --- a/pkg/networkservice/ipam/singlepointipam/server.go +++ b/pkg/networkservice/ipam/singlepointipam/server.go @@ -1,5 +1,7 @@ // Copyright (c) 2020-2022 Nordix and 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"); @@ -14,6 +16,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +// Package singlepointipam defines a chain element that implements IPAM service package singlepointipam import ( @@ -81,7 +84,7 @@ func (sipam *singlePIpam) init() { func (sipam *singlePIpam) Request(ctx context.Context, request *networkservice.NetworkServiceRequest) (*networkservice.Connection, error) { sipam.once.Do(sipam.init) if sipam.initErr != nil { - return nil, sipam.initErr + return nil, errors.WithStack(errors.Wrap(sipam.initErr, "failed to init IPAM server")) } conn := request.GetConnection() @@ -129,7 +132,7 @@ func (sipam *singlePIpam) Close( ctx context.Context, conn *networkservice.Connection) (_ *empty.Empty, err error) { sipam.once.Do(sipam.init) if sipam.initErr != nil { - return nil, sipam.initErr + return nil, errors.WithStack(errors.Wrap(sipam.initErr, "failed to init IPAM server")) } if connInfo, ok := sipam.Load(conn.GetId()); ok { @@ -155,7 +158,7 @@ func (sipam *singlePIpam) free(connInfo *connectionInfo) { func (sipam *singlePIpam) setMyIP(i int) error { myIP, err := sipam.ipPools[i].Pull() if err != nil { - return err + return errors.WithStack(err) } if i >= len(sipam.myIPs) { sipam.myIPs = append(sipam.myIPs, myIP.String()+sipam.masks[i]) @@ -205,7 +208,7 @@ func (sipam *singlePIpam) getAddrs(excludeIP4, excludeIP6 *ippool.IPPool) (connI } } } - return nil, err + return nil, errors.WithStack(err) } // diff --git a/pkg/networkservice/utils/checks/checkconnection/client.go b/pkg/networkservice/utils/checks/checkconnection/client.go index d3f8cf702d..00ed50aac8 100644 --- a/pkg/networkservice/utils/checks/checkconnection/client.go +++ b/pkg/networkservice/utils/checks/checkconnection/client.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020-2022 Cisco and/or its affiliates. +// Copyright (c) 2020-2023 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -23,6 +23,7 @@ import ( "github.com/golang/protobuf/ptypes/empty" "github.com/networkservicemesh/api/pkg/api/networkservice" + "github.com/pkg/errors" "google.golang.org/grpc" "github.com/networkservicemesh/sdk/pkg/networkservice/core/next" @@ -47,7 +48,7 @@ func NewClient(t *testing.T, check func(t *testing.T, conn *networkservice.Conne func (c *checkConnectionOnReturn) Request(ctx context.Context, request *networkservice.NetworkServiceRequest, opts ...grpc.CallOption) (*networkservice.Connection, error) { conn, err := next.Client(ctx).Request(ctx, request, opts...) c.check(c.T, conn) - return conn, err + return conn, errors.WithStack(err) } func (c *checkConnectionOnReturn) Close(ctx context.Context, conn *networkservice.Connection, opts ...grpc.CallOption) (*empty.Empty, error) { diff --git a/pkg/networkservice/utils/checks/checkcontextonreturn/client.go b/pkg/networkservice/utils/checks/checkcontextonreturn/client.go index f397908929..0643d98edb 100644 --- a/pkg/networkservice/utils/checks/checkcontextonreturn/client.go +++ b/pkg/networkservice/utils/checks/checkcontextonreturn/client.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020-2022 Cisco and/or its affiliates. +// Copyright (c) 2020-2023 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -25,6 +25,7 @@ import ( "github.com/golang/protobuf/ptypes/empty" "github.com/networkservicemesh/api/pkg/api/networkservice" + "github.com/pkg/errors" "google.golang.org/grpc" "github.com/networkservicemesh/sdk/pkg/networkservice/core/next" @@ -50,11 +51,11 @@ func NewClient(t *testing.T, check func(t *testing.T, ctx context.Context)) netw func (t *checkContextOnReturn) Request(ctx context.Context, request *networkservice.NetworkServiceRequest, opts ...grpc.CallOption) (*networkservice.Connection, error) { conn, err := next.Client(ctx).Request(ctx, request, opts...) t.check(t.T, ctx) - return conn, err + return conn, errors.WithStack(err) } func (t *checkContextOnReturn) Close(ctx context.Context, conn *networkservice.Connection, opts ...grpc.CallOption) (*empty.Empty, error) { e, err := next.Client(ctx).Close(ctx, conn, opts...) t.check(t.T, ctx) - return e, err + return e, errors.WithStack(err) } diff --git a/pkg/networkservice/utils/checks/checkerror/client.go b/pkg/networkservice/utils/checks/checkerror/client.go index a2845f3099..aa6a237da2 100644 --- a/pkg/networkservice/utils/checks/checkerror/client.go +++ b/pkg/networkservice/utils/checks/checkerror/client.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020-2022 Cisco and/or its affiliates. +// Copyright (c) 2020-2023 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -22,6 +22,7 @@ import ( "github.com/golang/protobuf/ptypes/empty" "github.com/networkservicemesh/api/pkg/api/networkservice" + "github.com/pkg/errors" "github.com/stretchr/testify/assert" "google.golang.org/grpc" @@ -54,24 +55,24 @@ func (c *checkErrorClient) Request(ctx context.Context, request *networkservice. conn, err := next.Client(ctx).Request(ctx, request, opts...) if c.isNil { assert.Nil(c.T, err) - return conn, err + return conn, errors.WithStack(err) } assert.NotNil(c.T, err) if c.err != nil { assert.Equal(c.T, &err, c.err) } - return conn, err + return conn, errors.WithStack(err) } func (c *checkErrorClient) Close(ctx context.Context, conn *networkservice.Connection, opts ...grpc.CallOption) (*empty.Empty, error) { e, err := next.Client(ctx).Close(ctx, conn, opts...) if c.isNil { assert.Nil(c.T, err) - return e, err + return e, errors.WithStack(err) } assert.NotNil(c.T, err) if c.err != nil { assert.Equal(c.T, &err, c.err) } - return e, err + return e, errors.WithStack(err) } diff --git a/pkg/networkservice/utils/checks/checkerror/server.go b/pkg/networkservice/utils/checks/checkerror/server.go index 5d41be74d1..aaf3a5bb22 100644 --- a/pkg/networkservice/utils/checks/checkerror/server.go +++ b/pkg/networkservice/utils/checks/checkerror/server.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020-2022 Cisco and/or its affiliates. +// Copyright (c) 2020-2023 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -22,6 +22,7 @@ import ( "github.com/golang/protobuf/ptypes/empty" "github.com/networkservicemesh/api/pkg/api/networkservice" + "github.com/pkg/errors" "github.com/stretchr/testify/assert" "github.com/networkservicemesh/sdk/pkg/networkservice/core/next" @@ -53,24 +54,24 @@ func (c *checkErrorServer) Request(ctx context.Context, request *networkservice. conn, err := next.Server(ctx).Request(ctx, request) if c.isNil { assert.Nil(c.T, err) - return conn, err + return conn, errors.WithStack(err) } assert.NotNil(c.T, err) if c.err != nil { assert.Equal(c.T, &err, c.err) } - return conn, err + return conn, errors.WithStack(err) } func (c *checkErrorServer) Close(ctx context.Context, conn *networkservice.Connection) (*empty.Empty, error) { e, err := next.Server(ctx).Close(ctx, conn) if c.isNil { assert.Nil(c.T, err) - return e, err + return e, errors.WithStack(err) } assert.NotNil(c.T, err) if c.err != nil { assert.Equal(c.T, &err, c.err) } - return e, err + return e, errors.WithStack(err) } diff --git a/pkg/networkservice/utils/checks/checkresponse/client.go b/pkg/networkservice/utils/checks/checkresponse/client.go index 9e4d51eb21..4e36fbf3f2 100644 --- a/pkg/networkservice/utils/checks/checkresponse/client.go +++ b/pkg/networkservice/utils/checks/checkresponse/client.go @@ -1,7 +1,7 @@ -// Copyright (c) 2022 Cisco and/or its affiliates. -// // Copyright (c) 2021-2022 Doc.ai and/or its affiliates. // +// Copyright (c) 2022-2023 Cisco and/or its affiliates. +// // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -27,6 +27,7 @@ import ( "github.com/golang/protobuf/ptypes/empty" "github.com/networkservicemesh/api/pkg/api/networkservice" + "github.com/pkg/errors" "github.com/networkservicemesh/sdk/pkg/networkservice/core/next" ) @@ -50,7 +51,7 @@ func NewClient(t *testing.T, check func(*testing.T, *networkservice.Connection)) func (c *checkResponseClient) Request(ctx context.Context, request *networkservice.NetworkServiceRequest, opts ...grpc.CallOption) (*networkservice.Connection, error) { resp, err := next.Client(ctx).Request(ctx, request, opts...) c.check(c.T, resp) - return resp, err + return resp, errors.WithStack(err) } func (c *checkResponseClient) Close(ctx context.Context, conn *networkservice.Connection, opts ...grpc.CallOption) (*empty.Empty, error) { diff --git a/pkg/networkservice/utils/checks/checkresponse/server.go b/pkg/networkservice/utils/checks/checkresponse/server.go index e95e34b16c..c64e6063aa 100644 --- a/pkg/networkservice/utils/checks/checkresponse/server.go +++ b/pkg/networkservice/utils/checks/checkresponse/server.go @@ -1,6 +1,6 @@ // Copyright (c) 2021 Doc.ai and/or its affiliates. // -// Copyright (c) 2022 Cisco Systems, Inc. +// Copyright (c) 2022-2023 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -25,6 +25,7 @@ import ( "github.com/golang/protobuf/ptypes/empty" "github.com/networkservicemesh/api/pkg/api/networkservice" + "github.com/pkg/errors" "github.com/networkservicemesh/sdk/pkg/networkservice/core/next" ) @@ -48,7 +49,7 @@ func NewServer(t *testing.T, check func(*testing.T, *networkservice.Connection)) func (c *checkResponseServer) Request(ctx context.Context, request *networkservice.NetworkServiceRequest) (*networkservice.Connection, error) { resp, err := next.Server(ctx).Request(ctx, request) c.check(c.T, resp) - return resp, err + return resp, errors.WithStack(err) } func (c *checkResponseServer) Close(ctx context.Context, conn *networkservice.Connection) (*empty.Empty, error) { diff --git a/pkg/networkservice/utils/inject/injecterror/error_supplier.go b/pkg/networkservice/utils/inject/injecterror/error_supplier.go index 42d68aaf79..fdff6dd83f 100644 --- a/pkg/networkservice/utils/inject/injecterror/error_supplier.go +++ b/pkg/networkservice/utils/inject/injecterror/error_supplier.go @@ -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"); @@ -16,6 +18,8 @@ package injecterror +import "github.com/pkg/errors" + type errorSupplier struct { err error count int @@ -34,7 +38,7 @@ func (e *errorSupplier) supply() error { break } if errorTime == e.count || errorTime == -1 { - return e.err + return errors.WithStack(e.err) } } diff --git a/pkg/networkservice/utils/metadata/client.go b/pkg/networkservice/utils/metadata/client.go index 1f7bd2b396..f199dceb31 100644 --- a/pkg/networkservice/utils/metadata/client.go +++ b/pkg/networkservice/utils/metadata/client.go @@ -1,6 +1,6 @@ // Copyright (c) 2021 Doc.ai and/or its affiliates. // -// Copyright (c) 2020-2022 Cisco and/or its affiliates. +// Copyright (c) 2020-2023 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -25,6 +25,7 @@ import ( "github.com/golang/protobuf/ptypes/empty" "github.com/networkservicemesh/api/pkg/api/networkservice" + "github.com/pkg/errors" "google.golang.org/grpc" "github.com/networkservicemesh/sdk/pkg/networkservice/core/next" @@ -55,7 +56,7 @@ func (m *metaDataClient) Request(ctx context.Context, request *networkservice.Ne WithField("connID", connID). Debugf("metadata deleted") } - return nil, err + return nil, errors.WithStack(err) } return conn, nil diff --git a/pkg/networkservice/utils/metadata/meta_data_map.gen.go b/pkg/networkservice/utils/metadata/meta_data_map.gen.go index eccfb9c59e..66d8f5ac42 100644 --- a/pkg/networkservice/utils/metadata/meta_data_map.gen.go +++ b/pkg/networkservice/utils/metadata/meta_data_map.gen.go @@ -1,4 +1,6 @@ // Code generated by "-output meta_data_map.gen.go -type metaDataMap -output meta_data_map.gen.go -type metaDataMap"; DO NOT EDIT. +// Install -output meta_data_map.gen.go -type metaDataMap by "go get -u github.com/searKing/golang/tools/-output meta_data_map.gen.go -type metaDataMap" + package metadata import ( diff --git a/pkg/networkservice/utils/metadata/server.go b/pkg/networkservice/utils/metadata/server.go index 8193c5157c..4f06f381c9 100644 --- a/pkg/networkservice/utils/metadata/server.go +++ b/pkg/networkservice/utils/metadata/server.go @@ -1,6 +1,6 @@ // Copyright (c) 2021 Doc.ai and/or its affiliates. // -// Copyright (c) 2020-2022 Cisco and/or its affiliates. +// Copyright (c) 2020-2023 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -25,6 +25,7 @@ import ( "github.com/golang/protobuf/ptypes/empty" "github.com/networkservicemesh/api/pkg/api/networkservice" + "github.com/pkg/errors" "github.com/networkservicemesh/sdk/pkg/networkservice/core/next" ) @@ -54,7 +55,7 @@ func (m *metadataServer) Request(ctx context.Context, request *networkservice.Ne WithField("connID", connID). Debugf("metadata deleted") } - return nil, err + return nil, errors.WithStack(err) } return conn, nil diff --git a/pkg/registry/common/authorize/common.go b/pkg/registry/common/authorize/common.go index c8b2a3552d..c5cb32d6e2 100644 --- a/pkg/registry/common/authorize/common.go +++ b/pkg/registry/common/authorize/common.go @@ -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 // @@ -20,6 +20,7 @@ import ( "context" "github.com/golang-jwt/jwt/v4" + "github.com/pkg/errors" "github.com/spiffe/go-spiffe/v2/spiffeid" "github.com/networkservicemesh/sdk/pkg/registry/common/grpcmetadata" @@ -54,7 +55,7 @@ func (l *policiesList) check(ctx context.Context, input RegistryOpaInput) error if err := policy.Check(ctx, input); err != nil { log.FromContext(ctx).Infof("policy failed %v", policy) - return err + return errors.WithStack(err) } log.FromContext(ctx).Infof("policy passed") diff --git a/pkg/registry/common/authorize/ns_client.go b/pkg/registry/common/authorize/ns_client.go index b26997618a..d1e499512e 100644 --- a/pkg/registry/common/authorize/ns_client.go +++ b/pkg/registry/common/authorize/ns_client.go @@ -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 // @@ -69,7 +69,7 @@ func (c *authorizeNSClient) Register(ctx context.Context, ns *registry.NetworkSe resp, err := next.NetworkServiceRegistryClient(ctx).Register(ctx, ns, opts...) if err != nil { - return nil, err + return nil, errors.WithStack(err) } if p != (peer.Peer{}) { @@ -92,7 +92,7 @@ func (c *authorizeNSClient) Register(ctx context.Context, ns *registry.NetworkSe defer cancelUnregister() if _, unregisterErr := next.NetworkServiceRegistryClient(ctx).Unregister(unregisterCtx, resp, opts...); unregisterErr != nil { - err = errors.Wrapf(err, "nse unregistered with error: %s", unregisterErr.Error()) + err = errors.WithStack(errors.Wrapf(err, "nse unregistered with error: %s", unregisterErr.Error())) } return nil, err @@ -119,7 +119,7 @@ func (c *authorizeNSClient) Unregister(ctx context.Context, ns *registry.Network resp, err := next.NetworkServiceRegistryClient(ctx).Unregister(ctx, ns, opts...) if err != nil { - return nil, err + return nil, errors.WithStack(err) } if p != (peer.Peer{}) { diff --git a/pkg/registry/common/authorize/nse_client.go b/pkg/registry/common/authorize/nse_client.go index fb22905d78..64f65ddb66 100644 --- a/pkg/registry/common/authorize/nse_client.go +++ b/pkg/registry/common/authorize/nse_client.go @@ -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 // @@ -70,7 +70,7 @@ func (c *authorizeNSEClient) Register(ctx context.Context, nse *registry.Network resp, err := next.NetworkServiceEndpointRegistryClient(ctx).Register(ctx, nse, opts...) if err != nil { - return nil, err + return nil, errors.WithStack(err) } if p != (peer.Peer{}) { @@ -91,7 +91,7 @@ func (c *authorizeNSEClient) Register(ctx context.Context, nse *registry.Network defer cancelUnregister() if _, unregisterErr := next.NetworkServiceEndpointRegistryClient(ctx).Unregister(unregisterCtx, resp, opts...); unregisterErr != nil { - err = errors.Wrapf(err, "nse unregistered with error: %s", unregisterErr.Error()) + err = errors.WithStack(errors.Wrapf(err, "nse unregistered with error: %s", unregisterErr.Error())) } return nil, err @@ -118,7 +118,7 @@ func (c *authorizeNSEClient) Unregister(ctx context.Context, nse *registry.Netwo resp, err := next.NetworkServiceEndpointRegistryClient(ctx).Unregister(ctx, nse, opts...) if err != nil { - return nil, err + return nil, errors.WithStack(err) } if p != (peer.Peer{}) { diff --git a/pkg/registry/common/authorize/sync_map.gen.go b/pkg/registry/common/authorize/sync_map.gen.go index 5923f054ca..1e27e2973e 100644 --- a/pkg/registry/common/authorize/sync_map.gen.go +++ b/pkg/registry/common/authorize/sync_map.gen.go @@ -1,4 +1,6 @@ // Code generated by "-output sync_map.gen.go -type PathIdsMap -output sync_map.gen.go -type PathIdsMap"; DO NOT EDIT. +// Install -output sync_map.gen.go -type PathIdsMap by "go get -u github.com/searKing/golang/tools/-output sync_map.gen.go -type PathIdsMap" + package authorize import ( diff --git a/pkg/registry/common/begin/ns_client.go b/pkg/registry/common/begin/ns_client.go index 899209dd39..d737c63566 100644 --- a/pkg/registry/common/begin/ns_client.go +++ b/pkg/registry/common/begin/ns_client.go @@ -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 // @@ -36,7 +36,7 @@ type beginNSClient struct { func (b *beginNSClient) Register(ctx context.Context, in *registry.NetworkService, opts ...grpc.CallOption) (*registry.NetworkService, error) { id := in.GetName() if id == "" { - return nil, errors.New("registry.NetworkService.Name must not be zero valued") + return nil, errors.WithStack(errors.New("registry.NetworkService.Name 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 { @@ -78,7 +78,7 @@ func (b *beginNSClient) Register(ctx context.Context, in *registry.NetworkServic eventFactoryClient.response = resp.Clone() eventFactoryClient.updateContext(grpcmetadata.PathWithContext(ctx, grpcmetadata.PathFromContext(ctx).Clone())) }) - return resp, err + return resp, errors.WithStack(err) } func (b *beginNSClient) Find(ctx context.Context, in *registry.NetworkServiceQuery, opts ...grpc.CallOption) (registry.NetworkServiceRegistry_FindClient, error) { @@ -113,7 +113,7 @@ func (b *beginNSClient) Unregister(ctx context.Context, in *registry.NetworkServ // afterCloseFunc() is used to cleanup things like the entry in the Map for EventFactories eventFactoryClient.afterCloseFunc() }) - return emp, err + return emp, errors.WithStack(err) } // NewNetworkServiceRegistryClient - returns a new null client that does nothing but call next.NetworkServiceRegistryClient(ctx). diff --git a/pkg/registry/common/begin/ns_client_map.gen.go b/pkg/registry/common/begin/ns_client_map.gen.go index 7ad9610848..1ca9baef72 100644 --- a/pkg/registry/common/begin/ns_client_map.gen.go +++ b/pkg/registry/common/begin/ns_client_map.gen.go @@ -1,4 +1,6 @@ // Code generated by "-output ns_client_map.gen.go -type nsClientMap -output ns_client_map.gen.go -type nsClientMap"; DO NOT EDIT. +// Install -output ns_client_map.gen.go -type nsClientMap by "go get -u github.com/searKing/golang/tools/-output ns_client_map.gen.go -type nsClientMap" + package begin import ( diff --git a/pkg/registry/common/begin/ns_server.go b/pkg/registry/common/begin/ns_server.go index 35264f3287..7875ca9cb1 100644 --- a/pkg/registry/common/begin/ns_server.go +++ b/pkg/registry/common/begin/ns_server.go @@ -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 // @@ -36,7 +36,7 @@ type beginNSServer struct { func (b *beginNSServer) Register(ctx context.Context, in *registry.NetworkService) (*registry.NetworkService, error) { id := in.GetName() if id == "" { - return nil, errors.New("NetworkService.Name can not be zero valued") + return nil, errors.WithStack(errors.New("NetworkService.Name can 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 { @@ -76,7 +76,7 @@ func (b *beginNSServer) Register(ctx context.Context, in *registry.NetworkServic eventFactoryServer.response = resp eventFactoryServer.updateContext(grpcmetadata.PathWithContext(ctx, grpcmetadata.PathFromContext(ctx).Clone())) }) - return resp, err + return resp, errors.WithStack(err) } func (b *beginNSServer) Find(query *registry.NetworkServiceQuery, server registry.NetworkServiceRegistry_FindServer) error { @@ -107,7 +107,7 @@ func (b *beginNSServer) Unregister(ctx context.Context, in *registry.NetworkServ _, err = next.NetworkServiceRegistryServer(withEventFactoryCtx).Unregister(withEventFactoryCtx, eventFactoryServer.registration) eventFactoryServer.afterCloseFunc() }) - return &emptypb.Empty{}, err + return &emptypb.Empty{}, errors.WithStack(err) } // NewNetworkServiceRegistryServer - returns a new null server that does nothing but call next.NetworkServiceRegistryServer(ctx). diff --git a/pkg/registry/common/begin/ns_server_map.gen.go b/pkg/registry/common/begin/ns_server_map.gen.go index 601134046d..379ef787b5 100644 --- a/pkg/registry/common/begin/ns_server_map.gen.go +++ b/pkg/registry/common/begin/ns_server_map.gen.go @@ -1,4 +1,6 @@ // Code generated by "-output ns_server_map.gen.go -type nsServerMap -output ns_server_map.gen.go -type nsServerMap"; DO NOT EDIT. +// Install -output ns_server_map.gen.go -type nsServerMap by "go get -u github.com/searKing/golang/tools/-output ns_server_map.gen.go -type nsServerMap" + package begin import ( diff --git a/pkg/registry/common/begin/nse_client.go b/pkg/registry/common/begin/nse_client.go index 960574030f..2273177631 100644 --- a/pkg/registry/common/begin/nse_client.go +++ b/pkg/registry/common/begin/nse_client.go @@ -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 // @@ -36,7 +36,7 @@ type beginNSEClient struct { func (b *beginNSEClient) Register(ctx context.Context, in *registry.NetworkServiceEndpoint, opts ...grpc.CallOption) (*registry.NetworkServiceEndpoint, error) { id := in.GetName() if id == "" { - return nil, errors.New("registry.NetworkServiceEndpoint.Name must not be zero valued") + return nil, errors.WithStack(errors.New("registry.NetworkServiceEndpoint.Name 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 { @@ -78,7 +78,7 @@ func (b *beginNSEClient) Register(ctx context.Context, in *registry.NetworkServi eventFactoryClient.response = resp.Clone() eventFactoryClient.updateContext(grpcmetadata.PathWithContext(ctx, grpcmetadata.PathFromContext(ctx).Clone())) }) - return resp, err + return resp, errors.WithStack(err) } func (b *beginNSEClient) Find(ctx context.Context, in *registry.NetworkServiceEndpointQuery, opts ...grpc.CallOption) (registry.NetworkServiceEndpointRegistry_FindClient, error) { @@ -113,7 +113,7 @@ func (b *beginNSEClient) Unregister(ctx context.Context, in *registry.NetworkSer // afterCloseFunc() is used to cleanup things like the entry in the Map for EventFactories eventFactoryClient.afterCloseFunc() }) - return emp, err + return emp, errors.WithStack(err) } // NewNetworkServiceEndpointRegistryClient - returns a new null client that does nothing but call next.NetworkServiceEndpointRegistryClient(ctx). diff --git a/pkg/registry/common/begin/nse_client_map.gen.go b/pkg/registry/common/begin/nse_client_map.gen.go index 62ef33c38b..393ea6b76b 100644 --- a/pkg/registry/common/begin/nse_client_map.gen.go +++ b/pkg/registry/common/begin/nse_client_map.gen.go @@ -1,4 +1,6 @@ // Code generated by "-output nse_client_map.gen.go -type nseClientMap -output nse_client_map.gen.go -type nseClientMap"; DO NOT EDIT. +// Install -output nse_client_map.gen.go -type nseClientMap by "go get -u github.com/searKing/golang/tools/-output nse_client_map.gen.go -type nseClientMap" + package begin import ( diff --git a/pkg/registry/common/begin/nse_server.go b/pkg/registry/common/begin/nse_server.go index 866d9f6ca3..77a8482420 100644 --- a/pkg/registry/common/begin/nse_server.go +++ b/pkg/registry/common/begin/nse_server.go @@ -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 // @@ -36,7 +36,7 @@ type beginNSEServer struct { func (b *beginNSEServer) Register(ctx context.Context, in *registry.NetworkServiceEndpoint) (*registry.NetworkServiceEndpoint, error) { id := in.GetName() if id == "" { - return nil, errors.New("NetworkServiceEndpoint.Name can not be zero valued") + return nil, errors.WithStack(errors.New("NetworkServiceEndpoint.Name can 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 { @@ -76,7 +76,7 @@ func (b *beginNSEServer) Register(ctx context.Context, in *registry.NetworkServi eventFactoryServer.response = resp eventFactoryServer.updateContext(grpcmetadata.PathWithContext(ctx, grpcmetadata.PathFromContext(ctx).Clone())) }) - return resp, err + return resp, errors.WithStack(err) } func (b *beginNSEServer) Find(query *registry.NetworkServiceEndpointQuery, server registry.NetworkServiceEndpointRegistry_FindServer) error { @@ -107,7 +107,7 @@ func (b *beginNSEServer) Unregister(ctx context.Context, in *registry.NetworkSer _, err = next.NetworkServiceEndpointRegistryServer(withEventFactoryCtx).Unregister(withEventFactoryCtx, eventFactoryServer.registration) eventFactoryServer.afterCloseFunc() }) - return &emptypb.Empty{}, err + return &emptypb.Empty{}, errors.WithStack(err) } // NewNetworkServiceEndpointRegistryServer - returns a new null server that does nothing but call next.NetworkServiceEndpointRegistryServer(ctx). diff --git a/pkg/registry/common/begin/nse_server_map.gen.go b/pkg/registry/common/begin/nse_server_map.gen.go index d35e82dffe..46d85070dd 100644 --- a/pkg/registry/common/begin/nse_server_map.gen.go +++ b/pkg/registry/common/begin/nse_server_map.gen.go @@ -1,4 +1,6 @@ // Code generated by "-output nse_server_map.gen.go -type nseServerMap -output nse_server_map.gen.go -type nseServerMap"; DO NOT EDIT. +// Install -output nse_server_map.gen.go -type nseServerMap by "go get -u github.com/searKing/golang/tools/-output nse_server_map.gen.go -type nseServerMap" + package begin import ( diff --git a/pkg/registry/common/clientconn/map.gen.go b/pkg/registry/common/clientconn/map.gen.go index 7a0b20f3ae..0263b3f50a 100644 --- a/pkg/registry/common/clientconn/map.gen.go +++ b/pkg/registry/common/clientconn/map.gen.go @@ -1,4 +1,6 @@ // Code generated by "-output map.gen.go -type stringCCMap -output map.gen.go -type stringCCMap"; DO NOT EDIT. +// Install -output map.gen.go -type stringCCMap by "go get -u github.com/searKing/golang/tools/-output map.gen.go -type stringCCMap" + package clientconn import ( diff --git a/pkg/registry/common/connect/ns_client.go b/pkg/registry/common/connect/ns_client.go index 07959e3b9a..9c4c541e7f 100644 --- a/pkg/registry/common/connect/ns_client.go +++ b/pkg/registry/common/connect/ns_client.go @@ -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 // @@ -21,6 +21,7 @@ import ( "github.com/golang/protobuf/ptypes/empty" "github.com/networkservicemesh/api/pkg/api/registry" + "github.com/pkg/errors" "google.golang.org/grpc" "github.com/networkservicemesh/sdk/pkg/registry/common/clientconn" @@ -31,7 +32,7 @@ type connectNSClient struct{} func (n *connectNSClient) Register(ctx context.Context, in *registry.NetworkService, opts ...grpc.CallOption) (*registry.NetworkService, error) { cc, loaded := clientconn.Load(ctx) if !loaded { - return nil, errNoCCProvided + return nil, errors.WithStack(errNoCCProvided) } return registry.NewNetworkServiceRegistryClient(cc).Register(ctx, in, opts...) } @@ -39,7 +40,7 @@ func (n *connectNSClient) Register(ctx context.Context, in *registry.NetworkServ func (n *connectNSClient) Find(ctx context.Context, in *registry.NetworkServiceQuery, opts ...grpc.CallOption) (registry.NetworkServiceRegistry_FindClient, error) { cc, loaded := clientconn.Load(ctx) if !loaded { - return nil, errNoCCProvided + return nil, errors.WithStack(errNoCCProvided) } return registry.NewNetworkServiceRegistryClient(cc).Find(ctx, in, opts...) } @@ -47,7 +48,7 @@ func (n *connectNSClient) Find(ctx context.Context, in *registry.NetworkServiceQ func (n *connectNSClient) Unregister(ctx context.Context, in *registry.NetworkService, opts ...grpc.CallOption) (*empty.Empty, error) { cc, loaded := clientconn.Load(ctx) if !loaded { - return nil, errNoCCProvided + return nil, errors.WithStack(errNoCCProvided) } return registry.NewNetworkServiceRegistryClient(cc).Unregister(ctx, in, opts...) } diff --git a/pkg/registry/common/connect/ns_server.go b/pkg/registry/common/connect/ns_server.go index bbd9f9d19c..de408e742f 100644 --- a/pkg/registry/common/connect/ns_server.go +++ b/pkg/registry/common/connect/ns_server.go @@ -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 // @@ -39,7 +39,7 @@ func (c *connectNSServer) Register(ctx context.Context, in *registry.NetworkServ closeCtxFunc := postpone.ContextWithValues(ctx) clientResp, clientErr := c.client.Register(ctx, in, c.callOptions...) if clientErr != nil { - return nil, clientErr + return nil, errors.WithStack(clientErr) } serverResp, serverErr := next.NetworkServiceRegistryServer(ctx).Register(ctx, clientResp) @@ -48,7 +48,7 @@ func (c *connectNSServer) Register(ctx context.Context, in *registry.NetworkServ defer closeCancel() _, _ = c.client.Unregister(closeCtx, clientResp, c.callOptions...) } - return serverResp, serverErr + return serverResp, errors.WithStack(serverErr) } func (c *connectNSServer) Find(query *registry.NetworkServiceQuery, server registry.NetworkServiceRegistry_FindServer) error { @@ -56,12 +56,12 @@ func (c *connectNSServer) Find(query *registry.NetworkServiceQuery, server regis clientResp, clientErr := c.client.Find(ctx, query, c.callOptions...) if clientErr != nil { - return clientErr + return errors.WithStack(clientErr) } for resp := range registry.ReadNetworkServiceChannel(clientResp) { if err := server.Send(resp); err != nil { - return err + return errors.WithStack(err) } } @@ -72,12 +72,12 @@ func (c *connectNSServer) Unregister(ctx context.Context, in *registry.NetworkSe _, clientErr := c.client.Unregister(ctx, in, c.callOptions...) _, serverErr := next.NetworkServiceRegistryClient(ctx).Unregister(ctx, in) 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) } // NewNetworkServiceRegistryServer - returns a connect chain element diff --git a/pkg/registry/common/connect/nse_client.go b/pkg/registry/common/connect/nse_client.go index cde60b35b3..bccb7d4a66 100644 --- a/pkg/registry/common/connect/nse_client.go +++ b/pkg/registry/common/connect/nse_client.go @@ -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 // @@ -34,7 +34,7 @@ type connectNSEClient struct{} func (n *connectNSEClient) Register(ctx context.Context, in *registry.NetworkServiceEndpoint, opts ...grpc.CallOption) (*registry.NetworkServiceEndpoint, error) { cc, loaded := clientconn.Load(ctx) if !loaded { - return nil, errNoCCProvided + return nil, errors.WithStack(errNoCCProvided) } return registry.NewNetworkServiceEndpointRegistryClient(cc).Register(ctx, in, opts...) } @@ -42,7 +42,7 @@ func (n *connectNSEClient) Register(ctx context.Context, in *registry.NetworkSer func (n *connectNSEClient) Find(ctx context.Context, in *registry.NetworkServiceEndpointQuery, opts ...grpc.CallOption) (registry.NetworkServiceEndpointRegistry_FindClient, error) { cc, loaded := clientconn.Load(ctx) if !loaded { - return nil, errNoCCProvided + return nil, errors.WithStack(errNoCCProvided) } return registry.NewNetworkServiceEndpointRegistryClient(cc).Find(ctx, in, opts...) } @@ -50,7 +50,7 @@ func (n *connectNSEClient) Find(ctx context.Context, in *registry.NetworkService func (n *connectNSEClient) Unregister(ctx context.Context, in *registry.NetworkServiceEndpoint, opts ...grpc.CallOption) (*empty.Empty, error) { cc, loaded := clientconn.Load(ctx) if !loaded { - return nil, errNoCCProvided + return nil, errors.WithStack(errNoCCProvided) } return registry.NewNetworkServiceEndpointRegistryClient(cc).Unregister(ctx, in, opts...) } diff --git a/pkg/registry/common/connect/nse_server.go b/pkg/registry/common/connect/nse_server.go index 96dc1a8fa2..cba1e6cf67 100644 --- a/pkg/registry/common/connect/nse_server.go +++ b/pkg/registry/common/connect/nse_server.go @@ -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 // @@ -39,7 +39,7 @@ func (c *connectNSEServer) Register(ctx context.Context, in *registry.NetworkSer closeCtxFunc := postpone.ContextWithValues(ctx) clientResp, clientErr := c.client.Register(ctx, in, c.callOptions...) if clientErr != nil { - return nil, clientErr + return nil, errors.WithStack(clientErr) } serverResp, serverErr := next.NetworkServiceEndpointRegistryServer(ctx).Register(ctx, clientResp) @@ -48,7 +48,7 @@ func (c *connectNSEServer) Register(ctx context.Context, in *registry.NetworkSer defer closeCancel() _, _ = c.client.Unregister(closeCtx, clientResp, c.callOptions...) } - return serverResp, serverErr + return serverResp, errors.WithStack(serverErr) } func (c *connectNSEServer) Find(query *registry.NetworkServiceEndpointQuery, server registry.NetworkServiceEndpointRegistry_FindServer) error { @@ -56,12 +56,12 @@ func (c *connectNSEServer) Find(query *registry.NetworkServiceEndpointQuery, ser clientResp, clientErr := c.client.Find(ctx, query, c.callOptions...) if clientErr != nil { - return clientErr + return errors.WithStack(clientErr) } for resp := range registry.ReadNetworkServiceEndpointChannel(clientResp) { if err := server.Send(resp); err != nil { - return err + return errors.WithStack(err) } } @@ -72,10 +72,10 @@ func (c *connectNSEServer) Unregister(ctx context.Context, in *registry.NetworkS _, clientErr := c.client.Unregister(ctx, in, c.callOptions...) _, serverErr := next.NetworkServiceEndpointRegistryClient(ctx).Unregister(ctx, in) 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 } diff --git a/pkg/registry/common/dial/dialer.go b/pkg/registry/common/dial/dialer.go index 351ed6f923..8935ec5ad9 100644 --- a/pkg/registry/common/dial/dialer.go +++ b/pkg/registry/common/dial/dialer.go @@ -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 // @@ -49,7 +49,7 @@ func newDialer(ctx context.Context, dialTimeout time.Duration, dialOptions ...gr func (di *dialer) Dial(ctx context.Context, clientURL *url.URL) error { if di == nil { - return errors.New("cannot call dialer.Dial on nil dialer") + return errors.WithStack(errors.New("cannot call dialer.Dial on nil dialer")) } // Cleanup any previous grpc.ClientConn if di.cleanupCancel != nil { @@ -72,7 +72,7 @@ func (di *dialer) Dial(ctx context.Context, clientURL *url.URL) error { if cc != nil { _ = cc.Close() } - return errors.Wrapf(err, "failed to dial %s", target) + return errors.WithStack(errors.Wrapf(err, "failed to dial %s", target)) } di.ClientConn = cc @@ -95,14 +95,14 @@ func (di *dialer) Close() error { func (di *dialer) Invoke(ctx context.Context, method string, args, reply interface{}, opts ...grpc.CallOption) error { if di.ClientConn == nil { - return errors.New("no dialer.ClientConn found") + return errors.WithStack(errors.New("no dialer.ClientConn found")) } return di.ClientConn.Invoke(ctx, method, args, reply, opts...) } func (di *dialer) NewStream(ctx context.Context, desc *grpc.StreamDesc, method string, opts ...grpc.CallOption) (grpc.ClientStream, error) { if di.ClientConn == nil { - return nil, errors.New("no dialer.ClientConn found") + return nil, errors.WithStack(errors.New("no dialer.ClientConn found")) } return di.ClientConn.NewStream(ctx, desc, method, opts...) } diff --git a/pkg/registry/common/dial/ns_client.go b/pkg/registry/common/dial/ns_client.go index b77e9d8ef9..798fa06f90 100644 --- a/pkg/registry/common/dial/ns_client.go +++ b/pkg/registry/common/dial/ns_client.go @@ -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 // @@ -25,6 +25,7 @@ import ( "github.com/golang/protobuf/ptypes/empty" "github.com/networkservicemesh/api/pkg/api/registry" + "github.com/pkg/errors" "google.golang.org/grpc" "github.com/networkservicemesh/sdk/pkg/registry/common/clientconn" @@ -82,7 +83,7 @@ func (c *dialNSClient) Register(ctx context.Context, in *registry.NetworkService conn, err := next.NetworkServiceRegistryClient(ctx).Register(ctx, in, opts...) if err != nil { _ = di.Close() - return nil, err + return nil, errors.WithStack(err) } return conn, nil } @@ -119,7 +120,7 @@ func (c *dialNSFindClient) Recv() (*registry.NetworkServiceResponse, error) { if err != nil { c.cleanupFn() } - return resp, err + return resp, errors.WithStack(err) } func (c *dialNSClient) Find(ctx context.Context, in *registry.NetworkServiceQuery, opts ...grpc.CallOption) (registry.NetworkServiceRegistry_FindClient, error) { @@ -146,7 +147,7 @@ func (c *dialNSClient) Find(ctx context.Context, in *registry.NetworkServiceQuer resp, err := next.NetworkServiceRegistryClient(ctx).Find(ctx, in, opts...) if err != nil { cleanupFn() - return nil, err + return nil, errors.WithStack(err) } go func() { diff --git a/pkg/registry/common/dial/nse_client.go b/pkg/registry/common/dial/nse_client.go index fac7267072..9e0d9a28d4 100644 --- a/pkg/registry/common/dial/nse_client.go +++ b/pkg/registry/common/dial/nse_client.go @@ -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 // @@ -25,6 +25,7 @@ import ( "github.com/golang/protobuf/ptypes/empty" "github.com/networkservicemesh/api/pkg/api/registry" + "github.com/pkg/errors" "google.golang.org/grpc" "github.com/networkservicemesh/sdk/pkg/registry/common/clientconn" @@ -82,7 +83,7 @@ func (c *dialNSEClient) Register(ctx context.Context, in *registry.NetworkServic conn, err := next.NetworkServiceEndpointRegistryClient(ctx).Register(ctx, in, opts...) if err != nil { _ = di.Close() - return nil, err + return nil, errors.WithStack(err) } return conn, nil } @@ -119,7 +120,7 @@ func (c *dialNSEFindClient) Recv() (*registry.NetworkServiceEndpointResponse, er if err != nil { c.cleanupFn() } - return resp, err + return resp, nil } func (c *dialNSEClient) Find(ctx context.Context, in *registry.NetworkServiceEndpointQuery, opts ...grpc.CallOption) (registry.NetworkServiceEndpointRegistry_FindClient, error) { @@ -146,7 +147,7 @@ func (c *dialNSEClient) Find(ctx context.Context, in *registry.NetworkServiceEnd resp, err := next.NetworkServiceEndpointRegistryClient(ctx).Find(ctx, in, opts...) if err != nil { cleanupFn() - return nil, err + return nil, errors.WithStack(err) } go func() { diff --git a/pkg/registry/common/dnsresolve/common.go b/pkg/registry/common/dnsresolve/common.go index 26671f685e..ece4000163 100644 --- a/pkg/registry/common/dnsresolve/common.go +++ b/pkg/registry/common/dnsresolve/common.go @@ -1,5 +1,7 @@ // Copyright (c) 2020-2022 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"); @@ -78,19 +80,19 @@ func resolveDomain(ctx context.Context, service, domain string, r Resolver) (u * _, records, err := r.LookupSRV(ctx, "", "", serviceDomain) if err != nil { - return nil, err + return nil, errors.WithStack(err) } if len(records) == 0 { - return nil, errors.New("resolver.LookupSERV return empty result") + return nil, errors.WithStack(errors.New("resolver.LookupSERV return empty result")) } port = strconv.Itoa(int(records[0].Port)) ips, err := r.LookupIPAddr(ctx, serviceDomain) if err != nil { - return nil, err + return nil, errors.WithStack(err) } if len(ips) == 0 { - return nil, errors.New("resolver.LookupIPAddr return empty result") + return nil, errors.WithStack(errors.New("resolver.LookupIPAddr return empty result")) } ip = ips[0].IP } @@ -110,7 +112,11 @@ func formatURL(ip, port string) (*url.URL, error) { urlStr = fmt.Sprintf("tcp://[%s]:%s", ip, port) } - return url.Parse(urlStr) + parsedURL, err := url.Parse(urlStr) + if err != nil { + return nil, errors.WithStack(err) + } + return parsedURL, nil } var _ Resolver = (*net.Resolver)(nil) diff --git a/pkg/registry/common/dnsresolve/ns_client.go b/pkg/registry/common/dnsresolve/ns_client.go index 5fbb10d6a1..6b0ad3a3dc 100644 --- a/pkg/registry/common/dnsresolve/ns_client.go +++ b/pkg/registry/common/dnsresolve/ns_client.go @@ -1,4 +1,4 @@ -// Copyright (c) 2022 Cisco Systems, Inc. +// Copyright (c) 2022-2023 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -18,10 +18,10 @@ package dnsresolve import ( "context" - "errors" "net" "github.com/golang/protobuf/ptypes/empty" + "github.com/pkg/errors" "google.golang.org/grpc" "github.com/networkservicemesh/api/pkg/api/registry" @@ -66,12 +66,12 @@ func (d *dnsNSResolveClient) Register(ctx context.Context, ns *registry.NetworkS ns.Name = interdomain.Target(ns.Name) resp, err := next.NetworkServiceRegistryClient(ctx).Register(ctx, ns, opts...) if err != nil { - return nil, err + return nil, errors.WithStack(err) } resp.Name = interdomain.Join(resp.Name, domain) - return resp, err + return resp, nil } type dnsNSResolveFindClient struct { @@ -82,17 +82,17 @@ type dnsNSResolveFindClient struct { func (c *dnsNSResolveFindClient) Recv() (*registry.NetworkServiceResponse, error) { resp, err := c.NetworkServiceRegistry_FindClient.Recv() if err != nil { - return resp, err + return resp, errors.WithStack(err) } resp.NetworkService.Name = interdomain.Join(resp.NetworkService.Name, c.domain) - return resp, err + return resp, nil } func (d *dnsNSResolveClient) Find(ctx context.Context, q *registry.NetworkServiceQuery, opts ...grpc.CallOption) (registry.NetworkServiceRegistry_FindClient, error) { domain := interdomain.Domain(q.NetworkService.Name) if domain == "" { - return nil, errors.New("domain cannot be empty") + return nil, errors.WithStack(errors.New("domain cannot be empty")) } url, err := resolveDomain(ctx, d.registryService, domain, d.resolver) if err != nil { @@ -103,7 +103,7 @@ func (d *dnsNSResolveClient) Find(ctx context.Context, q *registry.NetworkServic resp, err := next.NetworkServiceRegistryClient(ctx).Find(ctx, q, opts...) if err != nil { - return nil, err + return nil, errors.WithStack(err) } return &dnsNSResolveFindClient{ diff --git a/pkg/registry/common/dnsresolve/nse_client.go b/pkg/registry/common/dnsresolve/nse_client.go index 1a26e56f7d..bc209ce6cb 100644 --- a/pkg/registry/common/dnsresolve/nse_client.go +++ b/pkg/registry/common/dnsresolve/nse_client.go @@ -1,4 +1,4 @@ -// Copyright (c) 2022 Cisco Systems, Inc. +// Copyright (c) 2022-2023 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -21,6 +21,7 @@ import ( "net" "github.com/networkservicemesh/api/pkg/api/registry" + "github.com/pkg/errors" "github.com/golang/protobuf/ptypes/empty" "google.golang.org/grpc" @@ -70,14 +71,14 @@ func (d *dnsNSEResolveClient) Register(ctx context.Context, nse *registry.Networ resp, err := next.NetworkServiceEndpointRegistryClient(ctx).Register(ctx, nse, opts...) if err != nil { - return nil, err + return nil, errors.WithStack(err) } translateNSE(resp, func(s string) string { return interdomain.Join(s, domain) }) - return resp, err + return resp, nil } type dnsNSEResolveFindClient struct { @@ -88,14 +89,14 @@ type dnsNSEResolveFindClient struct { func (c *dnsNSEResolveFindClient) Recv() (*registry.NetworkServiceEndpointResponse, error) { resp, err := c.NetworkServiceEndpointRegistry_FindClient.Recv() if err != nil { - return resp, err + return resp, errors.WithStack(err) } translateNSE(resp.NetworkServiceEndpoint, func(str string) string { return interdomain.Join(str, c.domain) }) - return resp, err + return resp, nil } func (d *dnsNSEResolveClient) Find(ctx context.Context, q *registry.NetworkServiceEndpointQuery, opts ...grpc.CallOption) (registry.NetworkServiceEndpointRegistry_FindClient, error) { @@ -111,7 +112,7 @@ func (d *dnsNSEResolveClient) Find(ctx context.Context, q *registry.NetworkServi resp, err := next.NetworkServiceEndpointRegistryClient(ctx).Find(ctx, q, opts...) if err != nil { - return nil, err + return nil, errors.WithStack(err) } return &dnsNSEResolveFindClient{ diff --git a/pkg/registry/common/endpointurls/sync_map.gen.go b/pkg/registry/common/endpointurls/sync_map.gen.go index cf7285a8ba..61b50e2209 100644 --- a/pkg/registry/common/endpointurls/sync_map.gen.go +++ b/pkg/registry/common/endpointurls/sync_map.gen.go @@ -1,4 +1,6 @@ // Code generated by "-output sync_map.gen.go -type Map -output sync_map.gen.go -type Map"; DO NOT EDIT. +// Install -output sync_map.gen.go -type Map by "go get -u github.com/searKing/golang/tools/-output sync_map.gen.go -type Map" + package endpointurls import ( diff --git a/pkg/registry/common/expire/nse_server.go b/pkg/registry/common/expire/nse_server.go index 1de76265f6..09a46e2063 100644 --- a/pkg/registry/common/expire/nse_server.go +++ b/pkg/registry/common/expire/nse_server.go @@ -1,5 +1,7 @@ // Copyright (c) 2020-2022 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"); @@ -21,6 +23,7 @@ import ( "time" "github.com/golang/protobuf/ptypes/empty" + "github.com/pkg/errors" "google.golang.org/protobuf/types/known/timestamppb" "github.com/networkservicemesh/api/pkg/api/registry" @@ -73,7 +76,7 @@ func (s *expireNSEServer) Register(ctx context.Context, nse *registry.NetworkSer resp, err := next.NetworkServiceEndpointRegistryServer(ctx).Register(ctx, nse) if err != nil { - return nil, err + return nil, errors.WithStack(err) } if nseExpirationTime := resp.GetExpirationTime().AsTime().Local(); nseExpirationTime.Before(expirationTime) { diff --git a/pkg/registry/common/expire/sync_map.gen.go b/pkg/registry/common/expire/sync_map.gen.go index d3a5dc6326..88bb399653 100644 --- a/pkg/registry/common/expire/sync_map.gen.go +++ b/pkg/registry/common/expire/sync_map.gen.go @@ -1,4 +1,6 @@ // Code generated by "-output sync_map.gen.go -type cancelsMap -output sync_map.gen.go -type cancelsMap"; DO NOT EDIT. +// Install -output sync_map.gen.go -type cancelsMap by "go get -u github.com/searKing/golang/tools/-output sync_map.gen.go -type cancelsMap" + package expire import ( diff --git a/pkg/registry/common/grpcmetadata/common.go b/pkg/registry/common/grpcmetadata/common.go index 7eeda5d615..b4f39f4fca 100644 --- a/pkg/registry/common/grpcmetadata/common.go +++ b/pkg/registry/common/grpcmetadata/common.go @@ -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 // @@ -19,8 +19,8 @@ package grpcmetadata import ( "context" "encoding/json" - "errors" + "github.com/pkg/errors" "google.golang.org/grpc" "google.golang.org/grpc/metadata" ) @@ -49,7 +49,7 @@ func fromMD(md metadata.MD) (*Path, error) { pathValue, loaded := md[pathKey] if !loaded { - return nil, errors.New("failed to load path from grpc metadata") + return nil, errors.WithStack(errors.New("failed to load path from grpc metadata")) } path := &Path{} @@ -57,7 +57,7 @@ func fromMD(md metadata.MD) (*Path, error) { if len(pathValue) > 0 { err := json.Unmarshal([]byte(pathValue[len(pathValue)-1]), path) if err != nil { - return nil, err + return nil, errors.WithStack(err) } } @@ -68,7 +68,7 @@ func fromContext(ctx context.Context) (*Path, error) { md, loaded := metadata.FromIncomingContext(ctx) if !loaded { - return nil, errors.New("failed to load grpc metadata from context") + return nil, errors.WithStack(errors.New("failed to load grpc metadata from context")) } return fromMD(md) @@ -77,7 +77,7 @@ func fromContext(ctx context.Context) (*Path, error) { func appendToMetadata(ctx context.Context, path *Path) (context.Context, error) { bytes, err := json.Marshal(path) if err != nil { - return nil, err + return nil, errors.WithStack(err) } ctx = metadata.AppendToOutgoingContext(ctx, pathKey, string(bytes)) return ctx, nil @@ -86,9 +86,9 @@ func appendToMetadata(ctx context.Context, path *Path) (context.Context, error) func sendPath(ctx context.Context, path *Path) error { bytes, err := json.Marshal(path) if err != nil { - return err + return errors.WithStack(err) } header := metadata.Pairs(pathKey, string(bytes)) - return grpc.SendHeader(ctx, header) + return errors.WithStack(grpc.SendHeader(ctx, header)) } diff --git a/pkg/registry/common/grpcmetadata/ns_client.go b/pkg/registry/common/grpcmetadata/ns_client.go index 8a5d95c70b..8e61d6d4ef 100644 --- a/pkg/registry/common/grpcmetadata/ns_client.go +++ b/pkg/registry/common/grpcmetadata/ns_client.go @@ -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 // @@ -21,6 +21,7 @@ import ( "context" "github.com/golang/protobuf/ptypes/empty" + "github.com/pkg/errors" "google.golang.org/grpc" "google.golang.org/grpc/metadata" @@ -50,7 +51,7 @@ func (c *grpcMetadataNSClient) Register(ctx context.Context, ns *registry.Networ resp, err := next.NetworkServiceRegistryClient(ctx).Register(ctx, ns, opts...) if err != nil { - return nil, err + return nil, errors.WithStack(err) } newpath, err := fromMD(header) @@ -80,7 +81,7 @@ func (c *grpcMetadataNSClient) Unregister(ctx context.Context, ns *registry.Netw resp, err := next.NetworkServiceRegistryClient(ctx).Unregister(ctx, ns, opts...) if err != nil { - return nil, err + return nil, errors.WithStack(err) } newpath, err := fromMD(header) diff --git a/pkg/registry/common/grpcmetadata/ns_server.go b/pkg/registry/common/grpcmetadata/ns_server.go index 53ef0d2f2f..77f8b4e9ab 100644 --- a/pkg/registry/common/grpcmetadata/ns_server.go +++ b/pkg/registry/common/grpcmetadata/ns_server.go @@ -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 // @@ -20,6 +20,7 @@ import ( "context" "github.com/golang/protobuf/ptypes/empty" + "github.com/pkg/errors" "github.com/networkservicemesh/api/pkg/api/registry" @@ -49,7 +50,7 @@ func (s *grpcMetadataNSServer) Register(ctx context.Context, ns *registry.Networ resp, err := next.NetworkServiceRegistryServer(ctx).Register(ctx, ns) if err != nil { - return nil, err + return nil, errors.WithStack(err) } err = sendPath(ctx, path) @@ -73,7 +74,7 @@ func (s *grpcMetadataNSServer) Unregister(ctx context.Context, ns *registry.Netw resp, err := next.NetworkServiceRegistryServer(ctx).Unregister(ctx, ns) if err != nil { - return nil, err + return nil, errors.WithStack(err) } err = sendPath(ctx, path) diff --git a/pkg/registry/common/grpcmetadata/nse_client.go b/pkg/registry/common/grpcmetadata/nse_client.go index b77ba989b0..9897eb3140 100644 --- a/pkg/registry/common/grpcmetadata/nse_client.go +++ b/pkg/registry/common/grpcmetadata/nse_client.go @@ -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 // @@ -20,6 +20,7 @@ import ( "context" "github.com/golang/protobuf/ptypes/empty" + "github.com/pkg/errors" "google.golang.org/grpc" "google.golang.org/grpc/metadata" @@ -48,7 +49,7 @@ func (c *grpcMetadataNSEClient) Register(ctx context.Context, nse *registry.Netw opts = append(opts, grpc.Header(&header)) resp, err := next.NetworkServiceEndpointRegistryClient(ctx).Register(ctx, nse, opts...) if err != nil { - return nil, err + return nil, errors.WithStack(err) } newpath, err := fromMD(header) @@ -78,7 +79,7 @@ func (c *grpcMetadataNSEClient) Unregister(ctx context.Context, nse *registry.Ne resp, err := next.NetworkServiceEndpointRegistryClient(ctx).Unregister(ctx, nse, opts...) if err != nil { - return nil, err + return nil, errors.WithStack(err) } newpath, err := fromMD(header) diff --git a/pkg/registry/common/grpcmetadata/nse_server.go b/pkg/registry/common/grpcmetadata/nse_server.go index d7a3384873..3308c5fb65 100644 --- a/pkg/registry/common/grpcmetadata/nse_server.go +++ b/pkg/registry/common/grpcmetadata/nse_server.go @@ -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 // @@ -20,6 +20,7 @@ import ( "context" "github.com/golang/protobuf/ptypes/empty" + "github.com/pkg/errors" "github.com/networkservicemesh/api/pkg/api/registry" @@ -47,7 +48,7 @@ func (s *grpcMetadataNSEServer) Register(ctx context.Context, nse *registry.Netw resp, err := next.NetworkServiceEndpointRegistryServer(ctx).Register(ctx, nse) if err != nil { - return nil, err + return nil, errors.WithStack(err) } err = sendPath(ctx, path) @@ -71,7 +72,7 @@ func (s *grpcMetadataNSEServer) Unregister(ctx context.Context, nse *registry.Ne resp, err := next.NetworkServiceEndpointRegistryServer(ctx).Unregister(ctx, nse) if err != nil { - return nil, err + return nil, errors.WithStack(err) } err = sendPath(ctx, path) diff --git a/pkg/registry/common/heal/ns_client.go b/pkg/registry/common/heal/ns_client.go index ab791fed8e..2e8f8d0dca 100644 --- a/pkg/registry/common/heal/ns_client.go +++ b/pkg/registry/common/heal/ns_client.go @@ -1,5 +1,7 @@ // Copyright (c) 2021-2022 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"); @@ -21,6 +23,7 @@ import ( "github.com/golang/protobuf/ptypes/empty" "github.com/networkservicemesh/api/pkg/api/registry" + "github.com/pkg/errors" "google.golang.org/grpc" "google.golang.org/protobuf/proto" @@ -44,7 +47,7 @@ func (c *healNSClient) Register(ctx context.Context, ns *registry.NetworkService resp, err := next.NetworkServiceRegistryClient(ctx).Register(ctx, ns.Clone(), opts...) if err != nil { - return nil, err + return nil, errors.WithStack(err) } factory := begin.FromContext(ctx) @@ -58,7 +61,7 @@ func (c *healNSClient) Register(ctx context.Context, ns *registry.NetworkService if streamErr != nil { cancel() - return nil, streamErr + return nil, errors.WithStack(streamErr) } c.Store(ns.GetName(), cancel) @@ -73,7 +76,7 @@ func (c *healNSClient) Register(ctx context.Context, ns *registry.NetworkService } }() - return resp, err + return resp, nil } func (c *healNSClient) Find(ctx context.Context, query *registry.NetworkServiceQuery, opts ...grpc.CallOption) (registry.NetworkServiceRegistry_FindClient, error) { @@ -93,7 +96,7 @@ func (c *healNSClient) Find(ctx context.Context, query *registry.NetworkServiceQ queryClone := proto.Clone(query).(*registry.NetworkServiceQuery) stream, err := nextClient.Find(ctx, queryClone, opts...) if err != nil { - return nil, err + return nil, errors.WithStack(err) } clientCtx, clientCancel := context.WithCancel(c.ctx) diff --git a/pkg/registry/common/heal/ns_find_client.go b/pkg/registry/common/heal/ns_find_client.go index b5234dfbec..ed31709562 100644 --- a/pkg/registry/common/heal/ns_find_client.go +++ b/pkg/registry/common/heal/ns_find_client.go @@ -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"); @@ -20,6 +22,7 @@ import ( "context" "github.com/networkservicemesh/api/pkg/api/registry" + "github.com/pkg/errors" ) type healNSFindClient struct { @@ -32,7 +35,7 @@ type healNSFindClient struct { func (c *healNSFindClient) Recv() (*registry.NetworkServiceResponse, error) { if c.err != nil { - return nil, c.err + return nil, errors.WithStack(c.err) } nsResp, err := c.NetworkServiceRegistry_FindClient.Recv() @@ -41,13 +44,13 @@ func (c *healNSFindClient) Recv() (*registry.NetworkServiceResponse, error) { for ; err != nil; c.NetworkServiceRegistry_FindClient, err = c.createStream() { if c.ctx.Err() != nil { c.err = c.ctx.Err() - return nil, c.err + return nil, errors.WithStack(c.err) } } if c.ctx.Err() != nil { c.err = c.ctx.Err() - return nil, c.err + return nil, errors.WithStack(c.err) } } diff --git a/pkg/registry/common/heal/nse_client.go b/pkg/registry/common/heal/nse_client.go index d35eee93b8..879609328d 100644 --- a/pkg/registry/common/heal/nse_client.go +++ b/pkg/registry/common/heal/nse_client.go @@ -1,5 +1,7 @@ // Copyright (c) 2021-2022 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"); @@ -21,6 +23,7 @@ import ( "github.com/golang/protobuf/ptypes/empty" "github.com/networkservicemesh/api/pkg/api/registry" + "github.com/pkg/errors" "google.golang.org/grpc" "google.golang.org/protobuf/proto" @@ -44,7 +47,7 @@ func (c *healNSEClient) Register(ctx context.Context, nse *registry.NetworkServi resp, err := next.NetworkServiceEndpointRegistryClient(ctx).Register(ctx, nse.Clone(), opts...) if err != nil { - return nil, err + return nil, errors.WithStack(err) } factory := begin.FromContext(ctx) @@ -58,7 +61,7 @@ func (c *healNSEClient) Register(ctx context.Context, nse *registry.NetworkServi if streamErr != nil { cancel() - return nil, streamErr + return nil, errors.WithStack(streamErr) } c.Store(nse.GetName(), cancel) @@ -73,7 +76,7 @@ func (c *healNSEClient) Register(ctx context.Context, nse *registry.NetworkServi } }() - return resp, err + return resp, nil } func (c *healNSEClient) Find(ctx context.Context, query *registry.NetworkServiceEndpointQuery, opts ...grpc.CallOption) (registry.NetworkServiceEndpointRegistry_FindClient, error) { @@ -93,7 +96,7 @@ func (c *healNSEClient) Find(ctx context.Context, query *registry.NetworkService queryClone := proto.Clone(query).(*registry.NetworkServiceEndpointQuery) stream, err := nextClient.Find(ctx, queryClone, opts...) if err != nil { - return nil, err + return nil, errors.WithStack(err) } clientCtx, clientCancel := context.WithCancel(c.ctx) diff --git a/pkg/registry/common/heal/nse_find_client.go b/pkg/registry/common/heal/nse_find_client.go index 6420f7279c..ec1f31f5ff 100644 --- a/pkg/registry/common/heal/nse_find_client.go +++ b/pkg/registry/common/heal/nse_find_client.go @@ -1,5 +1,7 @@ // Copyright (c) 2021-2022 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"); @@ -20,6 +22,7 @@ import ( "context" "github.com/networkservicemesh/api/pkg/api/registry" + "github.com/pkg/errors" ) type healNSEFindClient struct { @@ -32,7 +35,7 @@ type healNSEFindClient struct { func (c *healNSEFindClient) Recv() (*registry.NetworkServiceEndpointResponse, error) { if c.err != nil { - return nil, c.err + return nil, errors.WithStack(c.err) } nseResp, err := c.NetworkServiceEndpointRegistry_FindClient.Recv() @@ -41,13 +44,13 @@ func (c *healNSEFindClient) Recv() (*registry.NetworkServiceEndpointResponse, er for ; err != nil; c.NetworkServiceEndpointRegistry_FindClient, err = c.createStream() { if c.ctx.Err() != nil { c.err = c.ctx.Err() - return nil, c.err + return nil, errors.WithStack(c.err) } } if c.ctx.Err() != nil { c.err = c.ctx.Err() - return nil, c.err + return nil, errors.WithStack(c.err) } } diff --git a/pkg/registry/common/heal/sync_map.gen.go b/pkg/registry/common/heal/sync_map.gen.go index e37bb8fc81..dd20912eb3 100644 --- a/pkg/registry/common/heal/sync_map.gen.go +++ b/pkg/registry/common/heal/sync_map.gen.go @@ -1,4 +1,6 @@ // Code generated by "-output sync_map.gen.go -type cancelsMap -output sync_map.gen.go -type cancelsMap"; DO NOT EDIT. +// Install -output sync_map.gen.go -type cancelsMap by "go get -u github.com/searKing/golang/tools/-output sync_map.gen.go -type cancelsMap" + package heal import ( diff --git a/pkg/registry/common/interdomainbypass/server.go b/pkg/registry/common/interdomainbypass/server.go index dfa61c1f35..bc2ebaad39 100644 --- a/pkg/registry/common/interdomainbypass/server.go +++ b/pkg/registry/common/interdomainbypass/server.go @@ -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 // @@ -23,6 +23,7 @@ import ( "github.com/golang/protobuf/ptypes/empty" "github.com/networkservicemesh/api/pkg/api/registry" + "github.com/pkg/errors" "github.com/networkservicemesh/sdk/pkg/registry/core/next" "github.com/networkservicemesh/sdk/pkg/tools/stringurl" @@ -46,7 +47,7 @@ func (n *interdomainBypassNSEServer) Register(ctx context.Context, service *regi resp, err := next.NetworkServiceEndpointRegistryServer(ctx).Register(ctx, service) if err != nil { - return nil, err + return nil, errors.WithStack(err) } u, _ := url.Parse(originalURL) @@ -55,7 +56,7 @@ func (n *interdomainBypassNSEServer) Register(ctx context.Context, service *regi resp.Url = originalURL - return resp, err + return resp, errors.WithStack(err) } func (n *interdomainBypassNSEServer) Find(query *registry.NetworkServiceEndpointQuery, server registry.NetworkServiceEndpointRegistry_FindServer) error { @@ -88,7 +89,7 @@ func NewNetworkServiceEndpointRegistryServer(m *stringurl.Map, u *url.URL) regis func (s *interdomainBypassNSEFindServer) Send(nseResp *registry.NetworkServiceEndpointResponse) error { u, err := url.Parse(nseResp.GetNetworkServiceEndpoint().GetUrl()) if err != nil { - return err + return errors.WithStack(err) } s.m.LoadOrStore(nseResp.NetworkServiceEndpoint.GetName(), u) nseResp.GetNetworkServiceEndpoint().Url = s.u.String() diff --git a/pkg/registry/common/localbypass/server.go b/pkg/registry/common/localbypass/server.go index f694397072..84900f1c71 100644 --- a/pkg/registry/common/localbypass/server.go +++ b/pkg/registry/common/localbypass/server.go @@ -1,5 +1,7 @@ // Copyright (c) 2020-2022 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"); @@ -66,10 +68,10 @@ func (s *localBypassNSEServer) Register(ctx context.Context, nse *registry.Netwo if !loaded || u.String() != nse.Url { u, err = url.Parse(nse.Url) if err != nil { - return nil, errors.Wrapf(err, "cannot register NSE with passed URL: %s", nse.Url) + return nil, errors.WithStack(errors.Wrapf(err, "cannot register NSE with passed URL: %s", nse.Url)) } if u.String() == "" { - return nil, errors.Errorf("cannot register NSE with passed URL: %s", nse.Url) + return nil, errors.WithStack(errors.Errorf("cannot register NSE with passed URL: %s", nse.Url)) } s.nseURLs.Store(nse.Name, u) } @@ -81,7 +83,7 @@ func (s *localBypassNSEServer) Register(ctx context.Context, nse *registry.Netwo if !loaded { s.nseURLs.Delete(nse.Name) } - return nil, err + return nil, errors.WithStack(err) } reg.Url = u.String() @@ -105,5 +107,5 @@ func (s *localBypassNSEServer) Unregister(ctx context.Context, nse *registry.Net s.nseURLs.Delete(nse.Name) } - return new(empty.Empty), err + return new(empty.Empty), errors.WithStack(err) } diff --git a/pkg/registry/common/memory/ns_server.go b/pkg/registry/common/memory/ns_server.go index 87de28be35..07d5853b34 100644 --- a/pkg/registry/common/memory/ns_server.go +++ b/pkg/registry/common/memory/ns_server.go @@ -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"); @@ -23,6 +25,7 @@ import ( "github.com/edwarnicke/serialize" "github.com/golang/protobuf/ptypes/empty" "github.com/google/uuid" + "github.com/pkg/errors" "github.com/networkservicemesh/api/pkg/api/registry" @@ -56,7 +59,7 @@ func (s *memoryNSServer) setEventChannelSize(l int) { func (s *memoryNSServer) Register(ctx context.Context, ns *registry.NetworkService) (*registry.NetworkService, error) { r, err := next.NetworkServiceRegistryServer(ctx).Register(ctx, ns) if err != nil { - return nil, err + return nil, errors.WithStack(err) } s.networkServices.Store(r.Name, r.Clone()) @@ -83,7 +86,7 @@ func (s *memoryNSServer) Find(query *registry.NetworkServiceQuery, server regist } if err := server.Send(nsResp); err != nil { - return err + return errors.WithStack(err) } } return next.NetworkServiceRegistryServer(server.Context()).Find(query, server) @@ -104,7 +107,7 @@ func (s *memoryNSServer) Find(query *registry.NetworkServiceQuery, server regist for ; err == nil; err = s.receiveEvent(query, server, eventCh) { } if err != io.EOF { - return err + return errors.WithStack(err) } return next.NetworkServiceRegistryServer(server.Context()).Find(query, server) } @@ -143,7 +146,7 @@ func (s *memoryNSServer) receiveEvent( ) error { select { case <-server.Context().Done(): - return io.EOF + return errors.WithStack(io.EOF) case event := <-eventCh: if matchutils.MatchNetworkServices(query.NetworkService, event) { nse := ®istry.NetworkServiceResponse{ @@ -152,9 +155,9 @@ func (s *memoryNSServer) receiveEvent( if err := server.Send(nse); err != nil { if server.Context().Err() != nil { - return io.EOF + return errors.WithStack(io.EOF) } - return err + return errors.WithStack(err) } } return nil diff --git a/pkg/registry/common/memory/ns_sync_map.gen.go b/pkg/registry/common/memory/ns_sync_map.gen.go index a038732818..060e25cc3b 100644 --- a/pkg/registry/common/memory/ns_sync_map.gen.go +++ b/pkg/registry/common/memory/ns_sync_map.gen.go @@ -1,4 +1,6 @@ // Code generated by "-output ns_sync_map.gen.go -type NetworkServiceSyncMap -output ns_sync_map.gen.go -type NetworkServiceSyncMap"; DO NOT EDIT. +// Install -output ns_sync_map.gen.go -type NetworkServiceSyncMap by "go get -u github.com/searKing/golang/tools/-output ns_sync_map.gen.go -type NetworkServiceSyncMap" + package memory import ( diff --git a/pkg/registry/common/memory/nse_server.go b/pkg/registry/common/memory/nse_server.go index f74fcc909d..8d61b8c025 100644 --- a/pkg/registry/common/memory/nse_server.go +++ b/pkg/registry/common/memory/nse_server.go @@ -1,5 +1,7 @@ // Copyright (c) 2020-2022 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"); @@ -23,6 +25,7 @@ import ( "github.com/edwarnicke/serialize" "github.com/golang/protobuf/ptypes/empty" "github.com/google/uuid" + "github.com/pkg/errors" "github.com/networkservicemesh/api/pkg/api/registry" @@ -56,14 +59,14 @@ func (s *memoryNSEServer) setEventChannelSize(l int) { func (s *memoryNSEServer) Register(ctx context.Context, nse *registry.NetworkServiceEndpoint) (*registry.NetworkServiceEndpoint, error) { r, err := next.NetworkServiceEndpointRegistryServer(ctx).Register(ctx, nse) if err != nil { - return nil, err + return nil, errors.WithStack(err) } s.networkServiceEndpoints.Store(r.Name, r.Clone()) s.sendEvent(®istry.NetworkServiceEndpointResponse{NetworkServiceEndpoint: r}) - return r, err + return r, nil } func (s *memoryNSEServer) sendEvent(event *registry.NetworkServiceEndpointResponse) { @@ -82,14 +85,14 @@ func (s *memoryNSEServer) Find(query *registry.NetworkServiceEndpointQuery, serv NetworkServiceEndpoint: nse, } if err := server.Send(nseResp); err != nil { - return err + return errors.WithStack(err) } } return next.NetworkServiceEndpointRegistryServer(server.Context()).Find(query, server) } if err := next.NetworkServiceEndpointRegistryServer(server.Context()).Find(query, server); err != nil { - return err + return errors.WithStack(err) } eventCh := make(chan *registry.NetworkServiceEndpointResponse, s.eventChannelSize) @@ -107,7 +110,7 @@ func (s *memoryNSEServer) Find(query *registry.NetworkServiceEndpointQuery, serv for ; err == nil; err = s.receiveEvent(query, server, eventCh) { } if err != io.EOF { - return err + return errors.WithStack(err) } return nil } @@ -146,14 +149,14 @@ func (s *memoryNSEServer) receiveEvent( ) error { select { case <-server.Context().Done(): - return io.EOF + return errors.WithStack(io.EOF) case event := <-eventCh: if matchutils.MatchNetworkServiceEndpoints(query.NetworkServiceEndpoint, event.NetworkServiceEndpoint) { if err := server.Send(event); err != nil { if server.Context().Err() != nil { - return io.EOF + return errors.WithStack(io.EOF) } - return err + return errors.WithStack(err) } } return nil diff --git a/pkg/registry/common/memory/nse_sync_map.gen.go b/pkg/registry/common/memory/nse_sync_map.gen.go index 4b1d664282..df08559945 100644 --- a/pkg/registry/common/memory/nse_sync_map.gen.go +++ b/pkg/registry/common/memory/nse_sync_map.gen.go @@ -1,4 +1,6 @@ // Code generated by "-output nse_sync_map.gen.go -type NetworkServiceEndpointSyncMap -output nse_sync_map.gen.go -type NetworkServiceEndpointSyncMap"; DO NOT EDIT. +// Install -output nse_sync_map.gen.go -type NetworkServiceEndpointSyncMap by "go get -u github.com/searKing/golang/tools/-output nse_sync_map.gen.go -type NetworkServiceEndpointSyncMap" + package memory import ( diff --git a/pkg/registry/common/querycache/cache_entry_map.gen.go b/pkg/registry/common/querycache/cache_entry_map.gen.go index e50a207f46..112ab60608 100644 --- a/pkg/registry/common/querycache/cache_entry_map.gen.go +++ b/pkg/registry/common/querycache/cache_entry_map.gen.go @@ -1,4 +1,6 @@ // Code generated by "-output cache_entry_map.gen.go -type cacheEntryMap -output cache_entry_map.gen.go -type cacheEntryMap"; DO NOT EDIT. +// Install -output cache_entry_map.gen.go -type cacheEntryMap by "go get -u github.com/searKing/golang/tools/-output cache_entry_map.gen.go -type cacheEntryMap" + package querycache import ( diff --git a/pkg/registry/common/querycache/nse_client.go b/pkg/registry/common/querycache/nse_client.go index efc37f204e..f4bcc4f1c9 100644 --- a/pkg/registry/common/querycache/nse_client.go +++ b/pkg/registry/common/querycache/nse_client.go @@ -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"); @@ -21,6 +23,7 @@ import ( "context" "github.com/golang/protobuf/ptypes/empty" + "github.com/pkg/errors" "google.golang.org/grpc" "github.com/networkservicemesh/api/pkg/api/registry" @@ -57,7 +60,7 @@ func (q *queryCacheNSEClient) Find(ctx context.Context, query *registry.NetworkS client, err := next.NetworkServiceEndpointRegistryClient(ctx).Find(ctx, query, opts...) if err != nil { - return nil, err + return nil, errors.WithStack(err) } nses := registry.ReadNetworkServiceEndpointList(client) diff --git a/pkg/registry/common/recvfd/client.go b/pkg/registry/common/recvfd/client.go index 8efe55ed07..35436cbf83 100644 --- a/pkg/registry/common/recvfd/client.go +++ b/pkg/registry/common/recvfd/client.go @@ -1,7 +1,7 @@ -// Copyright (c) 2021-2022 Cisco and/or its affiliates. -// // Copyright (c) 2021-2022 Doc.ai and/or its affiliates. // +// Copyright (c) 2021-2023 Cisco and/or its affiliates. +// // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -29,6 +29,7 @@ import ( "github.com/edwarnicke/grpcfd" "github.com/golang/protobuf/ptypes/empty" "github.com/networkservicemesh/api/pkg/api/registry" + "github.com/pkg/errors" "google.golang.org/grpc" "github.com/networkservicemesh/sdk/pkg/registry/core/next" @@ -48,7 +49,7 @@ func (n *recvfdNSEClient) Find(ctx context.Context, in *registry.NetworkServiceE recv, _ := grpcfd.FromPerRPCCredentials(rpcCredentials) resp, err := next.NetworkServiceEndpointRegistryClient(ctx).Find(ctx, in, opts...) if err != nil { - return nil, err + return nil, errors.WithStack(err) } return &recvfdNSEFindClient{ transceiver: recv, @@ -75,7 +76,7 @@ type recvfdNSEFindClient struct { func (x *recvfdNSEFindClient) Recv() (*registry.NetworkServiceEndpointResponse, error) { nseResp, err := x.NetworkServiceEndpointRegistry_FindClient.Recv() if err != nil { - return nil, err + return nil, errors.WithStack(err) } if x.transceiver != nil { // Get the fileMap diff --git a/pkg/registry/common/recvfd/per_endpoint_file_map.gen.go b/pkg/registry/common/recvfd/per_endpoint_file_map.gen.go index 517157b87d..f53d0835a6 100644 --- a/pkg/registry/common/recvfd/per_endpoint_file_map.gen.go +++ b/pkg/registry/common/recvfd/per_endpoint_file_map.gen.go @@ -1,4 +1,6 @@ // Code generated by "-output per_endpoint_file_map.gen.go -type perEndpointFileMapMap -output per_endpoint_file_map.gen.go -type perEndpointFileMapMap"; DO NOT EDIT. +// Install -output per_endpoint_file_map.gen.go -type perEndpointFileMapMap by "go get -u github.com/searKing/golang/tools/-output per_endpoint_file_map.gen.go -type perEndpointFileMapMap" + package recvfd import ( diff --git a/pkg/registry/common/recvfd/server.go b/pkg/registry/common/recvfd/server.go index 8a964408a5..09f7d29097 100644 --- a/pkg/registry/common/recvfd/server.go +++ b/pkg/registry/common/recvfd/server.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020-2022 Cisco and/or its affiliates. +// Copyright (c) 2020-2023 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -160,7 +160,7 @@ func recvFDAndSwapInodeToUnix(ctx context.Context, fileMap *perEndpointFileMap, // Wait for the file to arrive on the fileCh or the context to expire select { case <-ctx.Done(): - err = ctx.Err() + err = errors.WithStack(ctx.Err()) return case file = <-fileCh: // If we get the file, remember it in the fileMap so we can reuse it later diff --git a/pkg/registry/common/refresh/nse_registry_client.go b/pkg/registry/common/refresh/nse_registry_client.go index ce154c377e..fa1f2866d4 100644 --- a/pkg/registry/common/refresh/nse_registry_client.go +++ b/pkg/registry/common/refresh/nse_registry_client.go @@ -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 // @@ -20,6 +20,7 @@ import ( "context" "github.com/golang/protobuf/ptypes/empty" + "github.com/pkg/errors" "google.golang.org/grpc" "github.com/networkservicemesh/api/pkg/api/registry" @@ -48,7 +49,7 @@ func (c *refreshNSEClient) Register(ctx context.Context, nse *registry.NetworkSe resp, err := next.NetworkServiceEndpointRegistryClient(ctx).Register(ctx, nse, opts...) if err != nil { - return nil, err + return nil, errors.WithStack(err) } refreshCtx, cancel := context.WithCancel(c.ctx) @@ -74,7 +75,7 @@ func (c *refreshNSEClient) Register(ctx context.Context, nse *registry.NetworkSe }() } - return resp, err + return resp, nil } func (c *refreshNSEClient) Find(ctx context.Context, query *registry.NetworkServiceEndpointQuery, opts ...grpc.CallOption) (registry.NetworkServiceEndpointRegistry_FindClient, error) { diff --git a/pkg/registry/common/refresh/sync_map.gen.go b/pkg/registry/common/refresh/sync_map.gen.go index 151c5b79de..708746358d 100644 --- a/pkg/registry/common/refresh/sync_map.gen.go +++ b/pkg/registry/common/refresh/sync_map.gen.go @@ -1,4 +1,6 @@ // Code generated by "-output sync_map.gen.go -type cancelsMap -output sync_map.gen.go -type cancelsMap"; DO NOT EDIT. +// Install -output sync_map.gen.go -type cancelsMap by "go get -u github.com/searKing/golang/tools/-output sync_map.gen.go -type cancelsMap" + package refresh import ( diff --git a/pkg/registry/common/retry/ns_client.go b/pkg/registry/common/retry/ns_client.go index c0cf26ccc0..f8c0aa1609 100644 --- a/pkg/registry/common/retry/ns_client.go +++ b/pkg/registry/common/retry/ns_client.go @@ -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 // @@ -21,6 +21,7 @@ import ( "time" "github.com/networkservicemesh/api/pkg/api/registry" + "github.com/pkg/errors" "google.golang.org/grpc" "google.golang.org/protobuf/types/known/emptypb" @@ -67,22 +68,22 @@ func (r *retryNSClient) Register(ctx context.Context, in *registry.NetworkServic select { case <-r.chainCtx.Done(): - return nil, r.chainCtx.Err() + return nil, errors.WithStack(r.chainCtx.Err()) case <-ctx.Done(): - return nil, ctx.Err() + return nil, errors.WithStack(ctx.Err()) case <-c.After(r.interval): continue } } - return resp, err + return resp, errors.WithStack(err) } if r.chainCtx.Err() != nil { - return nil, r.chainCtx.Err() + return nil, errors.WithStack(r.chainCtx.Err()) } - return nil, ctx.Err() + return nil, errors.WithStack(ctx.Err()) } func (r *retryNSClient) Find(ctx context.Context, query *registry.NetworkServiceQuery, opts ...grpc.CallOption) (registry.NetworkServiceRegistry_FindClient, error) { @@ -98,14 +99,14 @@ func (r *retryNSClient) Find(ctx context.Context, query *registry.NetworkService continue } - return stream, err + return stream, errors.WithStack(err) } if r.chainCtx.Err() != nil { - return nil, r.chainCtx.Err() + return nil, errors.WithStack(r.chainCtx.Err()) } - return nil, ctx.Err() + return nil, errors.WithStack(ctx.Err()) } func (r *retryNSClient) Unregister(ctx context.Context, in *registry.NetworkService, opts ...grpc.CallOption) (*emptypb.Empty, error) { @@ -122,19 +123,19 @@ func (r *retryNSClient) Unregister(ctx context.Context, in *registry.NetworkServ select { case <-r.chainCtx.Done(): - return nil, r.chainCtx.Err() + return nil, errors.WithStack(r.chainCtx.Err()) case <-ctx.Done(): - return nil, ctx.Err() + return nil, errors.WithStack(ctx.Err()) case <-c.After(r.interval): continue } } - return resp, err + return resp, errors.WithStack(err) } if r.chainCtx.Err() != nil { - return nil, r.chainCtx.Err() + return nil, errors.WithStack(r.chainCtx.Err()) } - return nil, ctx.Err() + return nil, errors.WithStack(ctx.Err()) } diff --git a/pkg/registry/common/retry/nse_client.go b/pkg/registry/common/retry/nse_client.go index 9a458feb7a..bd17de095b 100644 --- a/pkg/registry/common/retry/nse_client.go +++ b/pkg/registry/common/retry/nse_client.go @@ -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 // @@ -21,6 +21,7 @@ import ( "time" "github.com/networkservicemesh/api/pkg/api/registry" + "github.com/pkg/errors" "google.golang.org/grpc" "google.golang.org/protobuf/types/known/emptypb" @@ -67,18 +68,18 @@ func (r *retryNSEClient) Register(ctx context.Context, nse *registry.NetworkServ select { case <-r.chainCtx.Done(): - return nil, err + return nil, errors.WithStack(err) case <-ctx.Done(): - return nil, ctx.Err() + return nil, errors.WithStack(ctx.Err()) case <-c.After(r.interval): continue } } - return resp, err + return resp, errors.WithStack(err) } - return nil, ctx.Err() + return nil, errors.WithStack(ctx.Err()) } func (r *retryNSEClient) Find(ctx context.Context, query *registry.NetworkServiceEndpointQuery, opts ...grpc.CallOption) (registry.NetworkServiceEndpointRegistry_FindClient, error) { diff --git a/pkg/registry/common/sendfd/client_linux.go b/pkg/registry/common/sendfd/client_linux.go index 532dfe4cdb..c68030b0ce 100644 --- a/pkg/registry/common/sendfd/client_linux.go +++ b/pkg/registry/common/sendfd/client_linux.go @@ -1,7 +1,7 @@ -// Copyright (c) 2020-2022 Cisco and/or its affiliates. -// // Copyright (c) 2021-2022 Doc.ai and/or its affiliates. // +// Copyright (c) 2020-2023 Cisco and/or its affiliates. +// // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -57,7 +57,7 @@ func (s *sendFDNSEClient) Register(ctx context.Context, endpoint *registry.Netwo returnedEndpoint, err := next.NetworkServiceEndpointRegistryClient(ctx).Register(ctx, endpoint, opts...) if err != nil { - return nil, err + return nil, errors.WithStack(err) } // Translate the InodeURl mechanism *back to a proper file://${path} url @@ -85,7 +85,7 @@ func (s *sendFDNSEClient) Unregister(ctx context.Context, endpoint *registry.Net _, err := next.NetworkServiceEndpointRegistryClient(ctx).Unregister(ctx, endpoint, opts...) if err != nil { - return nil, err + return nil, errors.WithStack(err) } // Translate the InodeURl mechanism *back to a proper file://${path} url diff --git a/pkg/registry/common/swapip/nse_registry.go b/pkg/registry/common/swapip/nse_registry.go index 697b206d1d..1a92da9458 100644 --- a/pkg/registry/common/swapip/nse_registry.go +++ b/pkg/registry/common/swapip/nse_registry.go @@ -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"); @@ -25,6 +27,7 @@ import ( "github.com/golang/protobuf/ptypes/empty" "github.com/networkservicemesh/api/pkg/api/registry" + "github.com/pkg/errors" "github.com/networkservicemesh/sdk/pkg/registry/core/next" "github.com/networkservicemesh/sdk/pkg/tools/log" @@ -52,7 +55,7 @@ func (n *swapIPNSEServer) Register(ctx context.Context, nse *registry.NetworkSer if err == nil { trySwapIP(ctx, resp, m) } - return resp, err + return resp, errors.WithStack(err) } func (n *swapIPNSEServer) Find(query *registry.NetworkServiceEndpointQuery, server registry.NetworkServiceEndpointRegistry_FindServer) error { diff --git a/pkg/registry/common/updatepath/common.go b/pkg/registry/common/updatepath/common.go index b599aad59e..c3ef39895c 100644 --- a/pkg/registry/common/updatepath/common.go +++ b/pkg/registry/common/updatepath/common.go @@ -1,6 +1,6 @@ // Copyright (c) 2020-2021 Doc.ai and/or its affiliates. // -// Copyright (c) 2022 Cisco Systems, Inc. +// Copyright (c) 2022-2023 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -35,7 +35,7 @@ import ( func updatePath(path *grpcmetadata.Path, peerTok, tok string) (*grpcmetadata.Path, uint32, error) { if path == nil { - return nil, 0, errors.New("updatePath cannot be called with a nil path") + return nil, 0, errors.WithStack(errors.New("updatePath cannot be called with a nil path")) } // Empty path from client means first request @@ -52,8 +52,8 @@ func updatePath(path *grpcmetadata.Path, peerTok, tok string) (*grpcmetadata.Pat // Check if path.Index is correct currentIndex := int(path.Index) + 1 if currentIndex > len(path.PathSegments) { - return nil, 0, errors.Errorf("Path.Index+1==%d should be less or equal len(Path.PathSegments)==%d", - currentIndex, len(path.PathSegments)) + return nil, 0, errors.WithStack(errors.Errorf("Path.Index+1==%d should be less or equal len(Path.PathSegments)==%d", + currentIndex, len(path.PathSegments))) } // Get previous and current PathSegment @@ -94,16 +94,16 @@ func getIDFromToken(tokenString string) (spiffeid.ID, error) { claims := jwt.MapClaims{} _, _, err := jwt.NewParser().ParseUnverified(tokenString, &claims) if err != nil { - return spiffeid.ID{}, errors.Errorf("failed to parse jwt token: %s", err.Error()) + return spiffeid.ID{}, errors.WithStack(errors.Errorf("failed to parse jwt token: %s", err.Error())) } sub, ok := claims["sub"] if !ok { - return spiffeid.ID{}, errors.New("failed to get field 'sub' from jwt token payload") + return spiffeid.ID{}, errors.WithStack(errors.New("failed to get field 'sub' from jwt token payload")) } subString, ok := sub.(string) if !ok { - return spiffeid.ID{}, errors.New("failed to convert field 'sub' from jwt token payload to string") + return spiffeid.ID{}, errors.WithStack(errors.New("failed to convert field 'sub' from jwt token payload to string")) } return spiffeid.FromString(subString) } diff --git a/pkg/registry/common/updatepath/ns_server.go b/pkg/registry/common/updatepath/ns_server.go index ee6fc06337..656e91a16e 100644 --- a/pkg/registry/common/updatepath/ns_server.go +++ b/pkg/registry/common/updatepath/ns_server.go @@ -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 // @@ -52,7 +52,7 @@ func (s *updatePathNSServer) Register(ctx context.Context, ns *registry.NetworkS } tok, _, tokenErr := generateToken(ctx, s.tokenGenerator) if tokenErr != nil { - return nil, errors.Wrap(tokenErr, "an error during generating token") + return nil, errors.WithStack(errors.Wrap(tokenErr, "an error during generating token")) } path, index, err := updatePath(path, peerTok, tok) if err != nil { @@ -73,11 +73,11 @@ func (s *updatePathNSServer) Register(ctx context.Context, ns *registry.NetworkS ns, err = next.NetworkServiceRegistryServer(ctx).Register(ctx, ns) if err != nil { - return nil, err + return nil, errors.WithStack(err) } path.Index = index - return ns, err + return ns, nil } func (s *updatePathNSServer) Find(query *registry.NetworkServiceQuery, server registry.NetworkServiceRegistry_FindServer) error { @@ -93,7 +93,7 @@ func (s *updatePathNSServer) Unregister(ctx context.Context, ns *registry.Networ } tok, _, tokenErr := generateToken(ctx, s.tokenGenerator) if tokenErr != nil { - return nil, errors.Wrap(tokenErr, "an error during generating token") + return nil, errors.WithStack(errors.Wrap(tokenErr, "an error during generating token")) } path, index, err := updatePath(path, peerTok, tok) if err != nil { @@ -114,5 +114,5 @@ func (s *updatePathNSServer) Unregister(ctx context.Context, ns *registry.Networ resp, err := next.NetworkServiceRegistryServer(ctx).Unregister(ctx, ns) path.Index = index - return resp, err + return resp, errors.WithStack(err) } diff --git a/pkg/registry/core/adapters/ns_next_client.go b/pkg/registry/core/adapters/ns_next_client.go index c4c0f2f50e..d082c1173d 100644 --- a/pkg/registry/core/adapters/ns_next_client.go +++ b/pkg/registry/core/adapters/ns_next_client.go @@ -1,5 +1,7 @@ // Copyright (c) 2020 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"); @@ -20,6 +22,8 @@ import ( "context" "github.com/golang/protobuf/ptypes/empty" + "github.com/pkg/errors" + "github.com/networkservicemesh/api/pkg/api/registry" ) @@ -34,7 +38,7 @@ func (c *callNextNSClient) Register(ctx context.Context, in *registry.NetworkSer func (c *callNextNSClient) Find(query *registry.NetworkServiceQuery, server registry.NetworkServiceRegistry_FindServer) error { client, err := c.client.Find(server.Context(), query) if client == nil || err != nil { - return err + return errors.WithStack(err) } return nsFindClientToServer(client, server) } diff --git a/pkg/registry/core/adapters/ns_registry.go b/pkg/registry/core/adapters/ns_registry.go index 393e0b1336..21ab22f4fe 100644 --- a/pkg/registry/core/adapters/ns_registry.go +++ b/pkg/registry/core/adapters/ns_registry.go @@ -1,5 +1,7 @@ // Copyright (c) 2020-2021 Cisco Systems, Inc. // +// Copyright (c) 2023 Cisco and/or its affiliates. +// // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,11 +21,11 @@ package adapters import ( "context" - "errors" "io" "github.com/golang/protobuf/ptypes/empty" "github.com/networkservicemesh/api/pkg/api/registry" + "github.com/pkg/errors" "google.golang.org/grpc" "github.com/networkservicemesh/sdk/pkg/registry/core/next" @@ -47,7 +49,7 @@ func (n *networkServiceRegistryServer) Find(query *registry.NetworkServiceQuery, &callNextNSServer{server: next.NetworkServiceRegistryServer(server.Context())}, ).Find(server.Context(), query) if client == nil || err != nil { - return err + return errors.WithStack(err) } return nsFindClientToServer(client, server) } @@ -109,11 +111,11 @@ func nsFindClientToServer(client registry.NetworkServiceRegistry_FindClient, ser if errors.Is(err, io.EOF) { break } - return err + return errors.WithStack(err) } err = server.Send(msg) if err != nil { - return err + return errors.WithStack(err) } } return nil @@ -130,7 +132,7 @@ func nsFindServerToClient(ctx context.Context, server registry.NetworkServiceReg } else { defer close(ch) if err := server.Find(in, s); err != nil { - return nil, err + return nil, errors.WithStack(err) } } return streamchannel.NewNetworkServiceFindClient(ctx, ch), nil diff --git a/pkg/registry/core/adapters/nse_registry.go b/pkg/registry/core/adapters/nse_registry.go index e17d1f4b2f..6ab733feaa 100644 --- a/pkg/registry/core/adapters/nse_registry.go +++ b/pkg/registry/core/adapters/nse_registry.go @@ -1,5 +1,7 @@ // Copyright (c) 2020-2021 Cisco Systems, Inc. // +// Copyright (c) 2023 Cisco and/or its affiliates. +// // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,11 +21,11 @@ package adapters import ( "context" - "errors" "io" "github.com/golang/protobuf/ptypes/empty" "github.com/networkservicemesh/api/pkg/api/registry" + "github.com/pkg/errors" "google.golang.org/grpc" "github.com/networkservicemesh/sdk/pkg/registry/core/next" @@ -47,7 +49,7 @@ func (n *networkServiceEndpointRegistryServer) Find(query *registry.NetworkServi &callNextNSEServer{server: next.NetworkServiceEndpointRegistryServer(server.Context())}, ).Find(server.Context(), query) if client == nil || err != nil { - return err + return errors.WithStack(err) } return nseFindClientToServer(client, server) } @@ -109,11 +111,11 @@ func nseFindClientToServer(client registry.NetworkServiceEndpointRegistry_FindCl if errors.Is(err, io.EOF) { break } - return err + return errors.WithStack(err) } err = server.Send(msg) if err != nil { - return err + return errors.WithStack(err) } } return nil @@ -130,7 +132,7 @@ func nseFindServerToClient(ctx context.Context, server registry.NetworkServiceEn } else { defer close(ch) if err := server.Find(in, s); err != nil { - return nil, err + return nil, errors.WithStack(err) } } return streamchannel.NewNetworkServiceEndpointFindClient(ctx, ch), nil diff --git a/pkg/registry/core/streamchannel/ns_registry_stream_channel.go b/pkg/registry/core/streamchannel/ns_registry_stream_channel.go index daa95fb62b..116c90900b 100644 --- a/pkg/registry/core/streamchannel/ns_registry_stream_channel.go +++ b/pkg/registry/core/streamchannel/ns_registry_stream_channel.go @@ -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"); @@ -48,9 +50,9 @@ func (c *networkServiceRegistryFindClient) Recv() (*registry.NetworkServiceRespo if c.err == nil { return nil, err } - return res, errors.Wrap(c.err, err.Error()) + return res, errors.WithStack(errors.Wrap(c.err, err.Error())) } - return res, c.err + return res, errors.WithStack(c.err) } func (c *networkServiceRegistryFindClient) Context() context.Context { @@ -76,7 +78,7 @@ type networkServiceRegistryFindServer struct { func (s *networkServiceRegistryFindServer) Send(nsResp *registry.NetworkServiceResponse) error { select { case <-s.ctx.Done(): - return s.ctx.Err() + return errors.WithStack(s.ctx.Err()) case s.sendCh <- nsResp: return nil } diff --git a/pkg/registry/core/streamchannel/nse_registry_stream_channel.go b/pkg/registry/core/streamchannel/nse_registry_stream_channel.go index 600d9fc251..2d4ffdde2a 100644 --- a/pkg/registry/core/streamchannel/nse_registry_stream_channel.go +++ b/pkg/registry/core/streamchannel/nse_registry_stream_channel.go @@ -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"); @@ -49,9 +51,9 @@ func (c *networkServiceEndpointRegistryFindClient) Recv() (*registry.NetworkServ if c.err == nil { return nil, err } - return res, errors.Wrap(c.err, err.Error()) + return res, errors.WithStack(errors.Wrap(c.err, err.Error())) } - return res, c.err + return res, errors.WithStack(c.err) } func (c *networkServiceEndpointRegistryFindClient) Context() context.Context { diff --git a/pkg/registry/core/trace/common.go b/pkg/registry/core/trace/common.go index e2851d615f..354befc918 100644 --- a/pkg/registry/core/trace/common.go +++ b/pkg/registry/core/trace/common.go @@ -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"); @@ -37,10 +39,10 @@ func logError(ctx context.Context, err error, operation string) error { } err = errors.Wrapf(err, "Error returned from %s", operation) log.FromContext(ctx).Errorf("%+v", err) - return err + return errors.WithStack(err) } log.FromContext(ctx).Errorf("%v", err) - return err + return errors.WithStack(err) } func logObjectTrace(ctx context.Context, k, v interface{}) { diff --git a/pkg/registry/core/trace/ns_registry.go b/pkg/registry/core/trace/ns_registry.go index d0a6478cca..1307602f4a 100644 --- a/pkg/registry/core/trace/ns_registry.go +++ b/pkg/registry/core/trace/ns_registry.go @@ -1,5 +1,7 @@ // Copyright (c) 2020-2022 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"); @@ -19,13 +21,13 @@ package trace import ( "context" - "errors" "io" "github.com/networkservicemesh/sdk/pkg/registry/core/streamcontext" "github.com/networkservicemesh/sdk/pkg/tools/typeutils" "github.com/golang/protobuf/ptypes/empty" + "github.com/pkg/errors" "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -51,15 +53,15 @@ func (t *traceNetworkServiceRegistryFindClient) Recv() (*registry.NetworkService if err != nil { if errors.Is(err, io.EOF) { - return nil, err + return nil, errors.WithStack(err) } if status.Code(err) == codes.Canceled { - return nil, err + return nil, errors.WithStack(err) } return nil, logError(ctx, err, operation) } logObjectTrace(ctx, "recv-response", rv.NetworkService) - return rv, err + return rv, errors.WithStack(err) } func (t *traceNetworkServiceRegistryClient) Register(ctx context.Context, in *registry.NetworkService, opts ...grpc.CallOption) (*registry.NetworkService, error) { @@ -74,7 +76,7 @@ func (t *traceNetworkServiceRegistryClient) Register(ctx context.Context, in *re return nil, logError(ctx, err, operation) } logObjectTrace(ctx, "register-response", rv) - return rv, err + return rv, errors.WithStack(err) } func (t *traceNetworkServiceRegistryClient) Find(ctx context.Context, in *registry.NetworkServiceQuery, opts ...grpc.CallOption) (registry.NetworkServiceRegistry_FindClient, error) { operation := typeutils.GetFuncName(t.traced, "Find") @@ -106,7 +108,7 @@ func (t *traceNetworkServiceRegistryClient) Unregister(ctx context.Context, in * return nil, logError(ctx, err, operation) } logObjectTrace(ctx, "unregister-response", rv) - return rv, err + return rv, errors.WithStack(err) } // NewNetworkServiceRegistryClient - wraps registry.NetworkServiceRegistryClient with tracing @@ -130,7 +132,7 @@ func (t *traceNetworkServiceRegistryServer) Register(ctx context.Context, in *re return nil, logError(ctx, err, operation) } logObjectTrace(ctx, "register-response", rv) - return rv, err + return rv, errors.WithStack(err) } func (t *traceNetworkServiceRegistryServer) Find(in *registry.NetworkServiceQuery, s registry.NetworkServiceRegistry_FindServer) error { @@ -164,7 +166,7 @@ func (t *traceNetworkServiceRegistryServer) Unregister(ctx context.Context, in * return nil, logError(ctx, err, operation) } logObjectTrace(ctx, "unregister-response", rv) - return rv, err + return rv, errors.WithStack(err) } // NewNetworkServiceRegistryServer - wraps registry.NetworkServiceRegistryServer with tracing @@ -188,5 +190,5 @@ func (t *traceNetworkServiceRegistryFindServer) Send(nsResp *registry.NetworkSer if err != nil { return logError(ctx, err, operation) } - return err + return errors.WithStack(err) } diff --git a/pkg/registry/core/trace/nse_registry.go b/pkg/registry/core/trace/nse_registry.go index d060275944..d3084591be 100644 --- a/pkg/registry/core/trace/nse_registry.go +++ b/pkg/registry/core/trace/nse_registry.go @@ -1,5 +1,7 @@ // Copyright (c) 2020-2022 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"); @@ -18,13 +20,13 @@ package trace import ( "context" - "errors" "io" "github.com/networkservicemesh/sdk/pkg/registry/core/streamcontext" "github.com/networkservicemesh/sdk/pkg/tools/typeutils" "github.com/golang/protobuf/ptypes/empty" + "github.com/pkg/errors" "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -51,15 +53,15 @@ func (t *traceNetworkServiceEndpointRegistryFindClient) Recv() (*registry.Networ if err != nil { if errors.Is(err, io.EOF) { - return nil, err + return nil, errors.WithStack(err) } if status.Code(err) == codes.Canceled { - return nil, err + return nil, errors.WithStack(err) } return nil, logError(ctx, err, operation) } logObjectTrace(ctx, "recv-response", rv) - return rv, err + return rv, errors.WithStack(err) } func (t *traceNetworkServiceEndpointRegistryClient) Register(ctx context.Context, in *registry.NetworkServiceEndpoint, opts ...grpc.CallOption) (*registry.NetworkServiceEndpoint, error) { @@ -73,7 +75,7 @@ func (t *traceNetworkServiceEndpointRegistryClient) Register(ctx context.Context return nil, logError(ctx, err, operation) } logObjectTrace(ctx, "register-response", rv) - return rv, err + return rv, errors.WithStack(err) } func (t *traceNetworkServiceEndpointRegistryClient) Find(ctx context.Context, in *registry.NetworkServiceEndpointQuery, opts ...grpc.CallOption) (registry.NetworkServiceEndpointRegistry_FindClient, error) { operation := typeutils.GetFuncName(t.traced, "Find") @@ -105,7 +107,7 @@ func (t *traceNetworkServiceEndpointRegistryClient) Unregister(ctx context.Conte return nil, logError(ctx, err, operation) } logObjectTrace(ctx, "unregister-response", rv) - return rv, err + return rv, errors.WithStack(err) } // NewNetworkServiceEndpointRegistryClient - wraps registry.NetworkServiceEndpointRegistryClient with tracing @@ -129,7 +131,7 @@ func (t *traceNetworkServiceEndpointRegistryServer) Register(ctx context.Context return nil, logError(ctx, err, operation) } logObjectTrace(ctx, "register-response", rv) - return rv, err + return rv, errors.WithStack(err) } func (t *traceNetworkServiceEndpointRegistryServer) Find(in *registry.NetworkServiceEndpointQuery, s registry.NetworkServiceEndpointRegistry_FindServer) error { @@ -165,7 +167,7 @@ func (t *traceNetworkServiceEndpointRegistryServer) Unregister(ctx context.Conte return nil, logError(ctx, err, operation) } logObjectTrace(ctx, "unregister-response", rv) - return rv, err + return rv, errors.WithStack(err) } // NewNetworkServiceEndpointRegistryServer - wraps registry.NetworkServiceEndpointRegistryServer with tracing @@ -188,5 +190,5 @@ func (t *traceNetworkServiceEndpointRegistryFindServer) Send(nseResp *registry.N if err != nil { return logError(ctx, err, operation) } - return err + return errors.WithStack(err) } diff --git a/pkg/registry/utils/inject/injecterror/error_supplier.go b/pkg/registry/utils/inject/injecterror/error_supplier.go index 42d68aaf79..fdff6dd83f 100644 --- a/pkg/registry/utils/inject/injecterror/error_supplier.go +++ b/pkg/registry/utils/inject/injecterror/error_supplier.go @@ -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"); @@ -16,6 +18,8 @@ package injecterror +import "github.com/pkg/errors" + type errorSupplier struct { err error count int @@ -34,7 +38,7 @@ func (e *errorSupplier) supply() error { break } if errorTime == e.count || errorTime == -1 { - return e.err + return errors.WithStack(e.err) } } diff --git a/pkg/tools/awarenessgroups/config_decoder.go b/pkg/tools/awarenessgroups/config_decoder.go index 98a3cab6d5..982c45d5f8 100644 --- a/pkg/tools/awarenessgroups/config_decoder.go +++ b/pkg/tools/awarenessgroups/config_decoder.go @@ -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 // @@ -45,11 +45,11 @@ func (d *Decoder) Decode(value string) error { groupItems := strings.Split(list, ",") for _, item := range groupItems { if item == "" { - return errors.New("empty nsurl") + return errors.WithStack(errors.New("empty nsurl")) } nsurl, err := url.Parse(item) if err != nil { - return err + return errors.WithStack(err) } awarenessGroups[i] = append(awarenessGroups[i], nsurl) } @@ -64,38 +64,38 @@ func validateParentheses(value string) error { i := 0 length := len(value) if length < 2 { - return errors.New("value is too short") + return errors.WithStack(errors.New("value is too short")) } parenthesesCounter := 0 for ; i < length; i++ { if value[i] == '[' { if parenthesesCounter == 1 { - return errors.Errorf("unexpected character: %c", value[i]) + return errors.WithStack(errors.Errorf("unexpected character: %c", value[i])) } parenthesesCounter++ } else if value[i] == ']' { if parenthesesCounter == 0 { - return errors.Errorf("unexpected character: %c", value[i]) + return errors.WithStack(errors.Errorf("unexpected character: %c", value[i])) } if i+1 == length { return nil } if i+2 == length { - return errors.New("unexpected end of value") + return errors.WithStack(errors.New("unexpected end of value")) } if value[i+1] != ',' { - return errors.Errorf("unexpected character: %c", value[i+1]) + return errors.WithStack(errors.Errorf("unexpected character: %c", value[i+1])) } if value[i+2] != '[' { - return errors.Errorf("unexpected character: %c", value[i+2]) + return errors.WithStack(errors.Errorf("unexpected character: %c", value[i+2])) } parenthesesCounter-- } } if parenthesesCounter != 0 { - return errors.New("parenteses are not balanced") + return errors.WithStack(errors.New("parenteses are not balanced")) } return nil } diff --git a/pkg/tools/cidr/group.go b/pkg/tools/cidr/group.go index 542ce95b41..059e990b5d 100644 --- a/pkg/tools/cidr/group.go +++ b/pkg/tools/cidr/group.go @@ -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 // @@ -65,11 +65,11 @@ func (g *Groups) Decode(value string) error { } toAdd := strings.Trim(item, "[]") if toAdd == "" { - return errors.New("empty value") + return errors.WithStack(errors.New("empty value")) } _, ipNet, parseErr := net.ParseCIDR(strings.TrimSpace(toAdd)) if parseErr != nil { - return errors.Errorf("сould not parse CIDR %s; %+v", item, parseErr) + return errors.WithStack(errors.Errorf("сould not parse CIDR %s; %+v", item, parseErr)) } groups[len(groups)-1] = append(groups[len(groups)-1], ipNet) @@ -88,35 +88,35 @@ func validateParentheses(value string) error { i := 0 length := len(value) if length < 2 { - return errors.New("value is too short") + return errors.WithStack(errors.New("value is too short")) } parenthesesCounter := 0 for ; i < length; i++ { if value[i] == '[' { if parenthesesCounter == 1 { - return errors.Errorf("unexpected character: %c", value[i]) + return errors.WithStack(errors.Errorf("unexpected character: %c", value[i])) } parenthesesCounter++ } else if value[i] == ']' { if parenthesesCounter == 0 { - return errors.Errorf("unexpected character: %c", value[i]) + return errors.WithStack(errors.Errorf("unexpected character: %c", value[i])) } if i+1 == length { return nil } if i+2 == length { - return errors.New("unexpected end of value") + return errors.WithStack(errors.New("unexpected end of value")) } if value[i+1] != ',' { - return errors.Errorf("unexpected character: %c", value[i+1]) + return errors.WithStack(errors.Errorf("unexpected character: %c", value[i+1])) } parenthesesCounter-- } } if parenthesesCounter != 0 { - return errors.New("parenteses are not balanced") + return errors.WithStack(errors.New("parenteses are not balanced")) } return nil } diff --git a/pkg/tools/clientmap/clientmap.gen.go b/pkg/tools/clientmap/clientmap.gen.go index 0c16031716..fea8ff8715 100644 --- a/pkg/tools/clientmap/clientmap.gen.go +++ b/pkg/tools/clientmap/clientmap.gen.go @@ -1,4 +1,6 @@ // Code generated by "-output clientmap.gen.go -type Map -output clientmap.gen.go -type Map"; DO NOT EDIT. +// Install -output clientmap.gen.go -type Map by "go get -u github.com/searKing/golang/tools/-output clientmap.gen.go -type Map" + package clientmap import ( diff --git a/pkg/tools/debug/self.go b/pkg/tools/debug/self.go index 0e2e53f4e1..2b5a4f8a09 100644 --- a/pkg/tools/debug/self.go +++ b/pkg/tools/debug/self.go @@ -1,6 +1,6 @@ // Copyright (c) 2020 Cisco and/or its affiliates. // -// Copyright (c) 2022 Cisco and/or its affiliates. +// Copyright (c) 2022-2023 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -58,7 +58,7 @@ func Self(envVariableParts ...string) error { // why we get it this way executable, err := os.Executable() if err != nil { - return errors.Errorf("unable to get excutable name: %+v", err) + return errors.WithStack(errors.Errorf("unable to get excutable name: %+v", err)) } // If you don't provide an env variable, we make a default choice if len(envVariableParts) == 0 { @@ -69,22 +69,22 @@ func Self(envVariableParts ...string) error { // Do we have that env variable? listen, exists := os.LookupEnv(dlvPortEnvVariable) if !exists { - return errors.Errorf("Setting env variable %s to a valid dlv '--listen' value will cause the dlv debugger to execute this binary and listen as directed.", dlvPortEnvVariable) + return errors.WithStack(errors.Errorf("Setting env variable %s to a valid dlv '--listen' value will cause the dlv debugger to execute this binary and listen as directed.", dlvPortEnvVariable)) } // Is it a valid listen? split := strings.Split(listen, ":") // break on ':' if len(split) < 2 { - return errors.Errorf("Unable to use value %q from env variable %s as a listen: missing ':' before port", listen, dlvPortEnvVariable) + return errors.WithStack(errors.Errorf("Unable to use value %q from env variable %s as a listen: missing ':' before port", listen, dlvPortEnvVariable)) } if _, err = strconv.ParseUint(split[1], 10, 16); err != nil { - return errors.Wrapf(err, "Unable to use value %q from env variable %s as a listen", listen, dlvPortEnvVariable) + return errors.WithStack(errors.Wrapf(err, "Unable to use value %q from env variable %s as a listen", listen, dlvPortEnvVariable)) } // Do we have dlv? dlv, err := exec.LookPath("dlv") if err != nil { - return errors.Wrap(err, "Unable to find dlv in your path") + return errors.WithStack(errors.Wrap(err, "Unable to find dlv in your path")) } // Marshal the new args @@ -112,7 +112,7 @@ func Self(envVariableParts ...string) error { // Make the syscall.Exec logrus.Infof("About to exec: \"%s %s\"", dlv, strings.Join(args[1:], " ")) // About to debug this not working at host rather than container level - return syscall.Exec(dlv, args, envv) + return errors.WithStack(syscall.Exec(dlv, args, envv)) } // envVariable - convert the envVariableParts to a proper env variable diff --git a/pkg/tools/dnsconfig/config_decoder.go b/pkg/tools/dnsconfig/config_decoder.go index 810f36f00b..cd39747189 100644 --- a/pkg/tools/dnsconfig/config_decoder.go +++ b/pkg/tools/dnsconfig/config_decoder.go @@ -1,6 +1,6 @@ // Copyright (c) 2021 Doc.ai and/or its affiliates. // -// Copyright (c) 2022 Cisco and/or its affiliates. +// Copyright (c) 2022-2023 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -22,6 +22,7 @@ import ( "encoding/json" "github.com/networkservicemesh/api/pkg/api/networkservice" + "github.com/pkg/errors" ) // Decoder allows to parse []*networkservice.DNSConfig from json string. Can be used for env configuration. @@ -32,7 +33,7 @@ type Decoder []*networkservice.DNSConfig func (d *Decoder) Decode(v string) error { var c []*networkservice.DNSConfig if err := json.Unmarshal([]byte(v), &c); err != nil { - return err + return errors.WithStack(err) } *d = Decoder(c) return nil diff --git a/pkg/tools/dnsconfig/sync_map.gen.go b/pkg/tools/dnsconfig/sync_map.gen.go index db496e983f..0b52c4d42d 100644 --- a/pkg/tools/dnsconfig/sync_map.gen.go +++ b/pkg/tools/dnsconfig/sync_map.gen.go @@ -1,4 +1,6 @@ // Code generated by "-output sync_map.gen.go -type Map -output sync_map.gen.go -type Map"; DO NOT EDIT. +// Install -output sync_map.gen.go -type Map by "go get -u github.com/searKing/golang/tools/-output sync_map.gen.go -type Map" + package dnsconfig import ( diff --git a/pkg/tools/dnsutils/cache/sync_map.gen.go b/pkg/tools/dnsutils/cache/sync_map.gen.go index 34a919e36b..6f989e7d89 100644 --- a/pkg/tools/dnsutils/cache/sync_map.gen.go +++ b/pkg/tools/dnsutils/cache/sync_map.gen.go @@ -1,4 +1,6 @@ // Code generated by "-output sync_map.gen.go -type msgMap -output sync_map.gen.go -type msgMap"; DO NOT EDIT. +// Install -output sync_map.gen.go -type msgMap by "go get -u github.com/searKing/golang/tools/-output sync_map.gen.go -type msgMap" + package cache import ( diff --git a/pkg/tools/dnsutils/memory/sync_map.gen.go b/pkg/tools/dnsutils/memory/sync_map.gen.go index aa8f83d900..67b5525a54 100644 --- a/pkg/tools/dnsutils/memory/sync_map.gen.go +++ b/pkg/tools/dnsutils/memory/sync_map.gen.go @@ -1,4 +1,6 @@ // Code generated by "-output sync_map.gen.go -type Map -output sync_map.gen.go -type Map"; DO NOT EDIT. +// Install -output sync_map.gen.go -type Map by "go get -u github.com/searKing/golang/tools/-output sync_map.gen.go -type Map" + package memory import ( diff --git a/pkg/tools/fs/inode.go b/pkg/tools/fs/inode.go index 30fdabaef1..0a38ee906c 100644 --- a/pkg/tools/fs/inode.go +++ b/pkg/tools/fs/inode.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020-2022 Cisco and/or its affiliates. +// Copyright (c) 2020-2023 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -31,11 +31,11 @@ import ( func GetInode(file string) (uintptr, error) { fileInfo, err := os.Stat(file) if err != nil { - return 0, errors.Wrap(err, "error stat file") + return 0, errors.WithStack(errors.Wrap(err, "error stat file")) } stat, ok := fileInfo.Sys().(*syscall.Stat_t) if !ok { - return 0, errors.New("not a stat_t") + return 0, errors.WithStack(errors.New("not a stat_t")) } return uintptr(stat.Ino), nil } diff --git a/pkg/tools/fs/inode_windows_amd64.go b/pkg/tools/fs/inode_windows_amd64.go index 5d919222df..c27f2974c1 100644 --- a/pkg/tools/fs/inode_windows_amd64.go +++ b/pkg/tools/fs/inode_windows_amd64.go @@ -1,5 +1,7 @@ // Copyright (c) 2020 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"); @@ -29,11 +31,11 @@ import ( func GetInode(file string) (uintptr, error) { fileInfo, err := os.Stat(file) if err != nil { - return 0, errors.Wrap(err, "error stat file") + return 0, errors.WithStack(errors.Wrap(err, "error stat file")) } stat, ok := fileInfo.Sys().(*syscall.Handle) if !ok { - return 0, errors.New("not a syscall.Handle") + return 0, errors.WithStack(errors.New("not a syscall.Handle")) } ptr := uintptr(unsafe.Pointer(stat)) return ptr, nil diff --git a/pkg/tools/grpcfdutils/transceiver.go b/pkg/tools/grpcfdutils/transceiver.go index 9ea0771b57..ab7a2f8188 100644 --- a/pkg/tools/grpcfdutils/transceiver.go +++ b/pkg/tools/grpcfdutils/transceiver.go @@ -1,5 +1,7 @@ // Copyright (c) 2021-2022 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"); @@ -44,7 +46,7 @@ type notifiableFDTransceiver struct { func (w *notifiableFDTransceiver) RecvFileByURL(urlStr string) (<-chan *os.File, error) { recv, err := w.FDTransceiver.RecvFileByURL(urlStr) if err != nil { - return nil, err + return nil, errors.WithStack(err) } var fileCh = make(chan *os.File) @@ -62,12 +64,12 @@ func (w *notifiableFDTransceiver) RecvFileByURL(urlStr string) (<-chan *os.File, func InjectOnFileReceivedCallback(ctx context.Context, callback func(string, *os.File)) error { p, ok := peer.FromContext(ctx) if !ok { - return errors.Errorf("No peer in context") + return errors.WithStack(errors.Errorf("No peer in context")) } transceiver, ok := p.Addr.(grpcfd.FDTransceiver) if !ok { - return errors.Errorf("No grpcfd transceiver in context") + return errors.WithStack(errors.Errorf("No grpcfd transceiver in context")) } p.Addr = ¬ifiableFDTransceiver{ diff --git a/pkg/tools/ippool/ippool.go b/pkg/tools/ippool/ippool.go index c1ec44a507..6c2a0736d7 100644 --- a/pkg/tools/ippool/ippool.go +++ b/pkg/tools/ippool/ippool.go @@ -1,6 +1,6 @@ // Copyright (c) 2021-2022 Doc.ai and/or its affiliates. // -// Copyright (c) 2022 Cisco and/or its affiliates. +// Copyright (c) 2022-2023 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -20,10 +20,11 @@ package ippool import ( - "errors" "math" "net" "sync" + + "github.com/pkg/errors" ) type color bool @@ -225,7 +226,7 @@ func (tree *IPPool) Pull() (net.IP, error) { ip := tree.pull() if ip == nil { - return nil, errors.New("IPPool is empty") + return nil, errors.WithStack(errors.New("IPPool is empty")) } return ipFromIPAddress(ip, tree.ipLength), nil } @@ -234,7 +235,7 @@ func (tree *IPPool) Pull() (net.IP, error) { func (tree *IPPool) PullIPString(ipString string, exclude ...*IPPool) (*net.IPNet, error) { ip, _, err := net.ParseCIDR(ipString) if err != nil { - return nil, err + return nil, errors.WithStack(err) } return tree.PullIP(ip, exclude...) @@ -256,7 +257,7 @@ func (tree *IPPool) PullIP(ip net.IP, exclude ...*IPPool) (*net.IPNet, error) { end: ipAddressFromIP(ip), }) } else { - return nil, errors.New("IPPool doesn't contain required IP") + return nil, errors.WithStack(errors.New("IPPool doesn't contain required IP")) } return &net.IPNet{ @@ -278,12 +279,12 @@ func (tree *IPPool) PullP2PAddrs(exclude ...*IPPool) (srcNet, dstNet *net.IPNet, srcIP := clone.pull() if srcIP == nil { - return nil, nil, errors.New("IPPool is empty") + return nil, nil, errors.WithStack(errors.New("IPPool is empty")) } dstIP := clone.pull() if dstIP == nil { - return nil, nil, errors.New("IPPool is empty") + return nil, nil, errors.WithStack(errors.New("IPPool is empty")) } tree.deleteRange(&ipRange{ diff --git a/pkg/tools/ippool/prefixpool.go b/pkg/tools/ippool/prefixpool.go index 03e935f38e..ccf815d4a7 100644 --- a/pkg/tools/ippool/prefixpool.go +++ b/pkg/tools/ippool/prefixpool.go @@ -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"); @@ -16,7 +18,11 @@ package ippool -import "net" +import ( + "net" + + "github.com/pkg/errors" +) // PrefixPool - keeps prefixes for both IPv4 and IPv6 addresses type PrefixPool struct { @@ -42,7 +48,7 @@ func (pool *PrefixPool) AddPrefixes(prefixes ...string) error { for _, prefix := range prefixes { _, ipNet, err := net.ParseCIDR(prefix) if err != nil { - return err + return errors.WithStack(err) } pool.ip4.AddNet(ipNet) pool.ip6.AddNet(ipNet) @@ -55,7 +61,7 @@ func (pool *PrefixPool) ExcludePrefixes(prefixes ...string) error { for _, prefix := range prefixes { _, ipNet, err := net.ParseCIDR(prefix) if err != nil { - return err + return errors.WithStack(err) } pool.ip4.Exclude(ipNet) pool.ip6.Exclude(ipNet) diff --git a/pkg/tools/matchutils/utils.go b/pkg/tools/matchutils/utils.go index b690aa382d..a7181085e9 100644 --- a/pkg/tools/matchutils/utils.go +++ b/pkg/tools/matchutils/utils.go @@ -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"); @@ -83,7 +85,7 @@ func process(t *template.Template, vars interface{}) (string, error) { err := t.Execute(&tmplBytes, vars) if err != nil { - return "", errors.Wrap(err, "error during execution of template") + return "", errors.WithStack(errors.Wrap(err, "error during execution of template")) } return tmplBytes.String(), nil } diff --git a/pkg/tools/monitorconnection/authorize/common.go b/pkg/tools/monitorconnection/authorize/common.go index 7a1c792ba6..e3ff8f54c2 100644 --- a/pkg/tools/monitorconnection/authorize/common.go +++ b/pkg/tools/monitorconnection/authorize/common.go @@ -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 // @@ -18,6 +18,8 @@ package authorize import ( "context" + + "github.com/pkg/errors" ) // Policy represents authorization policy for monitor connection. @@ -37,7 +39,7 @@ func (l *policiesList) check(ctx context.Context, srv MonitorOpaInput) error { continue } if err := policy.Check(ctx, srv); err != nil { - return err + return errors.WithStack(err) } } return nil diff --git a/pkg/tools/opa/opainput.go b/pkg/tools/opa/opainput.go index 87fed58a20..ec96b3d5c2 100644 --- a/pkg/tools/opa/opainput.go +++ b/pkg/tools/opa/opainput.go @@ -1,5 +1,7 @@ // Copyright (c) 2020-2022 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"); @@ -32,7 +34,7 @@ import ( func PreparedOpaInput(ctx context.Context, model interface{}) (map[string]interface{}, error) { result, err := convertToMap(model) if err != nil { - return nil, errors.Wrapf(err, "cannot convert %v to map", model) + return nil, errors.WithStack(errors.Wrapf(err, "cannot convert %v to map", model)) } p, ok := peer.FromContext(ctx) var cert *x509.Certificate @@ -80,11 +82,11 @@ func ParseX509Cert(authInfo credentials.AuthInfo) *x509.Certificate { func convertToMap(model interface{}) (map[string]interface{}, error) { jsonConn, err := json.Marshal(model) if err != nil { - return nil, err + return nil, errors.WithStack(err) } var rv map[string]interface{} if err := json.Unmarshal(jsonConn, &rv); err != nil { - return nil, err + return nil, errors.WithStack(err) } if rv == nil { rv = make(map[string]interface{}) diff --git a/pkg/tools/opa/policies.go b/pkg/tools/opa/policies.go index 351b4ed228..9aeef9d93d 100644 --- a/pkg/tools/opa/policies.go +++ b/pkg/tools/opa/policies.go @@ -1,5 +1,7 @@ // Copyright (c) 2020-2022 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"); @@ -64,7 +66,7 @@ func PolicyFromFile(p string) (*AuthorizationPolicy, error) { var embedErr error b, embedErr = embedFS.ReadFile(strings.ReplaceAll(p, defaultPoliciesDir, "policies")) if embedErr != nil { - return nil, errors.Wrap(err, embedErr.Error()) + return nil, errors.WithStack(errors.Wrap(err, embedErr.Error())) } } return &AuthorizationPolicy{ @@ -87,7 +89,7 @@ func findFilesByPath(mask string) ([]string, error) { var r, err = regexp.Compile("^" + mask + "$") if err != nil { - return nil, err + return nil, errors.WithStack(errors.Wrapf(err, "failed to compile regexp: ^%s$", mask)) } var dir = filepath.Dir(mask) diff --git a/pkg/tools/opa/policy.go b/pkg/tools/opa/policy.go index 0524d969e6..9af86e711c 100644 --- a/pkg/tools/opa/policy.go +++ b/pkg/tools/opa/policy.go @@ -1,5 +1,7 @@ // Copyright (c) 2020-2022 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"); @@ -43,13 +45,13 @@ func True(query string) CheckAccessFunc { if strings.HasSuffix(e.Text, query) { t, ok := e.Value.(bool) if !ok { - return false, errors.New("policy contains non boolean expression") + return false, errors.WithStack(errors.New("policy contains non boolean expression")) } return t, nil } } } - return false, errors.Errorf("result is not found for query %v", query) + return false, errors.WithStack(errors.Errorf("result is not found for query %v", query)) } } @@ -85,14 +87,14 @@ func (d *AuthorizationPolicy) Check(ctx context.Context, model interface{}) erro } rs, err := d.evalQuery.Eval(ctx, rego.EvalInput(input)) if err != nil { - return status.Error(codes.Internal, err.Error()) + return errors.WithStack(status.Error(codes.Internal, err.Error())) } hasAccess, err := d.checker(rs) if err != nil { - return status.Error(codes.Internal, err.Error()) + return errors.WithStack(status.Error(codes.Internal, err.Error())) } if !hasAccess { - return status.Error(codes.PermissionDenied, "no sufficient privileges") + return errors.WithStack(status.Error(codes.PermissionDenied, "no sufficient privileges")) } return nil } @@ -118,10 +120,10 @@ func (d *AuthorizationPolicy) init() error { d.evalQuery = &r }) if d.initErr != nil { - return d.initErr + return errors.WithStack(d.initErr) } if d.evalQuery == nil { - return errors.Errorf("policy %v is not compiled", d.policySource) + return errors.WithStack(errors.Errorf("policy %v is not compiled", d.policySource)) } return nil } @@ -133,7 +135,7 @@ func (d *AuthorizationPolicy) loadSource() error { var b []byte b, err := os.ReadFile(d.policyFilePath) if err != nil { - return err + return errors.WithStack(errors.Wrapf(err, "failed to read a policy file: %s", d.policyFilePath)) } d.policySource = strings.TrimSpace(string(b)) return nil @@ -151,5 +153,5 @@ func (d *AuthorizationPolicy) checkModule() error { return nil } } - return errors.New("missed package") + return errors.WithStack(errors.New("missed package")) } diff --git a/pkg/tools/prefixpool/prefixpool.go b/pkg/tools/prefixpool/prefixpool.go index f6b31580c7..7ad4460984 100644 --- a/pkg/tools/prefixpool/prefixpool.go +++ b/pkg/tools/prefixpool/prefixpool.go @@ -1,7 +1,7 @@ -// Copyright (c) 2020-2022 Cisco and/or its affiliates. -// // Copyright (c) 2020-2022 Doc.ai and/or its affiliates. // +// Copyright (c) 2020-2023 Cisco and/or its affiliates. +// // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -55,7 +55,7 @@ func New(prefixes ...string) (*PrefixPool, error) { for _, prefix := range prefixes { _, _, err := net.ParseCIDR(prefix) if err != nil { - return nil, err + return nil, errors.WithStack(err) } } return &PrefixPool{ @@ -145,7 +145,7 @@ func (impl *PrefixPool) ExcludePrefixes(excludedPrefixes []string) (removedPrefi /* Raise an error, if there aren't any available prefixes left after excluding */ if len(copyPrefixes) == 0 { err := errors.New("IPAM: The available address pool is empty, probably intersected by excludedPrefix") - return nil, err + return nil, errors.WithStack(err) } /* Everything should be fine, update the available prefixes with what's left */ impl.prefixes = copyPrefixes @@ -179,7 +179,7 @@ func extractSubnet(wider, smaller *net.IPNet) (retSubnets []string, retErr error leftParts = append(leftParts, sub1.String()) root = sub2 default: - return nil, errors.New("split failed") + return nil, errors.WithStack(errors.New("split failed")) } } return append(leftParts, rightParts...), nil @@ -206,7 +206,7 @@ func (impl *PrefixPool) Extract(connectionID string, family networkservice.IpFam ip, ipNet, err := net.ParseCIDR(result[0]) if err != nil { - return nil, nil, nil, err + return nil, nil, nil, errors.WithStack(err) } src, err := incrementIP(ip, ipNet) @@ -267,7 +267,7 @@ func (impl *PrefixPool) Release(connectionID string) error { conn := impl.connections[connectionID] if conn == nil { - return errors.Errorf("Failed to release connection infomration: %s", connectionID) + return errors.WithStack(errors.Errorf("Failed to release connection infomration: %s", connectionID)) } delete(impl.connections, connectionID) @@ -291,7 +291,7 @@ func (impl *PrefixPool) GetConnectionInformation(connectionID string) (ipNet str defer impl.mutex.RUnlock() conn := impl.connections[connectionID] if conn == nil { - return "", nil, errors.Errorf("No connection with id: %s is found", connectionID) + return "", nil, errors.WithStack(errors.Errorf("No connection with id: %s is found", connectionID)) } return conn.ipNet.String(), conn.prefixes, nil } @@ -300,7 +300,7 @@ func (impl *PrefixPool) GetConnectionInformation(connectionID string) (ipNet str func (impl *PrefixPool) Intersect(prefix string) (intersection bool, err error) { _, subnet, err := net.ParseCIDR(prefix) if err != nil { - return false, err + return false, errors.WithStack(err) } for _, p := range impl.prefixes { @@ -334,7 +334,7 @@ func ExtractPrefixes(prefixes []string, requests ...*networkservice.ExtraPrefixR for _, request := range requests { err := request.IsValid() if err != nil { - return nil, prefixes, err + return nil, prefixes, errors.WithStack(err) } } @@ -369,7 +369,7 @@ func ExtractPrefixes(prefixes []string, requests ...*networkservice.ExtraPrefixR } } if len(result) == 0 { - return nil, prefixes, errors.Errorf("Failed to extract prefixes, there is no available %v", prefixes) + return nil, prefixes, errors.WithStack(errors.Errorf("Failed to extract prefixes, there is no available %v", prefixes)) } return result, newPrefixes, nil } @@ -404,7 +404,7 @@ func extractPrefix(prefixes []string, prefixLen uint32) (retPrefix string, retLe // Not found, lets split minimal found prefix if maxPrefixIdx == -1 { // There is no room to split - return "", prefixes, errors.Errorf("Failed to find room to have prefix len %d at %v", prefixLen, prefixes) + return "", prefixes, errors.WithStack(errors.Errorf("Failed to find room to have prefix len %d at %v", prefixLen, prefixes)) } resultPrefixRoot := prefixes[maxPrefixIdx] @@ -535,7 +535,7 @@ func getSubnets(prefixes []string) (map[string]*net.IPNet, error) { for _, prefix := range prefixes { _, subnet, err := net.ParseCIDR(prefix) if err != nil { - return nil, errors.Wrapf(err, "Wrong CIDR: %v", prefix) + return nil, errors.WithStack(errors.Wrapf(err, "Wrong CIDR: %v", prefix)) } subnets[prefix] = subnet } @@ -580,11 +580,11 @@ func subnet(ipnet *net.IPNet, subnetIndex int) (retNet *net.IPNet, reterr error) parentLen, addrLen := mask.Size() newPrefixLen := parentLen + 1 if newPrefixLen > addrLen { - return nil, errors.Errorf("insufficient address space to extend prefix of %d", parentLen) + return nil, errors.WithStack(errors.Errorf("insufficient address space to extend prefix of %d", parentLen)) } if uint64(subnetIndex) > 2 { - return nil, errors.Errorf("prefix extension does not accommodate a subnet numbered %d", subnetIndex) + return nil, errors.WithStack(errors.Errorf("prefix extension does not accommodate a subnet numbered %d", subnetIndex)) } return &net.IPNet{ @@ -638,7 +638,7 @@ func incrementIP(sourceIP net.IP, ipNet *net.IPNet) (incrIP net.IP, retErr error } } if !ipNet.Contains(ip) { - return nil, errors.Errorf("Overflowed CIDR while incrementing IP") + return nil, errors.WithStack(errors.Errorf("Overflowed CIDR while incrementing IP")) } return ip, nil } diff --git a/pkg/tools/spiffejwt/token.go b/pkg/tools/spiffejwt/token.go index d61f1c04ea..3122c39351 100644 --- a/pkg/tools/spiffejwt/token.go +++ b/pkg/tools/spiffejwt/token.go @@ -1,5 +1,7 @@ // Copyright (c) 2020-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"); @@ -32,7 +34,7 @@ func TokenGeneratorFunc(source x509svid.Source, maxTokenLifeTime time.Duration) return func(authInfo credentials.AuthInfo) (string, time.Time, error) { ownSVID, err := source.GetX509SVID() if err != nil { - return "", time.Time{}, errors.Wrap(err, "Error creating Token") + return "", time.Time{}, errors.WithStack(errors.Wrap(err, "Error creating Token")) } expireTime := time.Now().Add(maxTokenLifeTime) @@ -40,7 +42,7 @@ func TokenGeneratorFunc(source x509svid.Source, maxTokenLifeTime time.Duration) expireTime = ownSVID.Certificates[0].NotAfter } if err != nil { - return "", time.Time{}, errors.Wrap(err, "Error creating Token") + return "", time.Time{}, errors.WithStack(errors.Wrap(err, "Error creating Token")) } claims := jwt.RegisteredClaims{ Subject: ownSVID.ID.String(), @@ -62,6 +64,6 @@ func TokenGeneratorFunc(source x509svid.Source, maxTokenLifeTime time.Duration) } } tok, err := jwt.NewWithClaims(jwt.SigningMethodES256, claims).SignedString(ownSVID.PrivateKey) - return tok, expireTime, err + return tok, expireTime, errors.WithStack(err) } } diff --git a/pkg/tools/spire/spiffe_id_connection_map.gen.go b/pkg/tools/spire/spiffe_id_connection_map.gen.go index f521d6bb0e..2d87793ee2 100644 --- a/pkg/tools/spire/spiffe_id_connection_map.gen.go +++ b/pkg/tools/spire/spiffe_id_connection_map.gen.go @@ -1,12 +1,13 @@ // Code generated by "-output spiffe_id_connection_map.gen.go -type SpiffeIDConnectionMap -output spiffe_id_connection_map.gen.go -type SpiffeIDConnectionMap"; DO NOT EDIT. +// Install -output spiffe_id_connection_map.gen.go -type SpiffeIDConnectionMap by "go get -u github.com/searKing/golang/tools/-output spiffe_id_connection_map.gen.go -type SpiffeIDConnectionMap" + package spire import ( "sync" // Used by sync.Map. - "github.com/spiffe/go-spiffe/v2/spiffeid" - "github.com/networkservicemesh/sdk/pkg/tools/stringset" + "github.com/spiffe/go-spiffe/v2/spiffeid" ) // Generate code that will fail if the constants change value. diff --git a/pkg/tools/spire/start.go b/pkg/tools/spire/start.go index 876784a101..e84ab2fde3 100644 --- a/pkg/tools/spire/start.go +++ b/pkg/tools/spire/start.go @@ -1,7 +1,7 @@ -// Copyright (c) 2020-2022 Cisco and/or its affiliates. -// // Copyright (c) 2021-2022 Doc.ai and/or its affiliates. // +// Copyright (c) 2020-2023 Cisco and/or its affiliates. +// // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,7 +24,6 @@ package spire import ( "context" "crypto/x509" - "errors" "fmt" "os" "path" @@ -32,14 +31,16 @@ import ( "sync" "time" + "github.com/networkservicemesh/sdk/pkg/tools/opa" + "github.com/edwarnicke/exechelper" "github.com/sirupsen/logrus" "github.com/spiffe/go-spiffe/v2/spiffeid" "github.com/spiffe/go-spiffe/v2/svid/x509svid" "github.com/spiffe/go-spiffe/v2/workloadapi" - "google.golang.org/grpc/peer" - "github.com/networkservicemesh/sdk/pkg/tools/opa" + "github.com/pkg/errors" + "google.golang.org/grpc/peer" ) type contextKeyType string @@ -252,10 +253,10 @@ func writeConfigFiles(ctx context.Context, agentConfig, serverConfig, spireRoot if _, err := os.Stat(filename); os.IsNotExist(err) { logrusEntry(ctx).Infof("Configuration file: %q not found, using defaults", filename) if err := os.MkdirAll(path.Dir(filename), 0o700); err != nil { - return err + return errors.WithStack(errors.Wrapf(err, "failed to create folders: %s", path.Dir(filename))) } if err := os.WriteFile(filename, []byte(contents), 0o600); err != nil { - return err + return errors.WithStack(errors.Wrapf(err, "failed to write to a %s", path.Dir(filename))) } } } @@ -272,7 +273,7 @@ func execHealthCheck(ctx context.Context, cmdStr string, options ...*exechelper. for { select { case <-ctx.Done(): - return ctx.Err() + return errors.WithStack(ctx.Err()) default: if err := exechelper.Run(cmdStr, options...); err == nil { return nil @@ -286,7 +287,7 @@ func PeerSpiffeIDFromContext(ctx context.Context) (spiffeid.ID, error) { p, ok := peer.FromContext(ctx) var cert *x509.Certificate if !ok { - return spiffeid.ID{}, errors.New("fail to get peer from context") + return spiffeid.ID{}, errors.WithStack(errors.New("fail to get peer from context")) } cert = opa.ParseX509Cert(p.AuthInfo) if cert != nil { @@ -294,7 +295,7 @@ func PeerSpiffeIDFromContext(ctx context.Context) (spiffeid.ID, error) { if err == nil { return spiffeID, nil } - return spiffeid.ID{}, errors.New("fail to get Spiffe ID from certificate") + return spiffeid.ID{}, errors.WithStack(errors.New("fail to get Spiffe ID from certificate")) } - return spiffeid.ID{}, errors.New("fail to get certificate from peer") + return spiffeid.ID{}, errors.WithStack(errors.New("fail to get certificate from peer")) } diff --git a/pkg/tools/stringset/gen.go b/pkg/tools/stringset/gen.go index 8790ac370d..1e4ef8600f 100644 --- a/pkg/tools/stringset/gen.go +++ b/pkg/tools/stringset/gen.go @@ -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 // @@ -14,6 +14,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +// Package stringset contains StringSet type definition package stringset import ( diff --git a/pkg/tools/stringset/sync_map.gen.go b/pkg/tools/stringset/sync_map.gen.go index cc4a23fde4..839d8e7cd4 100644 --- a/pkg/tools/stringset/sync_map.gen.go +++ b/pkg/tools/stringset/sync_map.gen.go @@ -1,4 +1,6 @@ // Code generated by "-output sync_map.gen.go -type StringSet -output sync_map.gen.go -type StringSet"; DO NOT EDIT. +// Install -output sync_map.gen.go -type StringSet by "go get -u github.com/searKing/golang/tools/-output sync_map.gen.go -type StringSet" + package stringset import ( diff --git a/pkg/tools/stringurl/sync_map.gen.go b/pkg/tools/stringurl/sync_map.gen.go index f1ce2ae89f..1f62c6c5eb 100644 --- a/pkg/tools/stringurl/sync_map.gen.go +++ b/pkg/tools/stringurl/sync_map.gen.go @@ -1,4 +1,6 @@ // Code generated by "-output sync_map.gen.go -type Map -output sync_map.gen.go -type Map"; DO NOT EDIT. +// Install -output sync_map.gen.go -type Map by "go get -u github.com/searKing/golang/tools/-output sync_map.gen.go -type Map" + package stringurl import ( diff --git a/pkg/tools/token/context.go b/pkg/tools/token/context.go index 489751f615..68e7ea4dc9 100644 --- a/pkg/tools/token/context.go +++ b/pkg/tools/token/context.go @@ -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"); @@ -63,7 +65,7 @@ func getSingleValue(md metadata.MD, key string) (string, error) { values := md.Get(key) if len(values) != 1 { - return "", errors.Errorf("values of '%v' has wrong length %v, expected 1", key, len(values)) + return "", errors.WithStack(errors.Errorf("values of '%v' has wrong length %v, expected 1", key, len(values))) } return values[0], nil diff --git a/pkg/tools/token/creds.go b/pkg/tools/token/creds.go index 90ec932c44..7fca881ed5 100644 --- a/pkg/tools/token/creds.go +++ b/pkg/tools/token/creds.go @@ -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"); @@ -18,9 +20,10 @@ package token import ( "context" - "errors" "time" + "github.com/pkg/errors" + "google.golang.org/grpc/credentials" "google.golang.org/grpc/peer" ) @@ -44,7 +47,7 @@ func (creds *perRPCCredentials) GetRequestMetadata(ctx context.Context, _ ...str tok, expire, err := creds.genTokenFunc(authInfo) if err != nil { - return nil, err + return nil, errors.WithStack(err) } return map[string]string{