优化错误处理,替换 errors.Wrap 为 fmt.Errorf
This commit is contained in:
@@ -2,6 +2,7 @@ package dispatcher
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"net"
|
||||
"proxy-server/pkg/utils"
|
||||
@@ -13,7 +14,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"errors"
|
||||
"github.com/soheilhy/cmux"
|
||||
)
|
||||
|
||||
@@ -48,7 +49,7 @@ func (s *Server) Run() error {
|
||||
|
||||
ls, err := net.Listen("tcp", ":"+port)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "dispatcher 监听失败")
|
||||
return fmt.Errorf("dispatcher 监听失败: %w", err)
|
||||
}
|
||||
defer utils.Close(ls)
|
||||
|
||||
@@ -83,7 +84,7 @@ func (s *Server) Run() error {
|
||||
defer close(errCh)
|
||||
err = m.Serve()
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "dispatcher serve error")
|
||||
err = fmt.Errorf("dispatcher serve error: %w", err)
|
||||
}
|
||||
errCh <- err
|
||||
}()
|
||||
@@ -110,7 +111,7 @@ func (s *Server) acceptHttp(ls net.Listener) error {
|
||||
if errors.As(err, &ne) && ne.Temporary() {
|
||||
continue
|
||||
}
|
||||
return errors.Wrap(err, "dispatcher http accept error")
|
||||
return fmt.Errorf("dispatcher http accept error: %w", err)
|
||||
}
|
||||
|
||||
metrics.TimerStart.Store(conn, time.Now())
|
||||
@@ -142,7 +143,7 @@ func (s *Server) acceptSocks(ls net.Listener) error {
|
||||
if errors.As(err, &ne) && ne.Temporary() {
|
||||
continue
|
||||
}
|
||||
return errors.Wrap(err, "dispatcher socks accept error")
|
||||
return fmt.Errorf("dispatcher socks accept error: %w", err)
|
||||
}
|
||||
|
||||
metrics.TimerStart.Store(conn, time.Now())
|
||||
|
||||
Reference in New Issue
Block a user