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

errors: Use common.ErrMsg for constants #3314

Merged
merged 3 commits into from
Nov 5, 2019
Merged
Changes from 1 commit
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
Next Next commit
errors: Use common.ErrMsg for constants
This PR prepares for migration from common.NewBasicError towards serrors.
  • Loading branch information
lukedirtwalker committed Nov 5, 2019
commit 1bee6849f1dcc84e396ed31df70786de9d7fa87d
4 changes: 2 additions & 2 deletions go/beacon_srv/internal/beacon/db.go
Original file line number Diff line number Diff line change
@@ -31,9 +31,9 @@ import (
const (
// ErrReadingRows is the error message in case we fail to read more from
// the database.
ErrReadingRows = "Failed to read rows"
ErrReadingRows common.ErrMsg = "Failed to read rows"
// ErrParse is the error message in case the parsing a db entry fails.
ErrParse = "Failed to parse entry"
ErrParse common.ErrMsg = "Failed to parse entry"
)

// DBRead defines all read operations of the beacon DB.
4 changes: 2 additions & 2 deletions go/beacon_srv/main.go
Original file line number Diff line number Diff line change
@@ -147,7 +147,7 @@ func realMain() int {
}
msgr, err := nc.Messenger()
if err != nil {
log.Crit(infraenv.ErrAppUnableToInitMessenger, "err", err)
log.Crit(infraenv.ErrAppUnableToInitMessenger.Error(), "err", err)
return 1
}
defer msgr.CloseServer()
@@ -215,7 +215,7 @@ func realMain() int {
}
signer, err := tasks.createSigner(topo.IA())
if err != nil {
log.Crit(infraenv.ErrAppUnableToInitMessenger, "err", err)
log.Crit(infraenv.ErrAppUnableToInitMessenger.Error(), "err", err)
return 1
}
msgr.UpdateSigner(signer, []infra.MessageType{infra.Seg})
2 changes: 1 addition & 1 deletion go/border/rpkt/extns.go
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ type rExtension interface {

const (
// FIXME(kormat): remove when generic header walker is implemented.
ErrExtChainTooLong = "Extension header chain longer than packet"
ErrExtChainTooLong common.ErrMsg = "Extension header chain longer than packet"
)

// extnParseHBH parses a specified hop-by-hop extension in a packet.
6 changes: 3 additions & 3 deletions go/border/rpkt/validate.go
Original file line number Diff line number Diff line change
@@ -23,9 +23,9 @@ import (
)

const (
errCurrIntfInvalid = "Invalid current interface"
errIntfRevoked = "Interface revoked"
errHookResponse = "Extension hook return value unrecognised"
errCurrIntfInvalid common.ErrMsg = "Invalid current interface"
errIntfRevoked common.ErrMsg = "Interface revoked"
errHookResponse common.ErrMsg = "Extension hook return value unrecognised"
)

// Validate performs basic validation of a packet, including calling any
5 changes: 3 additions & 2 deletions go/cert_srv/internal/config/config.go
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ import (
"io"
"time"

"github.com/scionproto/scion/go/lib/common"
"github.com/scionproto/scion/go/lib/config"
"github.com/scionproto/scion/go/lib/env"
"github.com/scionproto/scion/go/lib/infra/modules/idiscovery"
@@ -39,8 +40,8 @@ const (
// ReissueReqTimeout is the default timeout of a reissue request.
ReissueReqTimeout = 5 * time.Second

ErrorKeyConf = "Unable to load KeyConf"
ErrorCustomers = "Unable to load Customers"
ErrorKeyConf common.ErrMsg = "Unable to load KeyConf"
ErrorCustomers common.ErrMsg = "Unable to load Customers"
)

var _ config.Config = (*Config)(nil)
9 changes: 6 additions & 3 deletions go/cert_srv/internal/reiss/handler.go
Original file line number Diff line number Diff line change
@@ -37,9 +37,12 @@ import (

const (
HandlerTimeout = 5 * time.Second
)

KeyChanged = "Verifying key has changed in the meantime"
NotACustomer = "ISD-AS not in customer mapping"
// Errors
const (
ErrKeyChanged common.ErrMsg = "Verifying key has changed in the meantime"
ErrNotACustomer common.ErrMsg = "ISD-AS not in customer mapping"
)

// Handler handles certificate chain reissue requests.
@@ -258,7 +261,7 @@ func (h *Handler) getVerifyingKey(ctx context.Context,
return nil, 0, err
}
if k == nil {
return nil, 0, common.NewBasicError(NotACustomer, nil, "ISD-AS", ia)
return nil, 0, common.NewBasicError(ErrNotACustomer, nil, "ISD-AS", ia)
}
return k.Key, k.Version, nil
}
10 changes: 5 additions & 5 deletions go/cert_srv/setup.go
Original file line number Diff line number Diff line change
@@ -40,11 +40,11 @@ import (
)

const (
ErrorConf = "Unable to load configuration"
ErrorDispClose = "Unable to close dispatcher"
ErrorDispInit = "Unable to initialize dispatcher"
ErrorSign = "Unable to create sign"
ErrorSNET = "Unable to create local SCION Network context"
ErrorConf common.ErrMsg = "Unable to load configuration"
ErrorDispClose common.ErrMsg = "Unable to close dispatcher"
ErrorDispInit common.ErrMsg = "Unable to initialize dispatcher"
ErrorSign common.ErrMsg = "Unable to create sign"
ErrorSNET common.ErrMsg = "Unable to create local SCION Network context"
)

// setupBasic loads the config from file and initializes logging.
20 changes: 11 additions & 9 deletions go/godispatcher/internal/registration/errors.go
Original file line number Diff line number Diff line change
@@ -14,14 +14,16 @@

package registration

import "github.com/scionproto/scion/go/lib/common"

const (
ErrNoPublicAddress = "no public address"
ErrBindWithoutSvc = "bind address without svc address"
ErrOverlappingAddress = "overlapping address"
ErrNoValue = "nil value"
ErrZeroIP = "zero address"
ErrZeroPort = "zero port"
ErrNilAddress = "nil address"
ErrSvcNone = "svc none"
ErrNoPorts = "no free ports"
ErrNoPublicAddress common.ErrMsg = "no public address"
ErrBindWithoutSvc common.ErrMsg = "bind address without svc address"
ErrOverlappingAddress common.ErrMsg = "overlapping address"
ErrNoValue common.ErrMsg = "nil value"
ErrZeroIP common.ErrMsg = "zero address"
ErrZeroPort common.ErrMsg = "zero port"
ErrNilAddress common.ErrMsg = "nil address"
ErrSvcNone common.ErrMsg = "svc none"
ErrNoPorts common.ErrMsg = "no free ports"
)
4 changes: 2 additions & 2 deletions go/godispatcher/internal/registration/iatable.go
Original file line number Diff line number Diff line change
@@ -23,8 +23,8 @@ import (
)

const (
ErrBadISD = "0 is not valid ISD"
ErrBadAS = "0 is not valid AS"
ErrBadISD common.ErrMsg = "0 is not valid ISD"
ErrBadAS common.ErrMsg = "0 is not valid AS"
)

// Reference tracks an object from a collection.
4 changes: 2 additions & 2 deletions go/godispatcher/internal/registration/iatable_test.go
Original file line number Diff line number Diff line change
@@ -90,12 +90,12 @@ func TestIATableRegister(t *testing.T) {
value := "test value"
Convey("ISD zero is error", func() {
ref, err := table.Register(addr.IA{I: 0, A: 1}, public, nil, addr.SvcNone, value)
xtest.SoMsgErrorStr("err", err, ErrBadISD)
xtest.SoMsgErrorStr("err", err, ErrBadISD.Error())
SoMsg("ref", ref, ShouldBeNil)
})
Convey("AS zero is error", func() {
ref, err := table.Register(addr.IA{I: 1, A: 0}, public, nil, addr.SvcNone, value)
xtest.SoMsgErrorStr("err", err, ErrBadAS)
xtest.SoMsgErrorStr("err", err, ErrBadAS.Error())
SoMsg("ref", ref, ShouldBeNil)
})
Convey("for a good AS number", func() {
10 changes: 5 additions & 5 deletions go/godispatcher/network/overlay.go
Original file line number Diff line number Diff line change
@@ -31,11 +31,11 @@ import (
)

const (
ErrUnsupportedL4 = "unsupported SCION L4 protocol"
ErrUnsupportedDestination = "unsupported destination address type"
ErrUnsupportedSCMPDestination = "unsupported SCMP destination address type"
ErrUnsupportedQuotedL4Type = "unsupported quoted L4 protocol type"
ErrMalformedL4Quote = "malformed L4 quote"
ErrUnsupportedL4 common.ErrMsg = "unsupported SCION L4 protocol"
ErrUnsupportedDestination common.ErrMsg = "unsupported destination address type"
ErrUnsupportedSCMPDestination common.ErrMsg = "unsupported SCMP destination address type"
ErrUnsupportedQuotedL4Type common.ErrMsg = "unsupported quoted L4 protocol type"
ErrMalformedL4Quote common.ErrMsg = "malformed L4 quote"
)

// NetToRingDataplane reads SCION packets from the overlay socket, routes them
4 changes: 2 additions & 2 deletions go/godispatcher/network/overlay_test.go
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@ func TestComputeDestination(t *testing.T) {
Description string
Packet *spkt.ScnPkt
ExpectedDst Destination
ExpectedErr string
ExpectedErr common.ErrMsg
}
var testCases = []*TestCase{
{
@@ -212,7 +212,7 @@ func TestComputeDestination(t *testing.T) {
for _, test := range testCases {
Convey(test.Description, func() {
destination, err := ComputeDestination(test.Packet)
xtest.SoMsgErrorStr("err", err, test.ExpectedErr)
xtest.SoMsgErrorStr("err", err, test.ExpectedErr.Error())
SoMsg("destination", destination, ShouldResemble, test.ExpectedDst)
})
}
2 changes: 1 addition & 1 deletion go/lib/healthpool/pool.go
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ import (

// ErrPoolClosed is the error returned when operations on a closed pool are
// executed.
const ErrPoolClosed = "Pool closed"
const ErrPoolClosed common.ErrMsg = "Pool closed"

// InfoSet is a set of infos.
type InfoSet map[Info]struct{}
48 changes: 24 additions & 24 deletions go/lib/hiddenpath/group.go
Original file line number Diff line number Diff line change
@@ -27,26 +27,26 @@ import (

// Parsing errors
const (
// InvalidGroupIdFormat indicates an invalid GroupId format
InvalidGroupIdFormat = "Invalid GroupId format"
// InvalidGroupIdSuffix indicates an invalid GroupId suffix
InvalidGroupIdSuffix = "Invalid GroupId suffix"
// ErrInvalidGroupIdFormat indicates an invalid GroupId format
ErrInvalidGroupIdFormat common.ErrMsg = "Invalid GroupId format"
// ErrInvalidGroupIdSuffix indicates an invalid GroupId suffix
ErrInvalidGroupIdSuffix common.ErrMsg = "Invalid GroupId suffix"
)

// Validation errors
const (
// MissingGroupId indicates a missing GroupId
MissingGroupId = "Missing GroupId"
// InvalidVersion indicates a missing version
InvalidVersion = "Invalid version"
// MissingOwner indicates a missing Owner
MissingOwner = "Missing Owner"
// OwnerMismatch indicates a mismatch between Owner and GroupId.OwnerAS
OwnerMismatch = "Owner mismatch"
// EmptyWriters indicatres an empty Writer section
EmptyWriters = "Writer section cannot be empty"
// EmptyWriters indicatres an empty Writer section
EmptyRegistries = "Registry section cannot be empty"
// ErrMissingGroupId indicates a missing GroupId
ErrMissingGroupId common.ErrMsg = "Missing GroupId"
// ErrInvalidVersion indicates a missing version
ErrInvalidVersion common.ErrMsg = "Invalid version"
// ErrMissingOwner indicates a missing Owner
ErrMissingOwner common.ErrMsg = "Missing Owner"
// ErrOwnerMismatch indicates a mismatch between Owner and GroupId.OwnerAS
ErrOwnerMismatch common.ErrMsg = "Owner mismatch"
// ErrEmptyWriters indicates an empty Writer section
ErrEmptyWriters common.ErrMsg = "Writer section cannot be empty"
// ErrEmptyRegistries indicates an empty Registires section
ErrEmptyRegistries common.ErrMsg = "Registry section cannot be empty"
)

type GroupId struct {
@@ -63,15 +63,15 @@ func (id *GroupId) UnmarshalText(data []byte) error {
v = strings.Replace(v, "_", ":", 2)
parts := strings.Split(v, "-")
if len(parts) != 2 {
return common.NewBasicError(InvalidGroupIdFormat, nil, "GroupId", v)
return common.NewBasicError(ErrInvalidGroupIdFormat, nil, "GroupId", v)
}
ownerAS, err := addr.ASFromString(parts[0])
if err != nil {
return err
}
suffix, err := strconv.ParseUint(parts[1], 16, 16)
if err != nil {
return common.NewBasicError(InvalidGroupIdSuffix, err, "Suffix", parts[1])
return common.NewBasicError(ErrInvalidGroupIdSuffix, err, "Suffix", parts[1])
}
id.OwnerAS = ownerAS
id.Suffix = uint16(suffix)
@@ -126,23 +126,23 @@ func (g *Group) UnmarshalJSON(data []byte) (err error) {
return err
}
if v.Id == (GroupId{}) {
return common.NewBasicError(MissingGroupId, nil)
return common.NewBasicError(ErrMissingGroupId, nil)
}
if v.Version == 0 {
return common.NewBasicError(InvalidVersion, nil)
return common.NewBasicError(ErrInvalidVersion, nil)
}
if v.Owner == (addr.IA{}) {
return common.NewBasicError(MissingOwner, nil)
return common.NewBasicError(ErrMissingOwner, nil)
}
if v.Owner.A != v.Id.OwnerAS {
return common.NewBasicError(OwnerMismatch, nil,
return common.NewBasicError(ErrOwnerMismatch, nil,
"OwnerAS", v.Owner.A, "GroupId.OwnerAS", v.Id.OwnerAS)
}
if len(v.Writers) == 0 {
return common.NewBasicError(EmptyWriters, nil)
return common.NewBasicError(ErrEmptyWriters, nil)
}
if len(v.Registries) == 0 {
return common.NewBasicError(EmptyRegistries, nil)
return common.NewBasicError(ErrEmptyRegistries, nil)
}
*g = Group(v)
return nil
24 changes: 12 additions & 12 deletions go/lib/infra/disp/disp.go
Original file line number Diff line number Diff line change
@@ -107,23 +107,23 @@ func New(conn net.PacketConn, adapter MessageAdapter, logger log.Logger) *Dispat
func (d *Dispatcher) Request(ctx context.Context, msg proto.Cerealizable,
address net.Addr) (proto.Cerealizable, error) {
if err := d.waitTable.addRequest(msg); err != nil {
return nil, common.NewBasicError(infra.StrInternalError, err, "op", "waitTable.AddRequest")
return nil, common.NewBasicError(infra.ErrInternal, err, "op", "waitTable.AddRequest")
}
// Delete request entry when we exit this context
defer d.waitTable.cancelRequest(msg)

b, err := d.adapter.MsgToRaw(msg)
if err != nil {
return nil, common.NewBasicError(infra.StrAdapterError, err, "op", "MsgToRaw")
return nil, common.NewBasicError(infra.ErrAdapter, err, "op", "MsgToRaw")
}
// FIXME(scrye): Writes rarely block on packet conns.
if _, err := d.conn.WriteTo(b, address); err != nil {
return nil, common.NewBasicError(infra.StrTransportError, err, "op", "WriteTo")
return nil, common.NewBasicError(infra.ErrTransport, err, "op", "WriteTo")
}

reply, err := d.waitTable.waitForReply(ctx, msg)
if err != nil {
return nil, common.NewBasicError(infra.StrInternalError, err,
return nil, common.NewBasicError(infra.ErrInternal, err,
"op", "waitTable.WaitForReply")
}
return reply, nil
@@ -135,10 +135,10 @@ func (d *Dispatcher) Request(ctx context.Context, msg proto.Cerealizable,
func (d *Dispatcher) Notify(ctx context.Context, msg proto.Cerealizable, address net.Addr) error {
b, err := d.adapter.MsgToRaw(msg)
if err != nil {
return common.NewBasicError(infra.StrAdapterError, err, "op", "MsgToRaw")
return common.NewBasicError(infra.ErrAdapter, err, "op", "MsgToRaw")
}
if _, err := d.conn.WriteTo(b, address); err != nil {
return common.NewBasicError(infra.StrTransportError, err, "op", "WriteTo")
return common.NewBasicError(infra.ErrTransport, err, "op", "WriteTo")
}
return nil
}
@@ -148,10 +148,10 @@ func (d *Dispatcher) NotifyUnreliable(ctx context.Context, msg proto.Cerealizabl
address net.Addr) error {
b, err := d.adapter.MsgToRaw(msg)
if err != nil {
return common.NewBasicError(infra.StrAdapterError, err, "op", "MsgToRaw")
return common.NewBasicError(infra.ErrAdapter, err, "op", "MsgToRaw")
}
if _, err := d.conn.WriteTo(b, address); err != nil {
return common.NewBasicError(infra.StrTransportError, err, "op", "WriteTo")
return common.NewBasicError(infra.ErrTransport, err, "op", "WriteTo")
}
return nil
}
@@ -166,7 +166,7 @@ func (d *Dispatcher) RecvFrom(ctx context.Context) (proto.Cerealizable, int, net
return nil, 0, nil, ctx.Err()
case <-d.closedChan:
// Some other goroutine closed the dispatcher
return nil, 0, nil, common.NewBasicError(infra.StrClosedError, nil)
return nil, 0, nil, common.NewBasicError(infra.ErrLayerClosed, nil)
}
}

@@ -202,22 +202,22 @@ func (d *Dispatcher) recvNext() bool {
return true
} else {
d.log.Warn("error", "err",
common.NewBasicError(infra.StrTransportError, err, "op", "RecvFrom"))
common.NewBasicError(infra.ErrTransport, err, "op", "RecvFrom"))
}
return false
}

msg, err := d.adapter.RawToMsg(b)
if err != nil {
d.log.Warn("error", "err",
common.NewBasicError(infra.StrAdapterError, err, "op", "RawToMsg"))
common.NewBasicError(infra.ErrAdapter, err, "op", "RawToMsg"))
return false
}

found, err := d.waitTable.reply(msg)
if err != nil {
d.log.Warn("error", "err",
common.NewBasicError(infra.StrInternalError, err, "op", "waitTable.Reply"))
common.NewBasicError(infra.ErrInternal, err, "op", "waitTable.Reply"))
return false
}
if found {
Loading
Oops, something went wrong.