Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(lte): replace deprecated errors module #12728

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions lte/cloud/go/services/ha/servicers/southbound/servicer.go
Original file line number Diff line number Diff line change
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,7 +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")
fmt.Errorf("unable to load cellular gateway configs to find primary gateway's in its pool: %w", err)
return ret, err
}
cellularCfg, ok := cfg.(*lte_models.GatewayCellularConfigs)
Expand Down
19 changes: 9 additions & 10 deletions lte/cloud/go/services/lte/obsidian/handlers/handlers.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
2 changes: 1 addition & 1 deletion lte/cloud/go/services/lte/obsidian/models/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ 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(fmt.Sprintf("Failed to search for network %s: %w", string(m)), err)
}
if !exists {
return errors.New(fmt.Sprintf("Network: %s does not exist", string(m)))
Expand Down
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
12 changes: 6 additions & 6 deletions lte/cloud/go/services/lte/storage/enodeb_state_lookup.go
Original file line number Diff line number Diff line change
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,7 @@ func (l *enodebStateLookup) Initialize() error {
Unique(nidCol, gidCol, enbSnCol, enbStateCol).
RunWith(tx).
Exec()
return nil, errors.Wrap(err, "initialize enodeb state lookup table")
return nil, fmt.Errorf("initialize enodeb state lookup table: %w", err)
}
_, err := sqorc.ExecInTx(l.db, nil, nil, txFn)
return err
Expand All @@ -81,22 +81,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 +127,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
Original file line number Diff line number Diff line change
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
18 changes: 8 additions & 10 deletions lte/cloud/go/services/nprobe/storage/storage_blobstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ package storage
import (
"fmt"

"github.com/pkg/errors"

"magma/lte/cloud/go/services/nprobe/obsidian/models"
"magma/orc8r/cloud/go/blobstore"
"magma/orc8r/cloud/go/storage"
Expand All @@ -40,7 +38,7 @@ type nprobeBlobStore struct {
func (c *nprobeBlobStore) StoreNProbeData(networkID, taskID string, data models.NetworkProbeData) error {
store, err := c.factory.StartTransaction(nil)
if err != nil {
return errors.Wrap(err, "failed to start transaction")
return fmt.Errorf("failed to start transaction: %w", err)
}
defer store.Rollback()

Expand All @@ -51,7 +49,7 @@ func (c *nprobeBlobStore) StoreNProbeData(networkID, taskID string, data models.

err = store.Write(networkID, blobstore.Blobs{dataBlob})
if err != nil {
return errors.Wrap(err, fmt.Sprintf("failed to store nprobe data %s", taskID))
return fmt.Errorf(fmt.Sprintf("failed to store nprobe data %s: %w", taskID), err)
}
return store.Commit()
}
Expand All @@ -60,7 +58,7 @@ func (c *nprobeBlobStore) StoreNProbeData(networkID, taskID string, data models.
func (c *nprobeBlobStore) GetNProbeData(networkID, taskID string) (*models.NetworkProbeData, error) {
store, err := c.factory.StartTransaction(&storage.TxOptions{ReadOnly: true})
if err != nil {
return nil, errors.Wrap(err, "failed to start transaction")
return nil, fmt.Errorf("failed to start transaction: %w", err)
}
defer store.Rollback()

Expand All @@ -69,7 +67,7 @@ func (c *nprobeBlobStore) GetNProbeData(networkID, taskID string) (*models.Netwo
storage.TK{Type: NProbeBlobType, Key: taskID},
)
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("failed to get nprobe data %s", taskID))
return nil, fmt.Errorf(fmt.Sprintf("failed to get nprobe data %s: %w", taskID), err)
}

data, err := nprobeDataFromBlob(blob)
Expand All @@ -83,7 +81,7 @@ func (c *nprobeBlobStore) GetNProbeData(networkID, taskID string) (*models.Netwo
func (c *nprobeBlobStore) DeleteNProbeData(networkID, taskID string) error {
store, err := c.factory.StartTransaction(&storage.TxOptions{ReadOnly: true})
if err != nil {
return errors.Wrap(err, "failed to start transaction")
return fmt.Errorf("failed to start transaction: %w", err)
}
defer store.Rollback()

Expand All @@ -94,15 +92,15 @@ func (c *nprobeBlobStore) DeleteNProbeData(networkID, taskID string) error {
},
)
if err != nil {
return errors.Wrap(err, fmt.Sprintf("failed to delete nprobe data %s", taskID))
return fmt.Errorf(fmt.Sprintf("failed to delete nprobe data %s: %w", taskID), err)
}
return store.Commit()
}

func nprobeDataToBlob(taskID string, data models.NetworkProbeData) (blobstore.Blob, error) {
marshaledData, err := data.MarshalBinary()
if err != nil {
return blobstore.Blob{}, errors.Wrap(err, "Error marshaling NetworkProbeData")
return blobstore.Blob{}, fmt.Errorf("Error marshaling NetworkProbeData: %w", err)
}
return blobstore.Blob{
Type: NProbeBlobType,
Expand All @@ -115,7 +113,7 @@ func nprobeDataFromBlob(blob blobstore.Blob) (models.NetworkProbeData, error) {
data := models.NetworkProbeData{}
err := data.UnmarshalBinary(blob.Value)
if err != nil {
return models.NetworkProbeData{}, errors.Wrap(err, "Error unmarshaling NetworkProbeData")
return models.NetworkProbeData{}, fmt.Errorf("Error unmarshaling NetworkProbeData: %w", err)
}
return data, nil
}