Skip to content

Commit f0363a7

Browse files
committed
Chore: Simplify some syscall error checks
This just replaces some type casts to check whether a few dial errors are a specific syscall with the stdlibs errors.As/errors.Is pals. Signed-off-by: Danny Canter <[email protected]>
1 parent a26c686 commit f0363a7

File tree

2 files changed

+10
-26
lines changed

2 files changed

+10
-26
lines changed

pkg/dialer/dialer_unix.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
package dialer
2020

2121
import (
22+
"errors"
2223
"fmt"
2324
"net"
24-
"os"
2525
"strings"
2626
"syscall"
2727
"time"
@@ -34,16 +34,7 @@ func DialAddress(address string) string {
3434
}
3535

3636
func isNoent(err error) bool {
37-
if err != nil {
38-
if nerr, ok := err.(*net.OpError); ok {
39-
if serr, ok := nerr.Err.(*os.SyscallError); ok {
40-
if serr.Err == syscall.ENOENT {
41-
return true
42-
}
43-
}
44-
}
45-
}
46-
return false
37+
return errors.Is(err, syscall.ENOENT)
4738
}
4839

4940
func dialer(address string, timeout time.Duration) (net.Conn, error) {

pkg/shim/util_unix.go

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"bufio"
2323
"context"
2424
"crypto/sha256"
25+
"errors"
2526
"fmt"
2627
"io"
2728
"math"
@@ -173,22 +174,14 @@ func RemoveSocket(address string) error {
173174
// SocketEaddrinuse returns true if the provided error is caused by the
174175
// EADDRINUSE error number
175176
func SocketEaddrinuse(err error) bool {
176-
netErr, ok := err.(*net.OpError)
177-
if !ok {
178-
return false
179-
}
180-
if netErr.Op != "listen" {
181-
return false
182-
}
183-
syscallErr, ok := netErr.Err.(*os.SyscallError)
184-
if !ok {
185-
return false
186-
}
187-
errno, ok := syscallErr.Err.(syscall.Errno)
188-
if !ok {
189-
return false
177+
var netErr *net.OpError
178+
if errors.As(err, &netErr) {
179+
if netErr.Op != "listen" {
180+
return false
181+
}
182+
return errors.Is(err, syscall.EADDRINUSE)
190183
}
191-
return errno == syscall.EADDRINUSE
184+
return false
192185
}
193186

194187
// CanConnect returns true if the socket provided at the address

0 commit comments

Comments
 (0)