Skip to content

Commit 0ccaa27

Browse files
committed
fix panic error check when internal adapter is unreachable.
1 parent d2539a2 commit 0ccaa27

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

data/internal.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package data
22

33
import (
4+
"errors"
45
"net"
56
"strings"
67
)
@@ -15,7 +16,12 @@ type InternalData struct {
1516
func (i *InternalData) GetInternalIP() {
1617

1718
conn, err := net.Dial("udp", "8.8.8.8:80")
18-
checkErr(err)
19+
20+
defer func() {
21+
if r := recover(); r != nil {
22+
checkErr(errors.Join(err, r.(error)))
23+
}
24+
}()
1925
defer conn.Close()
2026

2127
localAddr := conn.LocalAddr().(*net.UDPAddr)

data/internal_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func TestGetInternalIP(t *testing.T) {
1313

1414
// assert
1515
if result == "" {
16-
t.Errorf("Wrong internal IP address! Shoud be fromat like this XX.XX.XX.XX %s\n", result)
16+
t.Errorf("Wrong internal IP address! Shoud be format like this XX.XX.XX.XX %s\n", result)
1717
}
1818
}
1919

0 commit comments

Comments
 (0)