Skip to content

Commit

Permalink
refactor(orc8r): replace deprecated errors module (magma#12724)
Browse files Browse the repository at this point in the history
* refactor(orc8r): replace deprecated errors module

Replace functions from the github.com/pgk/errors package
with `fmt.Errorf` in /magma/orc8r. Created in pairing
with Moritz Huebner.

Signed-off-by: Sebastian Wolf <sebastian.wolf@tngtech.com>

* refactor(orc8r): replace deprecated errors module

Replace functions from the github.com/pgk/errors package
with `fmt.Errorf` in /magma/lte. Created in pairing
with Moritz Huebner.

Signed-off-by: Sebastian Wolf <sebastian.wolf@tngtech.com>
  • Loading branch information
wolfseb authored and emakeev committed Aug 5, 2022
1 parent f9b13de commit 67f9393
Show file tree
Hide file tree
Showing 134 changed files with 680 additions and 702 deletions.
2 changes: 1 addition & 1 deletion lte/cloud/go/go.mod
Expand Up @@ -40,7 +40,6 @@ require (
github.com/lib/pq v1.2.0
github.com/magma/milenage v1.0.2
github.com/olivere/elastic/v7 v7.0.6
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.5.1
github.com/prometheus/common v0.9.1
github.com/stretchr/testify v1.7.1
Expand Down Expand Up @@ -91,6 +90,7 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/procfs v0.0.8 // indirect
Expand Down
4 changes: 1 addition & 3 deletions lte/cloud/go/services/ha/servicers/southbound/servicer.go
Expand Up @@ -19,7 +19,6 @@ import (
"time"

"github.com/golang/glog"
"github.com/pkg/errors"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

Expand Down Expand Up @@ -59,8 +58,7 @@ func (s *HAServicer) GetEnodebOffloadState(ctx context.Context, req *lte_protos.
}
cfg, err := configurator.LoadEntityConfig(ctx, secondaryGw.GetNetworkId(), lte.CellularGatewayEntityType, secondaryGw.LogicalId, lte_models.EntitySerdes)
if err != nil {
errors.Wrap(err, "unable to load cellular gateway configs to find primary gateway's in its pool")
return ret, err
return ret, fmt.Errorf("unable to load cellular gateway configs to find primary gateway's in its pool: %w", err)
}
cellularCfg, ok := cfg.(*lte_models.GatewayCellularConfigs)
if !ok {
Expand Down
19 changes: 9 additions & 10 deletions lte/cloud/go/services/lte/obsidian/handlers/handlers.go
Expand Up @@ -19,7 +19,6 @@ import (
"net/http"

"github.com/labstack/echo"
"github.com/pkg/errors"
"github.com/thoas/go-funk"

"magma/lte/cloud/go/lte"
Expand Down Expand Up @@ -193,7 +192,7 @@ func getGateway(c echo.Context) error {
serdes.Entity,
)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, errors.Wrap(err, "failed to load cellular gateway"))
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Errorf("failed to load cellular gateway: %w", err))
}

ret := &lte_models.LteGateway{
Expand All @@ -219,7 +218,7 @@ func getGateway(c echo.Context) error {
case lte.APNResourceEntityType:
e, err := configurator.LoadEntity(reqCtx, nid, tk.Type, tk.Key, configurator.EntityLoadCriteria{LoadConfig: true}, serdes.Entity)
if err != nil {
return errors.Wrap(err, "error loading apn resource entity")
return fmt.Errorf("error loading apn resource entity: %w", err)
}
apnResource := (&lte_models.ApnResource{}).FromEntity(e)
ret.ApnResources[string(apnResource.ApnName)] = *apnResource
Expand Down Expand Up @@ -257,7 +256,7 @@ func deleteGateway(c echo.Context) error {
serdes.Entity,
)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, errors.Wrap(err, "error loading existing cellular gateway"))
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Errorf("error loading existing cellular gateway: %w", err))
}
deletes = append(deletes, gw.Associations.Filter(lte.APNResourceEntityType)...)

Expand Down Expand Up @@ -619,7 +618,7 @@ func updateApnConfiguration(c echo.Context) error {
case err == merrors.ErrNotFound:
return echo.ErrNotFound
case err != nil:
return echo.NewHTTPError(http.StatusInternalServerError, errors.Wrap(err, "failed to load existing APN"))
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Errorf("failed to load existing APN: %w", err))
}

