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..54d348af99 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 // @@ -94,7 +94,7 @@ func (a *authorizeClient) Request(ctx context.Context, request *networkservice.N 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) { diff --git a/pkg/networkservice/common/cleanup/client.go b/pkg/networkservice/common/cleanup/client.go index 5a8ed2a7c0..a8eb8a9000 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 // @@ -105,7 +105,7 @@ func (c *cleanupClient) Request(ctx context.Context, request *networkservice.Net atomic.AddInt32(&c.activeConns, -1) } }() - return conn, err + return conn, nil } func (c *cleanupClient) Close(ctx context.Context, conn *networkservice.Connection, opts ...grpc.CallOption) (*empty.Empty, error) { diff --git a/pkg/networkservice/common/connect/client.go b/pkg/networkservice/common/connect/client.go index cb632eca1c..25e986ecfb 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"); @@ -39,8 +41,7 @@ func (c *connectClient) Request(ctx context.Context, request *networkservice.Net if !loaded { return nil, errors.New("no grpc.ClientConnInterface provided") } - conn, err := networkservice.NewNetworkServiceClient(cc).Request(ctx, request, opts...) - return conn, err + return networkservice.NewNetworkServiceClient(cc).Request(ctx, request, opts...) } func (c *connectClient) Close(ctx context.Context, conn *networkservice.Connection, opts ...grpc.CallOption) (*emptypb.Empty, error) { diff --git a/pkg/networkservice/common/discover/server.go b/pkg/networkservice/common/discover/server.go index 46ff375b51..806de0f97e 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"); @@ -116,7 +116,7 @@ func (d *discoverCandidatesServer) discoverNetworkServiceEndpoint(ctx context.Co nseRespStream, err := d.nseClient.Find(ctx, query) if err != nil { - return nil, errors.WithStack(err) + return nil, err } nseList := registry.ReadNetworkServiceEndpointList(nseRespStream) @@ -140,7 +140,7 @@ func (d *discoverCandidatesServer) discoverNetworkServiceEndpoints(ctx context.C nseRespStream, err := d.nseClient.Find(ctx, query) if err != nil { - return nil, errors.WithStack(err) + return nil, err } nseList := registry.ReadNetworkServiceEndpointList(nseRespStream) @@ -162,7 +162,7 @@ func (d *discoverCandidatesServer) discoverNetworkService(ctx context.Context, n nsRespStream, err := d.nsClient.Find(ctx, query) if err != nil { - return nil, errors.WithStack(err) + return nil, err } nsList := registry.ReadNetworkServiceList(nsRespStream) diff --git a/pkg/networkservice/common/discoverforwarder/server.go b/pkg/networkservice/common/discoverforwarder/server.go index 68635fae5e..613a88c02e 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"); @@ -81,14 +83,12 @@ func (d *discoverForwarderServer) Request(ctx context.Context, request *networks Url: d.nsmgrURL, }, }) - if err != nil { logger.Errorf("can not open registry nse stream by networkservice. Error: %v", err.Error()) - return nil, errors.WithStack(err) + return nil, err } nses := d.matchForwarders(request.Connection.GetLabels(), ns, registry.ReadNetworkServiceEndpointList(stream)) - if len(nses) == 0 { return nil, errors.New("no candidates found") } @@ -110,14 +110,12 @@ func (d *discoverForwarderServer) Request(ctx context.Context, request *networks // https://github.com/networkservicemesh/sdk/issues/790 for i, candidate := range nses { u, err := url.Parse(candidate.Url) - if err != nil { logger.Errorf("can not parse forwarder=%v url=%v error=%v", candidate.Name, candidate.Url, err.Error()) continue } resp, err := next.Server(ctx).Request(clienturlctx.WithClientURL(ctx, u), request.Clone()) - if err == nil { storeForwarderName(ctx, candidate.Name) return resp, nil @@ -128,27 +126,25 @@ func (d *discoverForwarderServer) Request(ctx context.Context, request *networks return nil, candidatesErr } + stream, err := d.nseClient.Find(ctx, ®istry.NetworkServiceEndpointQuery{ NetworkServiceEndpoint: ®istry.NetworkServiceEndpoint{ Name: forwarderName, Url: d.nsmgrURL, }, }) - if err != nil { logger.Errorf("can not open registry nse stream by forwarder name. Error: %v", err.Error()) - return nil, errors.WithStack(err) + return nil, err } nses := registry.ReadNetworkServiceEndpointList(stream) - if len(nses) == 0 { storeForwarderName(ctx, "") return nil, errors.New("forwarder not found") } u, err := url.Parse(nses[0].Url) - if err != nil { logger.Errorf("can not parse forwarder=%v url=%v error=%v", nses[0].Name, u, err.Error()) return nil, errors.WithStack(err) @@ -164,7 +160,6 @@ func (d *discoverForwarderServer) Request(ctx context.Context, request *networks func (d *discoverForwarderServer) Close(ctx context.Context, conn *networkservice.Connection) (*empty.Empty, error) { var forwarderName = loadForwarderName(ctx) var logger = log.FromContext(ctx).WithField("discoverForwarderServer", "request") - if forwarderName == "" { return nil, errors.New("forwarder is not selected") } @@ -175,20 +170,17 @@ func (d *discoverForwarderServer) Close(ctx context.Context, conn *networkservic Url: d.nsmgrURL, }, }) - if err != nil { logger.Errorf("can not open registry nse stream by forwarder name. Error: %v", err.Error()) - return nil, errors.WithStack(err) + return nil, err } nses := registry.ReadNetworkServiceEndpointList(stream) - if len(nses) == 0 { return nil, errors.New("forwarder not found") } u, err := url.Parse(nses[0].Url) - if err != nil { logger.Errorf("can not parse forwarder url %v", err.Error()) return nil, errors.WithStack(err) @@ -211,7 +203,6 @@ func (d *discoverForwarderServer) matchForwarders(nsLabels map[string]string, ns } var matchLabels = match.GetMetadata().GetLabels() - if matchLabels == nil { matchLabels = map[string]string{ "p2p": "true", @@ -247,10 +238,10 @@ func (d *discoverForwarderServer) discoverNetworkService(ctx context.Context, na nsRespStream, err := d.nsClient.Find(ctx, query) if err != nil { - return nil, errors.WithStack(err) + return nil, err } - nsList := registry.ReadNetworkServiceList(nsRespStream) + nsList := registry.ReadNetworkServiceList(nsRespStream) for _, ns := range nsList { if ns.Name == name { return ns, nil diff --git a/pkg/networkservice/common/excludedprefixes/client.go b/pkg/networkservice/common/excludedprefixes/client.go index fb7516f166..9afabb86e4 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"); @@ -158,7 +160,7 @@ func (epc *excludedPrefixesClient) Request(ctx context.Context, request *network ipCtx.ExcludedPrefixes = oldExcludedPrefixes - return resp, err + return resp, nil } 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,7 +227,7 @@ 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) { diff --git a/pkg/networkservice/common/journal/server.go b/pkg/networkservice/common/journal/server.go index f6dee3ac58..bc87961321 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" @@ -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 } diff --git a/pkg/networkservice/connectioncontext/dnscontext/client.go b/pkg/networkservice/connectioncontext/dnscontext/client.go index fc37618373..fe0fe5d2d5 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,11 @@ 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(err) } originalResolvConfig := string(bytes) - return os.WriteFile(c.resolveConfigPath, []byte(originalResolvConfig+resolvConf), os.ModePerm) + return errors.WithStack(os.WriteFile(c.resolveConfigPath, []byte(originalResolvConfig+resolvConf), os.ModePerm)) } func (c *dnsContextClient) initialize() { diff --git a/pkg/networkservice/connectioncontext/dnscontext/resolvconf.go b/pkg/networkservice/connectioncontext/dnscontext/resolvconf.go index 20a919d2d8..0b52c3770d 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.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..7abfddda77 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" @@ -93,7 +94,6 @@ func (n *vl3DNSServer) Request(ctx context.Context, request *networkservice.Netw dnsServerIPStr, added := n.addDNSContext(request.GetConnection()) var recordNames, err = n.buildSrcDNSRecords(request.GetConnection()) - if err != nil { return nil, err } @@ -117,7 +117,6 @@ func (n *vl3DNSServer) Request(ctx context.Context, request *networkservice.Netw } resp, err := next.Server(ctx).Request(ctx, request) - if err == nil { configs := make([]*networkservice.DNSConfig, 0) if srcRoutes := resp.GetContext().GetIpContext().GetSrcRoutes(); len(srcRoutes) > 0 { @@ -170,7 +169,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.Wrap(err, "error occurred executing the template or writing its output") } result = append(result, recordBuilder.String()) } 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..a6c1642d76 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.Wrap(err, "failed to get a monitor connections client") } for { event, err := cl.Recv() if err != nil { - return err + return errors.Wrap(err, "failed to receive a monitor connections event") } err = srv.Send(event) if err != nil { - return err + return 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..2cb2228673 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,7 +47,7 @@ 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() 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..9458d20864 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" diff --git a/pkg/networkservice/ipam/point2pointipam/server.go b/pkg/networkservice/ipam/point2pointipam/server.go index 895f93e9bd..84f379f07c 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.Wrap(s.initErr, "failed to init IPAM server") } conn := request.GetConnection() diff --git a/pkg/networkservice/ipam/singlepointipam/server.go b/pkg/networkservice/ipam/singlepointipam/server.go index ce288fb3e4..8d608f1166 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.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.Wrap(sipam.initErr, "failed to init IPAM server") } if connInfo, ok := sipam.Load(conn.GetId()); ok { diff --git a/pkg/networkservice/utils/checks/checkconnection/client.go b/pkg/networkservice/utils/checks/checkconnection/client.go index d3f8cf702d..e3306a1918 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 // diff --git a/pkg/registry/common/dnsresolve/common.go b/pkg/registry/common/dnsresolve/common.go index 26671f685e..c308404044 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,7 +80,7 @@ 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") @@ -87,7 +89,7 @@ func resolveDomain(ctx context.Context, service, domain string, r Resolver) (u * 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") @@ -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..820885c163 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" @@ -71,7 +71,7 @@ func (d *dnsNSResolveClient) Register(ctx context.Context, ns *registry.NetworkS resp.Name = interdomain.Join(resp.Name, domain) - return resp, err + return resp, nil } type dnsNSResolveFindClient struct { @@ -86,7 +86,7 @@ func (c *dnsNSResolveFindClient) Recv() (*registry.NetworkServiceResponse, error } 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) { diff --git a/pkg/registry/common/dnsresolve/nse_client.go b/pkg/registry/common/dnsresolve/nse_client.go index 1a26e56f7d..16fb7b1882 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 // @@ -77,7 +77,7 @@ func (d *dnsNSEResolveClient) Register(ctx context.Context, nse *registry.Networ return interdomain.Join(s, domain) }) - return resp, err + return resp, nil } type dnsNSEResolveFindClient struct { @@ -95,7 +95,7 @@ func (c *dnsNSEResolveFindClient) Recv() (*registry.NetworkServiceEndpointRespon 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) { diff --git a/pkg/registry/common/grpcmetadata/common.go b/pkg/registry/common/grpcmetadata/common.go index 7eeda5d615..26ee2ada4a 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" ) @@ -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) } } @@ -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,7 +86,7 @@ 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)) diff --git a/pkg/registry/common/heal/ns_client.go b/pkg/registry/common/heal/ns_client.go index ab791fed8e..79aa25237d 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"); @@ -73,7 +75,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) { 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..de2c5ce7a7 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"); @@ -73,7 +75,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) { 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/interdomainbypass/server.go b/pkg/registry/common/interdomainbypass/server.go index dfa61c1f35..53bb41ec08 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" @@ -55,7 +56,7 @@ func (n *interdomainBypassNSEServer) Register(ctx context.Context, service *regi resp.Url = originalURL - return resp, err + return resp, nil } 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/memory/ns_server.go b/pkg/registry/common/memory/ns_server.go index 87de28be35..505dfea3ff 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" @@ -103,7 +106,7 @@ func (s *memoryNSServer) Find(query *registry.NetworkServiceQuery, server regist var err error for ; err == nil; err = s.receiveEvent(query, server, eventCh) { } - if err != io.EOF { + if err.Error() != io.EOF.Error() { return 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,7 +155,7 @@ 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 } diff --git a/pkg/registry/common/memory/nse_server.go b/pkg/registry/common/memory/nse_server.go index f74fcc909d..54744d5d55 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" @@ -63,7 +66,7 @@ func (s *memoryNSEServer) Register(ctx context.Context, nse *registry.NetworkSer s.sendEvent(®istry.NetworkServiceEndpointResponse{NetworkServiceEndpoint: r}) - return r, err + return r, nil } func (s *memoryNSEServer) sendEvent(event *registry.NetworkServiceEndpointResponse) { @@ -106,7 +109,7 @@ func (s *memoryNSEServer) Find(query *registry.NetworkServiceEndpointQuery, serv var err error for ; err == nil; err = s.receiveEvent(query, server, eventCh) { } - if err != io.EOF { + if err.Error() != io.EOF.Error() { return err } return nil @@ -146,12 +149,12 @@ 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 } diff --git a/pkg/registry/common/refresh/nse_registry_client.go b/pkg/registry/common/refresh/nse_registry_client.go index ce154c377e..80a0f6054d 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 // @@ -74,7 +74,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/retry/ns_client.go b/pkg/registry/common/retry/ns_client.go index c0cf26ccc0..be53d63527 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,9 +68,9 @@ 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 } @@ -79,10 +80,10 @@ func (r *retryNSClient) Register(ctx context.Context, in *registry.NetworkServic } 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) { @@ -102,10 +103,10 @@ func (r *retryNSClient) Find(ctx context.Context, query *registry.NetworkService } 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,9 +123,9 @@ 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 } @@ -133,8 +134,8 @@ func (r *retryNSClient) Unregister(ctx context.Context, in *registry.NetworkServ return resp, 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..838d613c33 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,9 +68,9 @@ 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 } @@ -78,7 +79,7 @@ func (r *retryNSEClient) Register(ctx context.Context, nse *registry.NetworkServ return resp, 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/updatepath/ns_server.go b/pkg/registry/common/updatepath/ns_server.go index ee6fc06337..6ad7d2c634 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 // @@ -77,7 +77,7 @@ func (s *updatePathNSServer) Register(ctx context.Context, ns *registry.NetworkS } path.Index = index - return ns, err + return ns, nil } func (s *updatePathNSServer) Find(query *registry.NetworkServiceQuery, server registry.NetworkServiceRegistry_FindServer) error { diff --git a/pkg/registry/core/adapters/ns_registry.go b/pkg/registry/core/adapters/ns_registry.go index 393e0b1336..d3e068781d 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" diff --git a/pkg/registry/core/adapters/nse_registry.go b/pkg/registry/core/adapters/nse_registry.go index e17d1f4b2f..9f4ac8c11f 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" diff --git a/pkg/registry/core/streamchannel/ns_registry_stream_channel.go b/pkg/registry/core/streamchannel/ns_registry_stream_channel.go index daa95fb62b..b943b0dc1f 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"); @@ -50,7 +52,7 @@ func (c *networkServiceRegistryFindClient) Recv() (*registry.NetworkServiceRespo } return res, 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..53781f0a3d 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"); @@ -51,7 +53,7 @@ func (c *networkServiceEndpointRegistryFindClient) Recv() (*registry.NetworkServ } return res, errors.Wrap(c.err, err.Error()) } - return res, c.err + return res, errors.WithStack(c.err) } func (c *networkServiceEndpointRegistryFindClient) Context() context.Context { @@ -77,7 +79,7 @@ type networkServiceEndpointRegistryFindServer struct { func (s *networkServiceEndpointRegistryFindServer) Send(nseResp *registry.NetworkServiceEndpointResponse) error { select { case <-s.ctx.Done(): - return s.ctx.Err() + return errors.WithStack(s.ctx.Err()) case s.sendCh <- nseResp: return nil } diff --git a/pkg/registry/core/trace/ns_registry.go b/pkg/registry/core/trace/ns_registry.go index d0a6478cca..4f4a947aaf 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, nil } 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, nil } 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, nil } // 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, nil } 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, nil } // 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 nil } diff --git a/pkg/registry/core/trace/nse_registry.go b/pkg/registry/core/trace/nse_registry.go index d060275944..7fc6c9f19c 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, nil } 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, nil } 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, nil } // 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, nil } 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, nil } // 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 nil } 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..996b5e555e 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 // @@ -49,7 +49,7 @@ func (d *Decoder) Decode(value string) error { } nsurl, err := url.Parse(item) if err != nil { - return err + return errors.WithStack(err) } awarenessGroups[i] = append(awarenessGroups[i], nsurl) } @@ -95,7 +95,7 @@ func validateParentheses(value string) error { } 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/debug/self.go b/pkg/tools/debug/self.go index 0e2e53f4e1..27f02aaa96 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 // @@ -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/grpcfdutils/transceiver.go b/pkg/tools/grpcfdutils/transceiver.go index 9ea0771b57..e0aa4a9e7d 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) diff --git a/pkg/tools/ippool/ippool.go b/pkg/tools/ippool/ippool.go index c1ec44a507..b59d19f6fb 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 @@ -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...) 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/opa/opainput.go b/pkg/tools/opa/opainput.go index 87fed58a20..2b2b69c498 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"); @@ -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..f31cbbb705 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"); @@ -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.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..c9fb48b6d2 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"); @@ -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.Wrapf(err, "failed to read a policy file: %s", d.policyFilePath) } d.policySource = strings.TrimSpace(string(b)) return nil diff --git a/pkg/tools/prefixpool/prefixpool.go b/pkg/tools/prefixpool/prefixpool.go index f6b31580c7..c88aea2677 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 @@ -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) @@ -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) } } diff --git a/pkg/tools/prefixpool/prefixpool_test.go b/pkg/tools/prefixpool/prefixpool_test.go index 94d55282b7..34aedfd6c1 100644 --- a/pkg/tools/prefixpool/prefixpool_test.go +++ b/pkg/tools/prefixpool/prefixpool_test.go @@ -2,6 +2,8 @@ // // 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,6 +24,7 @@ import ( "net" "testing" + "github.com/pkg/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -238,6 +241,7 @@ func TestPrefixPoolValidation(t *testing.T) { require.Nil(t, err) _, err = prefixpool.New("10.20.0.0/56") if assert.Error(t, err) { - require.Equal(t, &net.ParseError{Type: "CIDR address", Text: "10.20.0.0/56"}, err) + expectedErr := errors.WithStack(&net.ParseError{Type: "CIDR address", Text: "10.20.0.0/56"}) + require.Equal(t, expectedErr.Error(), err.Error()) } } diff --git a/pkg/tools/spiffejwt/token.go b/pkg/tools/spiffejwt/token.go index d61f1c04ea..62a21060eb 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"); @@ -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/start.go b/pkg/tools/spire/start.go index 876784a101..77addc7c23 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.Wrapf(err, "failed to create folders: %s", path.Dir(filename)) } if err := os.WriteFile(filename, []byte(contents), 0o600); err != nil { - return err + return 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 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/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{