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

Use serrors.New instead of common.NewBasicError #3175

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go/beacon_srv/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ go_library(
"//go/lib/periodic:go_default_library",
"//go/lib/prom:go_default_library",
"//go/lib/scrypto:go_default_library",
"//go/lib/serrors:go_default_library",
"//go/lib/snet:go_default_library",
"//go/lib/sock/reliable:go_default_library",
"//go/lib/sock/reliable/reconnect:go_default_library",
Expand Down
1 change: 1 addition & 0 deletions go/beacon_srv/internal/beacon/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ go_library(
"//go/lib/infra/modules/db:go_default_library",
"//go/lib/log:go_default_library",
"//go/lib/prom:go_default_library",
"//go/lib/serrors:go_default_library",
"//go/lib/spath:go_default_library",
"//go/lib/util:go_default_library",
"//go/proto:go_default_library",
Expand Down
3 changes: 2 additions & 1 deletion go/beacon_srv/internal/beacon/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/scionproto/scion/go/lib/common"
"github.com/scionproto/scion/go/lib/ctrl/path_mgmt"
"github.com/scionproto/scion/go/lib/log"
"github.com/scionproto/scion/go/lib/serrors"
"github.com/scionproto/scion/go/lib/spath"
"github.com/scionproto/scion/go/proto"
)
Expand Down Expand Up @@ -273,7 +274,7 @@ func (s *baseStore) DeleteExpiredRevocations(ctx context.Context) (int, error) {
// UpdatePolicy updates the policy. Beacons that are filtered by all
// policies after the update are removed.
func (s *baseStore) UpdatePolicy(ctx context.Context, policy Policy) error {
return common.NewBasicError("policy update not supported", nil)
return serrors.New("policy update not supported")
}

// Close closes the store and the underlying database connection.
Expand Down
2 changes: 2 additions & 0 deletions go/beacon_srv/internal/beaconing/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ go_library(
"//go/lib/infra/modules/segverifier:go_default_library",
"//go/lib/log:go_default_library",
"//go/lib/periodic:go_default_library",
"//go/lib/serrors:go_default_library",
"//go/lib/snet:go_default_library",
"//go/lib/snet/addrutil:go_default_library",
"//go/lib/spath:go_default_library",
Expand Down Expand Up @@ -67,6 +68,7 @@ go_test(
"//go/lib/log:go_default_library",
"//go/lib/overlay:go_default_library",
"//go/lib/scrypto:go_default_library",
"//go/lib/serrors:go_default_library",
"//go/lib/snet:go_default_library",
"//go/lib/snet/mock_snet:go_default_library",
"//go/lib/spath:go_default_library",
Expand Down
9 changes: 5 additions & 4 deletions go/beacon_srv/internal/beaconing/extender.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/scionproto/scion/go/lib/common"
"github.com/scionproto/scion/go/lib/ctrl/seg"
"github.com/scionproto/scion/go/lib/log"
"github.com/scionproto/scion/go/lib/serrors"
"github.com/scionproto/scion/go/lib/spath"
"github.com/scionproto/scion/go/lib/util"
)
Expand All @@ -49,7 +50,7 @@ func (s *segExtender) extend(pseg *seg.PathSegment, inIfid, egIfid common.IFIDTy
peers []common.IFIDType) error {

if inIfid == 0 && egIfid == 0 {
return common.NewBasicError("Ingress and egress must not be both 0", nil)
return serrors.New("Ingress and egress must not be both 0")
}
infoF, err := pseg.InfoF()
if err != nil {
Expand Down Expand Up @@ -135,15 +136,15 @@ func (s *segExtender) remoteInfo(ifid common.IFIDType) (
}
intf := s.cfg.Intfs.Get(ifid)
if intf == nil {
return 0, 0, 0, common.NewBasicError("Interface not found", nil)
return 0, 0, 0, serrors.New("Interface not found")
}
state := intf.State()
if state != ifstate.Active {
return 0, 0, 0, common.NewBasicError("Interface is not active", nil)
return 0, 0, 0, serrors.New("Interface is not active")
}
topoInfo := intf.TopoInfo()
if topoInfo.RemoteIFID == 0 {
return 0, 0, 0, common.NewBasicError("Remote ifid is not set", nil)
return 0, 0, 0, serrors.New("Remote ifid is not set")
}
if topoInfo.ISD_AS.IsWildcard() {
return 0, 0, 0, common.NewBasicError("Remote IA is wildcard", nil, "ia", topoInfo.ISD_AS)
Expand Down
8 changes: 4 additions & 4 deletions go/beacon_srv/internal/beaconing/extender_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (
"hash"

"github.com/scionproto/scion/go/beacon_srv/internal/ifstate"
"github.com/scionproto/scion/go/lib/common"
"github.com/scionproto/scion/go/lib/infra"
"github.com/scionproto/scion/go/lib/serrors"
"github.com/scionproto/scion/go/lib/spath"
)

Expand Down Expand Up @@ -56,13 +56,13 @@ func (cfg *ExtenderConf) InitDefaults() {
// Validate checks that the config contains a signer.
func (cfg *ExtenderConf) Validate() error {
if cfg.Signer == nil {
return common.NewBasicError("Signer must be set", nil)
return serrors.New("Signer must be set")
}
if cfg.IfidSize == 0 {
return common.NewBasicError("IfidSize must be set", nil)
return serrors.New("IfidSize must be set")
}
if cfg.MTU == 0 {
return common.NewBasicError("MTU must be set", nil)
return serrors.New("MTU must be set")
}
return nil
}
3 changes: 2 additions & 1 deletion go/beacon_srv/internal/beaconing/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/scionproto/scion/go/lib/infra/messenger"
"github.com/scionproto/scion/go/lib/infra/modules/segverifier"
"github.com/scionproto/scion/go/lib/log"
"github.com/scionproto/scion/go/lib/serrors"
"github.com/scionproto/scion/go/lib/snet"
"github.com/scionproto/scion/go/proto"
)
Expand Down Expand Up @@ -76,7 +77,7 @@ func (h *handler) Handle() *infra.HandlerResult {
func (h *handler) handle(logger log.Logger) (*infra.HandlerResult, error) {
rw, ok := infra.ResponseWriterFromContext(h.request.Context())
if !ok {
return infra.MetricsErrInternal, common.NewBasicError("No Messenger found", nil)
return infra.MetricsErrInternal, serrors.New("No Messenger found")
}

sendAck := messenger.SendAckHelper(h.request.Context(), rw)
Expand Down
5 changes: 3 additions & 2 deletions go/beacon_srv/internal/beaconing/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/scionproto/scion/go/lib/infra"
"github.com/scionproto/scion/go/lib/infra/mock_infra"
"github.com/scionproto/scion/go/lib/log"
"github.com/scionproto/scion/go/lib/serrors"
"github.com/scionproto/scion/go/lib/snet"
"github.com/scionproto/scion/go/lib/spath"
"github.com/scionproto/scion/go/lib/topology"
Expand Down Expand Up @@ -166,7 +167,7 @@ func TestNewHandler(t *testing.T) {
verifier.EXPECT().WithSrc(gomock.Any()).Return(verifier)
verifier.EXPECT().WithServer(gomock.Any()).Return(verifier)
verifier.EXPECT().Verify(gomock.Any(), gomock.Any(),
gomock.Any()).MaxTimes(2).Return(common.NewBasicError("failed", nil))
gomock.Any()).MaxTimes(2).Return(serrors.New("failed"))

handler := NewHandler(localIA, intfs, inserter, verifier)
pseg := testBeacon(g, []common.IFIDType{graph.If_220_X_120_B, graph.If_120_A_110_X}).Segment
Expand All @@ -177,7 +178,7 @@ func TestNewHandler(t *testing.T) {
inserter := mock_beaconing.NewMockBeaconInserter(mctrl)
inserter.EXPECT().PreFilter(gomock.Any()).Return(nil)
inserter.EXPECT().InsertBeacon(gomock.Any(),
gomock.Any()).Return(beacon.InsertStats{}, common.NewBasicError("failed", nil))
gomock.Any()).Return(beacon.InsertStats{}, serrors.New("failed"))

verifier := mock_infra.NewMockVerifier(mctrl)
verifier.EXPECT().WithServer(gomock.Any()).MaxTimes(2).Return(verifier)
Expand Down
3 changes: 2 additions & 1 deletion go/beacon_srv/internal/beaconing/originator.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/scionproto/scion/go/lib/ctrl/seg"
"github.com/scionproto/scion/go/lib/log"
"github.com/scionproto/scion/go/lib/periodic"
"github.com/scionproto/scion/go/lib/serrors"
"github.com/scionproto/scion/go/lib/spath"
"github.com/scionproto/scion/go/lib/util"
"github.com/scionproto/scion/go/proto"
Expand Down Expand Up @@ -164,7 +165,7 @@ func (o *beaconOriginator) originateBeacon(ctx context.Context) error {
intf := o.cfg.Intfs.Get(o.ifId)
if intf == nil {
o.metrics.IncInternalErr()
return common.NewBasicError("Interface does not exist", nil)
return serrors.New("Interface does not exist")
}
topoInfo := intf.TopoInfo()
ov := topoInfo.InternalAddrs.PublicOverlay(topoInfo.InternalAddrs.Overlay)
Expand Down
1 change: 1 addition & 0 deletions go/beacon_srv/internal/beaconstorage/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ go_library(
"//go/lib/infra/modules/cleaner:go_default_library",
"//go/lib/infra/modules/db:go_default_library",
"//go/lib/log:go_default_library",
"//go/lib/serrors:go_default_library",
"//go/lib/spath:go_default_library",
"//go/lib/util:go_default_library",
"//go/proto:go_default_library",
Expand Down
3 changes: 2 additions & 1 deletion go/beacon_srv/internal/beaconstorage/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/scionproto/scion/go/lib/config"
"github.com/scionproto/scion/go/lib/infra/modules/db"
"github.com/scionproto/scion/go/lib/log"
"github.com/scionproto/scion/go/lib/serrors"
"github.com/scionproto/scion/go/lib/util"
)

Expand Down Expand Up @@ -102,7 +103,7 @@ func (cfg *BeaconDBConf) validateBackend() error {
case BackendSqlite:
return nil
case backendNone:
return common.NewBasicError("No backend set", nil)
return serrors.New("No backend set")
}
return common.NewBasicError("Unsupported backend", nil, "backend", cfg.Backend())
}
Expand Down
1 change: 1 addition & 0 deletions go/beacon_srv/internal/config/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ go_library(
"//go/lib/ctrl/path_mgmt:go_default_library",
"//go/lib/env:go_default_library",
"//go/lib/infra/modules/idiscovery:go_default_library",
"//go/lib/serrors:go_default_library",
"//go/lib/truststorage:go_default_library",
"//go/lib/util:go_default_library",
],
Expand Down
19 changes: 10 additions & 9 deletions go/beacon_srv/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/scionproto/scion/go/lib/ctrl/path_mgmt"
"github.com/scionproto/scion/go/lib/env"
"github.com/scionproto/scion/go/lib/infra/modules/idiscovery"
"github.com/scionproto/scion/go/lib/serrors"
"github.com/scionproto/scion/go/lib/truststorage"
"github.com/scionproto/scion/go/lib/util"
)
Expand Down Expand Up @@ -162,35 +163,35 @@ func (cfg *BSConfig) InitDefaults() {
// Validate validates that all durations are set.
func (cfg *BSConfig) Validate() error {
if cfg.KeepaliveInterval.Duration == 0 {
return common.NewBasicError("KeepaliveInterval not set", nil)
return serrors.New("KeepaliveInterval not set")
}
if cfg.KeepaliveTimeout.Duration == 0 {
return common.NewBasicError("KeepaliveTimeout not set", nil)
return serrors.New("KeepaliveTimeout not set")
}
if cfg.OriginationInterval.Duration == 0 {
return common.NewBasicError("OriginationInterval not set", nil)
return serrors.New("OriginationInterval not set")
}
if cfg.PropagationInterval.Duration == 0 {
return common.NewBasicError("PropagationInterval not set", nil)
return serrors.New("PropagationInterval not set")
}
if cfg.RegistrationInterval.Duration == 0 {
return common.NewBasicError("RegistrationInterval not set", nil)
return serrors.New("RegistrationInterval not set")
}
if cfg.ExpiredCheckInterval.Duration == 0 {
return common.NewBasicError("ExpiredCheckInterval not set", nil)
return serrors.New("ExpiredCheckInterval not set")
}
if cfg.RevTTL.Duration == 0 {
return common.NewBasicError("RevTTL is not set", nil)
return serrors.New("RevTTL is not set")
}
if cfg.RevTTL.Duration < path_mgmt.MinRevTTL {
return common.NewBasicError("RevTTL must be equal or greater than MinRevTTL", nil,
"MinRevTTL", path_mgmt.MinRevTTL)
}
if cfg.RevOverlap.Duration == 0 {
return common.NewBasicError("RevOverlap not set", nil)
return serrors.New("RevOverlap not set")
}
if cfg.RevOverlap.Duration > cfg.RevTTL.Duration {
return common.NewBasicError("RevOverlap cannot be greater than RevTTL", nil)
return serrors.New("RevOverlap cannot be greater than RevTTL")
}
return nil
}
Expand Down
1 change: 1 addition & 0 deletions go/beacon_srv/internal/ifstate/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ go_library(
"//go/lib/infra/messenger:go_default_library",
"//go/lib/log:go_default_library",
"//go/lib/periodic:go_default_library",
"//go/lib/serrors:go_default_library",
"//go/lib/snet:go_default_library",
"//go/lib/topology:go_default_library",
"//go/lib/util:go_default_library",
Expand Down
3 changes: 2 additions & 1 deletion go/beacon_srv/internal/ifstate/ifstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/scionproto/scion/go/lib/common"
"github.com/scionproto/scion/go/lib/ctrl/path_mgmt"
"github.com/scionproto/scion/go/lib/serrors"
"github.com/scionproto/scion/go/lib/topology"
)

Expand Down Expand Up @@ -184,7 +185,7 @@ func (intf *Interface) Revoke(rev *path_mgmt.SignedRevInfo) error {
intf.mu.Lock()
defer intf.mu.Unlock()
if intf.state == Active {
return common.NewBasicError("Interface activated in the meantime", nil)
return serrors.New("Interface activated in the meantime")
}
intf.state = Revoked
intf.revocation = rev
Expand Down
3 changes: 2 additions & 1 deletion go/beacon_srv/internal/ifstate/mock_ifstate/ifstate.go

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

3 changes: 2 additions & 1 deletion go/beacon_srv/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import (
"github.com/scionproto/scion/go/lib/periodic"
"github.com/scionproto/scion/go/lib/prom"
"github.com/scionproto/scion/go/lib/scrypto"
"github.com/scionproto/scion/go/lib/serrors"
"github.com/scionproto/scion/go/lib/snet"
"github.com/scionproto/scion/go/lib/sock/reliable"
"github.com/scionproto/scion/go/lib/sock/reliable/reconnect"
Expand Down Expand Up @@ -292,7 +293,7 @@ func (t *periodicTasks) Start() error {
topo := t.topoProvider.Get()
topoAddress := topo.BS.GetById(cfg.General.ID)
if topoAddress == nil {
return common.NewBasicError("Unable to find topo address", nil)
return serrors.New("Unable to find topo address")
}
var err error
if t.registrars, err = t.startSegRegRunners(); err != nil {
Expand Down
1 change: 1 addition & 0 deletions go/border/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ go_library(
"//go/lib/ringbuf:go_default_library",
"//go/lib/scmp:go_default_library",
"//go/lib/scrypto:go_default_library",
"//go/lib/serrors:go_default_library",
"//go/lib/topology:go_default_library",
"//go/proto:go_default_library",
"@com_github_burntsushi_toml//:go_default_library",
Expand Down
3 changes: 2 additions & 1 deletion go/border/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/scionproto/scion/go/lib/log"
"github.com/scionproto/scion/go/lib/profile"
"github.com/scionproto/scion/go/lib/prom"
"github.com/scionproto/scion/go/lib/serrors"
)

var (
Expand Down Expand Up @@ -133,7 +134,7 @@ func checkPerms() error {
return common.NewBasicError("Error retrieving user", err)
}
if u.Uid == "0" {
return common.NewBasicError("Running as root is not allowed for security reasons", nil)
return serrors.New("Running as root is not allowed for security reasons")
}
return nil
}
3 changes: 2 additions & 1 deletion go/border/rpkt/extns.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package rpkt
import (
"github.com/scionproto/scion/go/lib/common"
"github.com/scionproto/scion/go/lib/scmp"
"github.com/scionproto/scion/go/lib/serrors"
)

// rExtension extends common.ExtnBase, adding a method to retrieve the
Expand Down Expand Up @@ -134,7 +135,7 @@ func (rp *RtrPkt) extnAddE2E(e common.Extension) error {
// that extension, as well as a pointer to the nextHdr field of that extension.
func (rp *RtrPkt) extnOffsetNew(isHBH bool) (int, *uint8, error) {
if isHBH && len(rp.E2EExt) > 0 {
return 0, nil, common.NewBasicError("HBH extension illegal to add after E2E extension", nil)
return 0, nil, serrors.New("HBH extension illegal to add after E2E extension")
}
offset := rp.CmnHdr.HdrLenBytes()
nextHdr := (*uint8)(&rp.CmnHdr.NextHdr)
Expand Down
7 changes: 4 additions & 3 deletions go/border/rpkt/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/scionproto/scion/go/lib/assert"
"github.com/scionproto/scion/go/lib/common"
"github.com/scionproto/scion/go/lib/scmp"
"github.com/scionproto/scion/go/lib/serrors"
"github.com/scionproto/scion/go/lib/spath"
"github.com/scionproto/scion/go/proto"
)
Expand All @@ -47,7 +48,7 @@ func (rp *RtrPkt) validatePath(dirFrom rcmn.Dir) error {
if rp.infoF.Shortcut {
currentLinkType := rp.Ctx.Conf.BR.IFs[*rp.ifCurr].LinkType
if currentLinkType == proto.LinkType_core {
return common.NewBasicError("Shortcut not allowed on core segment", nil)
return serrors.New("Shortcut not allowed on core segment")
}
}
// A verify-only Hop Field cannot be used for routing.
Expand Down Expand Up @@ -82,7 +83,7 @@ func (rp *RtrPkt) validatePath(dirFrom rcmn.Dir) error {
// destination is this router.
func (rp *RtrPkt) validateLocalIF(ifid *common.IFIDType) error {
if ifid == nil {
return common.NewBasicError("validateLocalIF: Interface is nil", nil)
return serrors.New("validateLocalIF: Interface is nil")
}
if _, ok := rp.Ctx.Conf.Topo.IFInfoMap[*ifid]; !ok {
// No such interface.
Expand Down Expand Up @@ -448,7 +449,7 @@ func (rp *RtrPkt) IFCurr() (*common.IFIDType, error) {
// valid before setting the ifCurr field and returning the value.
func (rp *RtrPkt) checkSetCurrIF(ifid *common.IFIDType) (*common.IFIDType, error) {
if ifid == nil {
return nil, common.NewBasicError("No interface found", nil)
return nil, serrors.New("No interface found")
}
if _, ok := rp.Ctx.Conf.BR.IFs[*ifid]; !ok {
return nil, common.NewBasicError("Unknown interface", nil, "ifid", *ifid)
Expand Down
Loading