From: Matt Joiner Date: Sun, 21 May 2023 09:29:35 +0000 (+1000) Subject: Fix panic logging unknown holepunch error code X-Git-Url: http://www.git.stargrave.org/?p=btrtrc.git;a=commitdiff_plain;h=60db1104397f6e4eb581e6fc2dec428702d2455e Fix panic logging unknown holepunch error code --- diff --git a/peer_protocol/ut-holepunch/err-code.go b/peer_protocol/ut-holepunch/err-code.go index 42b1db1a..7cc61db7 100644 --- a/peer_protocol/ut-holepunch/err-code.go +++ b/peer_protocol/ut-holepunch/err-code.go @@ -1,5 +1,9 @@ package utHolepunch +import ( + "fmt" +) + type ErrCode uint32 var _ error = ErrCode(0) @@ -22,6 +26,6 @@ func (ec ErrCode) Error() string { case NoSelf: return "the target endpoint belongs to the relaying peer" default: - panic(ec) + return fmt.Sprintf("error code %d", ec) } } diff --git a/peer_protocol/ut-holepunch/err-code_test.go b/peer_protocol/ut-holepunch/err-code_test.go new file mode 100644 index 00000000..45538109 --- /dev/null +++ b/peer_protocol/ut-holepunch/err-code_test.go @@ -0,0 +1,10 @@ +package utHolepunch + +import ( + "math/rand" + "testing" +) + +func TestUnknownErrCodeError(t *testing.T) { + ErrCode(rand.Uint32()).Error() +}