Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: cleanup error handling code #1500

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bench/bench_reader/bench_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package main

import (
"bufio"
"errors"
"flag"
"fmt"
"log"
"net"
"runtime"
"strings"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -96,7 +96,7 @@ func subWorker(td time.Duration, workers int, tcpAddr string, topic string, chan
for {
resp, err := nsq.ReadResponse(rw)
if err != nil {
if strings.Contains(err.Error(), "use of closed network connection") {
if errors.Is(err, net.ErrClosed) {
break
}
panic(err.Error())
Expand Down
4 changes: 2 additions & 2 deletions internal/http_api/http_server.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package http_api

import (
"errors"
"fmt"
"log"
"net"
"net/http"
"strings"

"github.com/nsqio/nsq/internal/lg"
)
Expand All @@ -28,7 +28,7 @@ func Serve(listener net.Listener, handler http.Handler, proto string, logf lg.Ap
}
err := server.Serve(listener)
// theres no direct way to detect this error because it is not exposed
if err != nil && !strings.Contains(err.Error(), "use of closed network connection") {
if err != nil && !errors.Is(err, net.ErrClosed) {
return fmt.Errorf("http.Serve() error - %s", err)
}

Expand Down
4 changes: 2 additions & 2 deletions internal/protocol/tcp_server.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package protocol

import (
"errors"
"fmt"
"net"
"runtime"
"strings"
"sync"

"github.com/nsqio/nsq/internal/lg"
Expand All @@ -30,7 +30,7 @@ func TCPServer(listener net.Listener, handler TCPHandler, logf lg.AppLogFunc) er
continue
}
// theres no direct way to detect this error because it is not exposed
if !strings.Contains(err.Error(), "use of closed network connection") {
if !errors.Is(err, net.ErrClosed) {
return fmt.Errorf("listener.Accept() error - %s", err)
}
break
Expand Down
Loading