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

pkg/private/serrors: act the constructors deprecations #4595

Merged
merged 16 commits into from
Aug 15, 2024
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
2 changes: 1 addition & 1 deletion acceptance/router_benchmark/brload/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ func openDevices(interfaceNames []string) (map[string]*afpacket.TPacket, error)
for _, intf := range interfaceNames {
handle, err := afpacket.NewTPacket(afpacket.OptInterface(intf), afpacket.OptFrameSize(4096))
if err != nil {
return nil, serrors.WrapStr("creating TPacket", err)
return nil, serrors.Wrap("creating TPacket", err)
}
handles[intf] = handle
}
Expand Down
6 changes: 3 additions & 3 deletions control/beacon/chain_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ func (v chainChecker) Verify(ctx context.Context, signedMsg *cryptopb.SignedMess

var keyID cppb.VerificationKeyID
if err := proto.Unmarshal(hdr.VerificationKeyID, &keyID); err != nil {
return nil, serrors.WrapStr("parsing verification key ID", err)
return nil, serrors.Wrap("parsing verification key ID", err)
}
if len(keyID.SubjectKeyId) == 0 {
return nil, serrors.WrapStr("subject key ID must be set", err)
return nil, serrors.Wrap("subject key ID must be set", err)
}
ia := addr.IA(keyID.IsdAs)
if ia.IsWildcard() {
Expand All @@ -87,7 +87,7 @@ func (v chainChecker) Verify(ctx context.Context, signedMsg *cryptopb.SignedMess
Validity: v.BoundValidity,
}
if err := v.checkChains(ctx, query); err != nil {
return nil, serrors.WrapStr("getting chains", err,
return nil, serrors.Wrap("getting chains", err,
"query.isd_as", query.IA,
"query.subject_key_id", fmt.Sprintf("%x", query.SubjectKeyID),
"query.validity", query.Validity.String(),
Expand Down
4 changes: 2 additions & 2 deletions control/beacon/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func (p *Policy) initDefaults(t PolicyType) {
func ParsePolicyYaml(b []byte, t PolicyType) (*Policy, error) {
p := &Policy{}
if err := yaml.UnmarshalStrict(b, p); err != nil {
return nil, serrors.WrapStr("Unable to parse policy", err)
return nil, serrors.Wrap("Unable to parse policy", err)
}
if p.Type != "" && p.Type != t {
return nil, serrors.New("specified policy type does not match",
Expand All @@ -231,7 +231,7 @@ func ParsePolicyYaml(b []byte, t PolicyType) (*Policy, error) {
func LoadPolicyFromYaml(path string, t PolicyType) (*Policy, error) {
b, err := os.ReadFile(path)
if err != nil {
return nil, serrors.WrapStr("Unable to read policy file", err, "path", path)
return nil, serrors.Wrap("Unable to read policy file", err, "path", path)
}
return ParsePolicyYaml(b, t)
}
Expand Down
12 changes: 6 additions & 6 deletions control/beaconing/extender.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ func (s *DefaultExtender) Extend(

signers, err := s.SignerGen.Generate(ctx)
if err != nil {
return serrors.WrapStr("getting signer", err)
return serrors.Wrap("getting signer", err)
}
now := time.Now()
signer, err := trust.LastExpiring(signers, cppki.Validity{
NotBefore: pseg.Info.Timestamp,
NotAfter: now,
})
if err != nil {
return serrors.WrapStr("selecting signer", err)
return serrors.Wrap("selecting signer", err)
}
// Make sure the hop expiration time is not longer than the signer expiration time.
expTime := s.MaxExpTime()
Expand All @@ -131,7 +131,7 @@ func (s *DefaultExtender) Extend(
var err error
expTime, err = path.ExpTimeFromDuration(signerExp.Sub(ts))
if err != nil {
return serrors.WrapStr(
return serrors.Wrap(
"calculating expiry time from signer expiration time", err,
"signer_expiration", signerExp,
)
Expand All @@ -142,7 +142,7 @@ func (s *DefaultExtender) Extend(
hopBeta := extractBeta(pseg)
hopEntry, epicHopMac, err := s.createHopEntry(ingress, egress, expTime, ts, hopBeta)
if err != nil {
return serrors.WrapStr("creating hop entry", err)
return serrors.Wrap("creating hop entry", err)
}

// The peer hop fields chain to the main hop field, just like any child hop field.
Expand Down Expand Up @@ -234,7 +234,7 @@ func (s *DefaultExtender) createHopEntry(

remoteInMTU, err := s.remoteMTU(ingress)
if err != nil {
return seg.HopEntry{}, nil, serrors.WrapStr("checking remote ingress interface (mtu)", err,
return seg.HopEntry{}, nil, serrors.Wrap("checking remote ingress interface (mtu)", err,
"interfaces", ingress)
}
hopF, epicMac := s.createHopF(ingress, egress, expTime, ts, beta)
Expand All @@ -254,7 +254,7 @@ func (s *DefaultExtender) createPeerEntry(ingress, egress uint16, expTime uint8,

remoteInIA, remoteInIfID, remoteInMTU, err := s.remoteInfo(ingress)
if err != nil {
return seg.PeerEntry{}, nil, serrors.WrapStr("checking remote ingress interface", err,
return seg.PeerEntry{}, nil, serrors.Wrap("checking remote ingress interface", err,
"ingress_interface", ingress)
}
hopF, epicMac := s.createHopF(ingress, egress, expTime, ts, beta)
Expand Down
2 changes: 1 addition & 1 deletion control/beaconing/grpc/beacon_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (f *BeaconSenderFactory) NewSender(
}
conn, err := f.Dialer.Dial(ctx, addr)
if err != nil {
return nil, serrors.WrapStr("dialing gRPC conn", err)
return nil, serrors.Wrap("dialing gRPC conn", err)
}
return &BeaconSender{
Conn: conn,
Expand Down
4 changes: 2 additions & 2 deletions control/beaconing/grpc/creation_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (s SegmentCreationServer) Beacon(ctx context.Context,
if err := s.Handler.HandleBeacon(ctx, b, peer); err != nil {
logger.Debug("Failed to handle beacon", "peer", peer, "err", err)
// TODO(roosd): return better error with status code.
return nil, serrors.WrapStr("handling beacon", err)
return nil, serrors.Wrap("handling beacon", err)
}
return &cppb.BeaconResponse{}, nil

Expand All @@ -91,7 +91,7 @@ func extractIngressIfID(path snet.DataplanePath) (uint16, error) {
}
hf, err := rawScionPath.GetCurrentHopField()
if err != nil {
return 0, serrors.WrapStr("getting current hop field", err)
return 0, serrors.Wrap("getting current hop field", err)
}
return hf.ConsIngress, nil
}
4 changes: 2 additions & 2 deletions control/beaconing/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ func (h Handler) HandleBeacon(ctx context.Context, b beacon.Beacon, peer *snet.U
if err := h.verifySegment(ctx, b.Segment, peer); err != nil {
logger.Info("Beacon verification failed", "err", err)
h.updateMetric(span, labels.WithResult(prom.ErrVerify), err)
return serrors.WrapStr("verifying beacon", err)
return serrors.Wrap("verifying beacon", err)
}
stat, err := h.Inserter.InsertBeacon(ctx, b)
if err != nil {
logger.Debug("Failed to insert beacon", "err", err)
h.updateMetric(span, labels.WithResult(prom.ErrDB), err)
return serrors.WrapStr("inserting beacon", err)
return serrors.Wrap("inserting beacon", err)

}
labels = labels.WithResult(resultValue(stat.Inserted, stat.Updated, stat.Filtered))
Expand Down
15 changes: 8 additions & 7 deletions control/beaconing/originator.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (o *beaconOriginator) originateBeacon(ctx context.Context) error {
beacon, err := o.createBeacon(ctx)
if err != nil {
o.incrementMetrics(labels.WithResult("err_create"))
return serrors.WrapStr("creating beacon", err, "egress_interface", o.intf.TopoInfo().ID)
return serrors.Wrap("creating beacon", err, "egress_interface", o.intf.TopoInfo().ID)
}

senderStart := time.Now()
Expand All @@ -178,17 +178,18 @@ func (o *beaconOriginator) originateBeacon(ctx context.Context) error {
)
if err != nil {
o.incrementMetrics(labels.WithResult(prom.ErrNetwork))
return serrors.WrapStr("getting beacon sender", err,
return serrors.Wrap("getting beacon sender", err,
"waited_for", time.Since(senderStart).String())

}
defer sender.Close()

sendStart := time.Now()
if err := sender.Send(ctx, beacon); err != nil {
o.incrementMetrics(labels.WithResult(prom.ErrNetwork))
return serrors.WrapStr("sending beacon", err,
"waited_for", time.Since(sendStart).String(),
)
return serrors.Wrap("sending beacon", err,
"waited_for", time.Since(sendStart).String())

}
o.onSuccess(o.intf)
o.incrementMetrics(labels.WithResult(prom.Success))
Expand All @@ -202,11 +203,11 @@ func (o *beaconOriginator) createBeacon(ctx context.Context) (*seg.PathSegment,
}
beacon, err := seg.CreateSegment(o.timestamp, uint16(segID.Uint64()))
if err != nil {
return nil, serrors.WrapStr("creating segment", err)
return nil, serrors.Wrap("creating segment", err)
}

if err := o.Extender.Extend(ctx, beacon, 0, o.intf.TopoInfo().ID, nil); err != nil {
return nil, serrors.WrapStr("extending segment", err)
return nil, serrors.Wrap("extending segment", err)
}
return beacon, nil
}
Expand Down
8 changes: 4 additions & 4 deletions control/beaconing/propagator.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (p *Propagator) beaconsPerInterface(

allBeacons, err := p.Provider.BeaconsToPropagate(ctx)
if err != nil {
return nil, serrors.WrapStr("fetching beacons to propagate", err)
return nil, serrors.Wrap("fetching beacons to propagate", err)
}
var beacons []beacon.Beacon
for _, b := range allBeacons {
Expand Down Expand Up @@ -273,9 +273,9 @@ func (p *propagator) Propagate(ctx context.Context) error {
for _, b := range p.beacons {
p.incMetric(b.Segment.FirstIA(), b.InIfID, egress, prom.ErrNetwork)
}
return serrors.WrapStr("getting beacon sender", err,
"waited_for", time.Since(senderStart).String(),
)
return serrors.Wrap("getting beacon sender", err,
"waited_for", time.Since(senderStart).String())

}
defer sender.Close()

Expand Down
6 changes: 4 additions & 2 deletions control/beaconing/staticinfo_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,15 @@ type StaticInfoCfg struct {
func ParseStaticInfoCfg(file string) (*StaticInfoCfg, error) {
raw, err := os.ReadFile(file)
if err != nil {
return nil, serrors.WrapStr("failed to read static info config: ",
return nil, serrors.Wrap("failed to read static info config: ",
err, "file", file)

}
var cfg StaticInfoCfg
if err := json.Unmarshal(raw, &cfg); err != nil {
return nil, serrors.WrapStr("failed to parse static info config: ",
return nil, serrors.Wrap("failed to parse static info config: ",
err, "file ", file)

}
cfg.clean()
return &cfg, nil
Expand Down
32 changes: 16 additions & 16 deletions control/cmd/control/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func realMain(ctx context.Context) error {
Metrics: metrics.TopoLoader,
})
if err != nil {
return serrors.WrapStr("creating topology loader", err)
return serrors.Wrap("creating topology loader", err)
}
g, errCtx := errgroup.WithContext(ctx)
g.Go(func() error {
Expand All @@ -143,15 +143,15 @@ func realMain(ctx context.Context) error {

closer, err := cs.InitTracer(globalCfg.Tracing, globalCfg.General.ID)
if err != nil {
return serrors.WrapStr("initializing tracer", err)
return serrors.Wrap("initializing tracer", err)
}
defer closer.Close()

revCache := storage.NewRevocationStorage()
defer revCache.Close()
pathDB, err := storage.NewPathStorage(globalCfg.PathDB)
if err != nil {
return serrors.WrapStr("initializing path storage", err)
return serrors.Wrap("initializing path storage", err)
}
pathDB = pathstoragemetrics.WrapDB(pathDB, pathstoragemetrics.Config{
Driver: string(storage.BackendSqlite),
Expand All @@ -166,7 +166,7 @@ func realMain(ctx context.Context) error {

trustDB, err := storage.NewTrustStorage(globalCfg.TrustDB)
if err != nil {
return serrors.WrapStr("initializing trust storage", err)
return serrors.Wrap("initializing trust storage", err)
}
defer trustDB.Close()
fileWrites := libmetrics.NewPromCounter(metrics.TrustTRCFileWritesTotal)
Expand Down Expand Up @@ -224,11 +224,11 @@ func realMain(ctx context.Context) error {
}
quicStack, err := nc.QUICStack()
if err != nil {
return serrors.WrapStr("initializing QUIC stack", err)
return serrors.Wrap("initializing QUIC stack", err)
}
tcpStack, err := nc.TCPStack()
if err != nil {
return serrors.WrapStr("initializing TCP stack", err)
return serrors.Wrap("initializing TCP stack", err)
}
dialer := &libgrpc.QUICDialer{
Rewriter: &onehop.AddressRewriter{
Expand All @@ -240,7 +240,7 @@ func realMain(ctx context.Context) error {

beaconDB, err := storage.NewBeaconStorage(globalCfg.BeaconDB, topo.IA())
if err != nil {
return serrors.WrapStr("initializing beacon storage", err)
return serrors.Wrap("initializing beacon storage", err)
}
defer beaconDB.Close()
beaconDB = beaconstoragemetrics.WrapDB(beaconDB, beaconstoragemetrics.Config{
Expand All @@ -261,7 +261,7 @@ func realMain(ctx context.Context) error {
},
)
if err != nil {
return serrors.WrapStr("initializing beacon store", err)
return serrors.Wrap("initializing beacon store", err)
}

trustengineCache := globalCfg.TrustEngine.Cache.New()
Expand Down Expand Up @@ -594,11 +594,11 @@ func realMain(ctx context.Context) error {
log.Debug("DRKey debug info", "epoch duration", epochDuration.String())
masterKey, err := loadMasterSecret(globalCfg.General.ConfigDir)
if err != nil {
return serrors.WrapStr("loading master secret in DRKey", err)
return serrors.Wrap("loading master secret in DRKey", err)
}
svBackend, err := storage.NewDRKeySecretValueStorage(globalCfg.DRKey.SecretValueDB)
if err != nil {
return serrors.WrapStr("initializing Secret Value DB", err)
return serrors.Wrap("initializing Secret Value DB", err)
}
svCounter := libmetrics.NewPromCounter(metrics.DRKeySecretValueQueriesTotal)
svDB := &secret.Database{
Expand All @@ -615,7 +615,7 @@ func realMain(ctx context.Context) error {
defer svDB.Close()
level1Backend, err := storage.NewDRKeyLevel1Storage(globalCfg.DRKey.Level1DB)
if err != nil {
return serrors.WrapStr("initializing DRKey DB", err)
return serrors.Wrap("initializing DRKey DB", err)
}
lvl1Counter := libmetrics.NewPromCounter(metrics.DRKeyLevel1QueriesTotal)
level1DB := &level1.Database{
Expand Down Expand Up @@ -670,15 +670,15 @@ func realMain(ctx context.Context) error {
g.Go(func() error {
defer log.HandlePanic()
if err := quicServer.Serve(quicStack.Listener); err != nil {
return serrors.WrapStr("serving gRPC/QUIC API", err)
return serrors.Wrap("serving gRPC/QUIC API", err)
}
return nil
})
cleanup.Add(func() error { quicServer.GracefulStop(); return nil })
g.Go(func() error {
defer log.HandlePanic()
if err := tcpServer.Serve(tcpStack); err != nil {
return serrors.WrapStr("serving gRPC/TCP API", err)
return serrors.Wrap("serving gRPC/TCP API", err)
}
return nil
})
Expand Down Expand Up @@ -720,7 +720,7 @@ func realMain(ctx context.Context) error {
g.Go(func() error {
defer log.HandlePanic()
if err := s.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
return serrors.WrapStr("serving service management API", err)
return serrors.Wrap("serving service management API", err)
}
return nil
})
Expand Down Expand Up @@ -810,7 +810,7 @@ func realMain(ctx context.Context) error {
EPIC: globalCfg.BS.EPIC,
})
if err != nil {
return serrors.WrapStr("starting periodic tasks", err)
return serrors.Wrap("starting periodic tasks", err)
}
defer tasks.Kill()
log.Info("Started periodic tasks")
Expand Down Expand Up @@ -1018,7 +1018,7 @@ func updateCAHealthMetrics(caHealthGauge libmetrics.Gauge, caStatus api.CAHealth
func loadMasterSecret(dir string) (keyconf.Master, error) {
masterKey, err := keyconf.LoadMaster(filepath.Join(dir, "keys"))
if err != nil {
return keyconf.Master{}, serrors.WrapStr("error getting master secret", err)
return keyconf.Master{}, serrors.Wrap("error getting master secret", err)
}
return masterKey, nil
}
2 changes: 1 addition & 1 deletion control/cmd/control/sample.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func newSamplePolicy(pather command.Pather) *cobra.Command {
var sample beacon.Policy
sample.InitDefaults()
if err := yaml.NewEncoder(os.Stdout).Encode(sample); err != nil {
return serrors.WrapStr("producing sample policy", err)
return serrors.Wrap("producing sample policy", err)
}
return nil
},
Expand Down
2 changes: 1 addition & 1 deletion control/drkey/arc.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type Level1ARC struct {
func NewLevel1ARC(size int) (*Level1ARC, error) {
cache, err := arc.NewARC[Level1PrefetchInfo, struct{}](size)
if err != nil {
return nil, serrors.WrapStr("creating Level1ARC cache", err)
return nil, serrors.Wrap("creating Level1ARC cache", err)
}
return &Level1ARC{
cache: cache,
Expand Down
Loading
Loading