Skip to content

Commit b5980eb

Browse files
committed
fix: Include actual value in PathSegType.String()
refactor: Simplify code, use Stringer method
1 parent 5fb5db8 commit b5980eb

File tree

9 files changed

+18
-17
lines changed

9 files changed

+18
-17
lines changed

control/segreq/authoritative.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func (a AuthoritativeLookup) LookupSegments(
4949
case seg.TypeCore:
5050
return getCoreSegments(ctx, a.PathDB, a.LocalIA, dst)
5151
default:
52-
panic(fmt.Errorf("unexpected segType: %d (%s)", segType, segType.String()))
52+
panic(fmt.Errorf("unexpected segType: %s", segType.String()))
5353
}
5454
}
5555

control/segreq/expander.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ func (e *WildcardExpander) ExpandSrcWildcard(ctx context.Context,
5757
default:
5858
// no wildcard source for up requests
5959
panic(fmt.Errorf(
60-
"unexpected wildcard for up segment request, should not have passed validation: %d",
61-
req.SegType,
60+
"unexpected wildcard for up segment request, should not have passed validation: %s",
61+
req.SegType.String(),
6262
))
6363
}
6464
}

control/segreq/fetcher.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ func (p *dstProvider) Dst(ctx context.Context, req segfetcher.Request) (net.Addr
199199
default:
200200
panic(fmt.Errorf(
201201
"unsupported segment type for request forwarding: "+
202-
"up segment should have been resolved locally: %d (%s)",
203-
req.SegType, req.SegType.String(),
202+
"up segment should have been resolved locally: %s",
203+
req.SegType.String(),
204204
))
205205
}
206206
addr := &snet.SVCAddr{

daemon/cmd/daemon/main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ func realMain(ctx context.Context) error {
128128
SvcResolver: func(dst addr.SVC) []resolver.Address {
129129
if base := dst.Base(); base != addr.SvcCS {
130130
panic(fmt.Errorf(
131-
"unsupported address type, possible implementation error: %d (%s)",
132-
base, base.String(),
131+
"unsupported address type, possible implementation error: %s",
132+
base.String(),
133133
))
134134
}
135135
targets := []resolver.Address{}

pkg/addr/host.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func (h Host) Type() HostAddrType {
9999
// Panics if h.Type() is not HostTypeIP.
100100
func (h Host) IP() netip.Addr {
101101
if h.t != HostTypeIP {
102-
panic(fmt.Errorf("IP called on non-IP address: %d (%s)", h.t, h.t.String()))
102+
panic(fmt.Errorf("IP called on non-IP address: %s", h.t.String()))
103103
}
104104
return h.ip
105105
}
@@ -108,7 +108,7 @@ func (h Host) IP() netip.Addr {
108108
// Panics if h.Type() is not HostTypeSVC.
109109
func (h Host) SVC() SVC {
110110
if h.t != HostTypeSVC {
111-
panic(fmt.Errorf("SVC called on non-SVC address: %d (%s)", h.t, h.t.String()))
111+
panic(fmt.Errorf("SVC called on non-SVC address: %s", h.t.String()))
112112
}
113113
return h.svc
114114
}
@@ -122,7 +122,7 @@ func (h Host) String() string {
122122
case HostTypeSVC:
123123
return h.svc.String()
124124
default:
125-
panic(fmt.Errorf("unsupported host type: %d (%s)", t, t.String()))
125+
panic(fmt.Errorf("unsupported host type: %s", t.String()))
126126
}
127127
}
128128

pkg/private/ctrl/path_mgmt/proto/defs.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ suitable place eventually.
2121
*/
2222
package proto
2323

24+
import "fmt"
25+
2426
type LinkType uint16
2527

2628
// Values of LinkType.
@@ -92,9 +94,8 @@ func (c PathSegType) String() string {
9294
return "down"
9395
case PathSegType_core:
9496
return "core"
95-
9697
default:
97-
return ""
98+
return fmt.Sprintf("unknown(%d)", c)
9899
}
99100
}
100101

pkg/slayers/path/path.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ type Metadata struct {
7575
func RegisterPath(pathMeta Metadata) {
7676
pm := registeredPaths[pathMeta.Type]
7777
if pm.inUse {
78-
panic(fmt.Errorf("path type already registered: %d (%s)",
79-
pathMeta.Type, pathMeta.Type.String()))
78+
panic(fmt.Errorf("path type already registered: %s",
79+
pathMeta.Type.String()))
8080
}
8181
registeredPaths[pathMeta.Type].inUse = true
8282
registeredPaths[pathMeta.Type].Metadata = pathMeta

private/path/combinator/graph.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ func validNextSeg(currSeg, nextSeg *inputSegment) bool {
592592
case proto.PathSegType_down:
593593
return false
594594
default:
595-
panic(fmt.Sprintf("Invalid segment type: %d", currSeg.Type))
595+
panic(fmt.Sprintf("Invalid segment type: %s", currSeg.Type.String()))
596596
}
597597
}
598598

router/dataplane.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1855,8 +1855,8 @@ func (d *dataPlane) resolveLocalDst(
18551855
}
18561856
return d.addEndhostPort(resolvedDst, lastLayer, dstIP)
18571857
default:
1858-
panic(fmt.Errorf("unexpected address type returned from DstAddr: %d (%s)",
1859-
dstType, dstType.String()))
1858+
panic(fmt.Errorf("unexpected address type returned from DstAddr: %s",
1859+
dstType.String()))
18601860
}
18611861
}
18621862

0 commit comments

Comments
 (0)