err = configurator.CreateOrUpdateEntityConfig(reqCtx, networkID, lte.APNEntityType, apnName, payload.ApnConfiguration, serdes.Entity)
Expand Down Expand Up @@ -670,7 +669,7 @@ func AddNetworkWideSubscriberRuleName(c echo.Context) error {
}
err := addToNetworkSubscriberConfig(c.Request().Context(), networkID, params[0], "")
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, errors.Wrap(err, "Failed to update config"))
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Errorf("Failed to update config: %w", err))
}
return c.NoContent(http.StatusCreated)
}
Expand All @@ -686,7 +685,7 @@ func AddNetworkWideSubscriberBaseName(c echo.Context) error {
}
err := addToNetworkSubscriberConfig(c.Request().Context(), networkID, "", params[0])
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, errors.Wrap(err, "Failed to update config"))
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Errorf("Failed to update config: %w", err))
}
return c.NoContent(http.StatusCreated)
}
Expand All @@ -702,7 +701,7 @@ func RemoveNetworkWideSubscriberRuleName(c echo.Context) error {
}
err := removeFromNetworkSubscriberConfig(c.Request().Context(), networkID, params[0], "")
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, errors.Wrap(err, "Failed to update config"))
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Errorf("Failed to update config: %w", err))
}
return c.NoContent(http.StatusNoContent)
}
Expand All @@ -718,7 +717,7 @@ func RemoveNetworkWideSubscriberBaseName(c echo.Context) error {
}
err := removeFromNetworkSubscriberConfig(c.Request().Context(), networkID, "", params[0])
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, errors.Wrap(err, "Failed to update config"))
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Errorf("Failed to update config: %w", err))
}
return c.NoContent(http.StatusNoContent)
}
Expand Down Expand Up @@ -883,7 +882,7 @@ func updateGatewayPoolHandler(c echo.Context) error {
// 404 if pool doesn't exist
exists, err := configurator.DoesEntityExist(reqCtx, networkID, lte.CellularGatewayPoolEntityType, gatewayPoolID)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, errors.Wrap(err, "Error while checking if gateway pool exists"))
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Errorf("Error while checking if gateway pool exists: %w", err))
}
if !exists {
return echo.ErrNotFound
Expand Down
3 changes: 1 addition & 2 deletions lte/cloud/go/services/lte/obsidian/models/conversion.go
Expand Up @@ -19,7 +19,6 @@ import (
"sort"

"github.com/go-openapi/swag"
"github.com/pkg/errors"
"github.com/thoas/go-funk"

"magma/lte/cloud/go/lte"
Expand Down Expand Up @@ -307,7 +306,7 @@ func (m *MutableLteGateway) getAPNResourceChanges(
oldIDs := existingGateway.Associations.Filter(lte.APNResourceEntityType).Keys()
oldByAPN, err := LoadAPNResources(ctx, existingGateway.NetworkID, oldIDs)
if err != nil {
return nil, nil, errors.Wrap(err, "error loading existing APN resources")
return nil, nil, fmt.Errorf("error loading existing APN resources: %w", err)
}
oldResources := oldByAPN.GetByID()
newResources := m.ApnResources.GetByID()
Expand Down
12 changes: 6 additions & 6 deletions lte/cloud/go/services/lte/obsidian/models/validate.go
Expand Up @@ -15,14 +15,14 @@ package models

import (
"context"
"errors"
"fmt"
"net"

oerrors "github.com/go-openapi/errors"
"github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
"github.com/go-openapi/validate"
"github.com/pkg/errors"

"magma/lte/cloud/go/lte"
"magma/orc8r/cloud/go/services/configurator"
Expand Down Expand Up @@ -83,10 +83,10 @@ func (m FegNetworkID) ValidateModel(ctx context.Context) error {
if !swag.IsZero(m) {
exists, err := configurator.DoesNetworkExist(ctx, string(m))
if err != nil {
return errors.Wrap(err, fmt.Sprintf("Failed to search for network %s", string(m)))
return fmt.Errorf("Failed to search for network %s: %w", string(m), err)
}
if !exists {
return errors.New(fmt.Sprintf("Network: %s does not exist", string(m)))
return fmt.Errorf("Network: %s does not exist", string(m))
}
}
return nil
Expand Down Expand Up @@ -151,14 +151,14 @@ func (m *NetworkRanConfigs) ValidateModel(context.Context) error {
}

if tddConfigSet && band.Mode != lte.TDDMode {
return errors.Errorf("band %d not a TDD band", band.ID)
return fmt.Errorf("band %d not a TDD band", band.ID)
}
if fddConfigSet {
if band.Mode != lte.FDDMode {
return errors.Errorf("band %d not a FDD band", band.ID)
return fmt.Errorf("band %d not a FDD band", band.ID)
}
if !band.EarfcnULInRange(m.FddConfig.Earfcnul) {
return errors.Errorf("EARFCNUL=%d invalid for band %d (%d, %d)", m.FddConfig.Earfcnul, band.ID, band.StartEarfcnUl, band.StartEarfcnDl)
return fmt.Errorf("EARFCNUL=%d invalid for band %d (%d, %d)", m.FddConfig.Earfcnul, band.ID, band.StartEarfcnUl, band.StartEarfcnDl)
}
}

Expand Down
2 changes: 1 addition & 1 deletion lte/cloud/go/services/lte/protos/validate.go
Expand Up @@ -14,7 +14,7 @@
package protos

import (
"github.com/pkg/errors"
"errors"
)

func (m *GetEnodebStateRequest) Validate() error {
Expand Down
Expand Up @@ -15,14 +15,14 @@ package servicers

import (
"context"
"errors"
"fmt"
"sort"

"github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
"github.com/golang/glog"
"github.com/golang/protobuf/proto"
"github.com/pkg/errors"
"github.com/thoas/go-funk"

"magma/feg/cloud/go/feg"
Expand Down Expand Up @@ -322,7 +322,7 @@ func getPipelineDServicesConfig(networkServices []string) ([]lte_mconfig.Pipelin
for _, service := range networkServices {
mc, found := networkServicesByName[service]
if !found {
return nil, errors.Errorf("unknown network service name %s", service)
return nil, fmt.Errorf("unknown network service name %s", service)
}
apps = append(apps, mc)
}
Expand Down
Expand Up @@ -18,7 +18,6 @@ import (
"fmt"

"github.com/golang/glog"
"github.com/pkg/errors"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

Expand Down Expand Up @@ -103,12 +102,12 @@ func setEnodebState(ctx context.Context, networkID string, states state_types.St
}
gwEnt, err := configurator.LoadEntityForPhysicalID(ctx, st.ReporterID, configurator.EntityLoadCriteria{}, serdes.Entity)
if err != nil {
stateErrors[id] = errors.Wrap(err, "error loading gatewayID")
stateErrors[id] = fmt.Errorf("error loading gatewayID: %w", err)
continue
}
err = lte_api.SetEnodebState(ctx, networkID, gwEnt.Key, id.DeviceID, serializedState)
if err != nil {
stateErrors[id] = errors.Wrap(err, "error setting enodeb state")
stateErrors[id] = fmt.Errorf("error setting enodeb state: %w", err)
continue
}
glog.V(2).Infof("successfully stored ENB state for eNB SN: %s, gatewayID: %s:w", id.DeviceID, gwEnt.Key)
Expand Down
4 changes: 2 additions & 2 deletions lte/cloud/go/services/lte/servicers/protected/lookup.go
Expand Up @@ -15,8 +15,8 @@ package servicers

import (
"context"
"fmt"

"github.com/pkg/errors"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

Expand Down Expand Up @@ -62,7 +62,7 @@ func (l *lookupServicer) SetEnodebState(ctx context.Context, req *protos.SetEnod
}

func makeErr(err error, wrap string) error {
e := errors.Wrap(err, wrap)
e := fmt.Errorf(wrap+": %w", err)
code := codes.Internal
if err == merrors.ErrNotFound {
code = codes.NotFound
Expand Down
15 changes: 9 additions & 6 deletions lte/cloud/go/services/lte/storage/enodeb_state_lookup.go
Expand Up @@ -15,9 +15,9 @@ package storage

import (
"database/sql"
"fmt"

"github.com/Masterminds/squirrel"
"github.com/pkg/errors"

"magma/orc8r/cloud/go/sqorc"
"magma/orc8r/lib/go/merrors"
Expand Down Expand Up @@ -66,7 +66,10 @@ func (l *enodebStateLookup) Initialize() error {
Unique(nidCol, gidCol, enbSnCol, enbStateCol).
RunWith(tx).
Exec()
return nil, errors.Wrap(err, "initialize enodeb state lookup table")
if err != nil {
return nil, fmt.Errorf("initialize enodeb state lookup table: %w", err)
}
return nil, nil
}
_, err := sqorc.ExecInTx(l.db, nil, nil, txFn)
return err
Expand All @@ -81,22 +84,22 @@ func (l *enodebStateLookup) GetEnodebState(networkID string, gatewayID string, e
RunWith(tx).
Query()
if err != nil {
return nil, errors.Wrapf(err, "select EnodebState for gatewayID, enodebSN %v, %v", gatewayID, enodebSN)
return nil, fmt.Errorf("select EnodebState for gatewayID, enodebSN %v, %v: %w", gatewayID, enodebSN, err)
}
defer sqorc.CloseRowsLogOnError(rows, "GetEnodebState")

var serializedState []byte
for rows.Next() {
err = rows.Scan(&serializedState)
if err != nil {
return nil, errors.Wrap(err, "select EnodebState for (gatewayID, enodebSN), SQL row scan error")
return nil, fmt.Errorf("select EnodebState for (gatewayID, enodebSN), SQL row scan error: %w", err)
}
// always return the first record as all cols are unique
break
}
err = rows.Err()
if err != nil {
return nil, errors.Wrap(err, "select EnodebState for (gatewayID, enodebSN), SQL rows error")
return nil, fmt.Errorf("select EnodebState for (gatewayID, enodebSN), SQL rows error: %w", err)
}
return serializedState, nil
}
Expand Down Expand Up @@ -127,7 +130,7 @@ func (l *enodebStateLookup) SetEnodebState(networkID string, gatewayID string, e
RunWith(sc).
Exec()
if err != nil {
return nil, errors.Wrapf(err, "insert EnodbeState %+v", enodebState)
return nil, fmt.Errorf("insert EnodbeState %+v: %w", enodebState, err)
}
return nil, nil
}
Expand Down
6 changes: 3 additions & 3 deletions lte/cloud/go/services/nprobe/obsidian/handlers/handlers.go
Expand Up @@ -14,13 +14,13 @@
package handlers

import (
"fmt"
"math/rand"
"net/http"
"time"

strfmt "github.com/go-openapi/strfmt"
"github.com/labstack/echo"
"github.com/pkg/errors"

"magma/lte/cloud/go/lte"
"magma/lte/cloud/go/serdes"
Expand Down Expand Up @@ -75,7 +75,7 @@ func listNetworkProbeTasks(c echo.Context) error {
return echo.ErrNotFound
}
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, errors.Wrap(err, "failed to load existing NetworkProbeTasks"))
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Errorf("failed to load existing NetworkProbeTasks: %w", err))
}

ret := make(map[string]*models.NetworkProbeTask, len(ents))
Expand Down Expand Up @@ -115,7 +115,7 @@ func getCreateNetworkProbeTaskHandlerFunc(storage storage.NProbeStorage) echo.Ha

taskID := string(payload.TaskID)
if err := storage.StoreNProbeData(networkID, taskID, data); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, errors.Wrap(err, "failed to store NetworkProbeData"))
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Errorf("failed to store NetworkProbeData: %w", err))
}

_, err := configurator.CreateEntity(
Expand Down

0 comments on commit 67f9393

Please sign in to comment.