From 60db1104397f6e4eb581e6fc2dec428702d2455e Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Sun, 21 May 2023 19:29:35 +1000 Subject: [PATCH] Fix panic logging unknown holepunch error code --- peer_protocol/ut-holepunch/err-code.go | 6 +++++- peer_protocol/ut-holepunch/err-code_test.go | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 peer_protocol/ut-holepunch/err-code_test.go 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() +} -- 2.44.0