]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Fix panic logging unknown holepunch error code
authorMatt Joiner <anacrolix@gmail.com>
Sun, 21 May 2023 09:29:35 +0000 (19:29 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Sun, 21 May 2023 09:29:35 +0000 (19:29 +1000)
peer_protocol/ut-holepunch/err-code.go
peer_protocol/ut-holepunch/err-code_test.go [new file with mode: 0644]

index 42b1db1adf3f31d8abbb707918d3de20d92e9c2a..7cc61db736fd474f2d3dd731e372079a3e6201ac 100644 (file)
@@ -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 (file)
index 0000000..4553810
--- /dev/null
@@ -0,0 +1,10 @@
+package utHolepunch
+
+import (
+       "math/rand"
+       "testing"
+)
+
+func TestUnknownErrCodeError(t *testing.T) {
+       ErrCode(rand.Uint32()).Error()
+}