From 745d2c298b6ef253b84066927f4b114f5393848a Mon Sep 17 00:00:00 2001 From: jinronga <1460595002@qq.com> Date: Wed, 9 Jul 2025 23:21:21 +0800 Subject: [PATCH] refactor(manager/scheduler): optimize IP formatting error handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Optimized error handling when IP formatting fails in the manager and scheduler modules - Replaced errors.New with fmt.Errorf to improve readability of error messages - Extracted IP address string into a separate variable to enhance code maintainability Signed-off-by: jinronga <1460595002@qq.com> Update manager.go Update scheduler.go Update manager.go refactor(scheduler): 更新 GRPC 监听器的 IP 配置 - 将 GRPC监听 IP 改为全局监听 IP - 优化了 IP格式化错误的错误消息 --- manager/manager.go | 3 +-- scheduler/scheduler.go | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/manager/manager.go b/manager/manager.go index 999307b3f58..d1a37314aad 100644 --- a/manager/manager.go +++ b/manager/manager.go @@ -19,7 +19,6 @@ package manager import ( "context" "embed" - "errors" "fmt" "io/fs" "net" @@ -318,7 +317,7 @@ func (s *Server) Serve() error { // Generate GRPC listener. ip, ok := ip.FormatIP(s.config.Server.GRPC.ListenIP.String()) if !ok { - return errors.New("format ip failed") + return fmt.Errorf("format ip failed: %s", ip) } listener, err := net.Listen("tcp", fmt.Sprintf("%s:%d", ip, s.config.Server.GRPC.Port.Start)) diff --git a/scheduler/scheduler.go b/scheduler/scheduler.go index 9d347e2bfda..dcd743997af 100644 --- a/scheduler/scheduler.go +++ b/scheduler/scheduler.go @@ -18,7 +18,6 @@ package scheduler import ( "context" - "errors" "fmt" "net" "net/http" @@ -269,7 +268,7 @@ func (s *Server) Serve() error { // Generate GRPC listener. ip, ok := ip.FormatIP(s.config.Server.ListenIP.String()) if !ok { - return errors.New("format ip failed") + return fmt.Errorf("format ip failed: %s", ip) } listener, err := net.Listen("tcp", fmt.Sprintf("%s:%d", ip, s.config.Server.Port))