Skip to content

Commit c320dd5

Browse files
committed
Simplify error handling
1 parent b895c3e commit c320dd5

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

traverse.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ func (r *Reader) NetworksWithin(prefix netip.Prefix, options ...NetworksOption)
8686
prefix, err := netIP.Prefix(bit)
8787
if err != nil {
8888
yield(Result{
89-
err: fmt.Errorf("prefixing %s with %d", netIP, bit),
89+
ip: ip,
90+
prefixLen: uint8(bit),
91+
err: fmt.Errorf("prefixing %s with %d", netIP, bit),
9092
})
9193
}
9294

@@ -132,18 +134,19 @@ func (r *Reader) NetworksWithin(prefix netip.Prefix, options ...NetworksOption)
132134
ipRight := node.ip.As16()
133135
if len(ipRight) <= int(node.bit>>3) {
134136
displayAddr := node.ip
135-
displayBits := node.bit
136137
if isInIPv4Subtree(node.ip) {
137138
displayAddr = v6ToV4(displayAddr)
138-
displayBits -= 96
139139
}
140140

141-
yield(Result{
141+
res := Result{
142142
ip: displayAddr,
143143
prefixLen: uint8(node.bit),
144-
err: newInvalidDatabaseError(
145-
"invalid search tree at %s/%d", displayAddr, displayBits),
146-
})
144+
}
145+
res.err = newInvalidDatabaseError(
146+
"invalid search tree at %s", res.Network())
147+
148+
yield(res)
149+
147150
return
148151
}
149152
ipRight[node.bit>>3] |= 1 << (7 - (node.bit % 8))

0 commit comments

Comments
 (0)