peer_protocol/ut-holepunch/err-code.go | 6 +++++- peer_protocol/ut-holepunch/err-code_test.go | 10 ++++++++++ diff --git a/peer_protocol/ut-holepunch/err-code.go b/peer_protocol/ut-holepunch/err-code.go index 42b1db1adf3f31d8abbb707918d3de20d92e9c2a..7cc61db736fd474f2d3dd731e372079a3e6201ac 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 @@ return "the target peer does not support the holepunch extension" 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 0000000000000000000000000000000000000000..4553810920444f4f011d8bbdbc822ad1090888e4 --- /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() +}