From 70d8507c4b0bca9b637e06fa7b710c5f30348aa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Fri, 11 Aug 2023 14:51:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=94=99=E8=AF=AF=E5=A4=84?= =?UTF-8?q?=E7=90=86=E7=9B=B8=E5=85=B3=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/caches/list_file_db.go | 2 +- internal/firewalls/nftables/installer.go | 6 +++--- internal/iplibrary/action_firewalld.go | 2 +- internal/iplibrary/action_iptables.go | 4 ++-- internal/iplibrary/action_script.go | 3 +-- internal/nodes/listener_manager.go | 4 ++-- internal/nodes/node.go | 2 +- internal/utils/clock/manager.go | 3 +-- internal/utils/service_linux.go | 3 ++- internal/waf/waf.go | 4 ++-- 10 files changed, 16 insertions(+), 17 deletions(-) diff --git a/internal/caches/list_file_db.go b/internal/caches/list_file_db.go index 0cf2d4d..dcc919a 100644 --- a/internal/caches/list_file_db.go +++ b/internal/caches/list_file_db.go @@ -540,7 +540,7 @@ func (this *FileListDB) WrapError(err error) error { if err == nil { return nil } - return errors.New(err.Error() + "(file: " + this.dbPath + ")") + return fmt.Errorf("%w (file: %s)", err, this.dbPath) } // 初始化 diff --git a/internal/firewalls/nftables/installer.go b/internal/firewalls/nftables/installer.go index c1aae6d..0f1e6a9 100644 --- a/internal/firewalls/nftables/installer.go +++ b/internal/firewalls/nftables/installer.go @@ -4,7 +4,7 @@ package nftables import ( - "errors" + "fmt" "github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs" teaconst "github.com/TeaOSLab/EdgeNode/internal/const" "github.com/TeaOSLab/EdgeNode/internal/events" @@ -85,7 +85,7 @@ func (this *Installer) Install() error { } // 检查是否已经存在 - if len(NftExePath()) > 0 { + if len(NftExePath()) > 0 { return nil } @@ -121,7 +121,7 @@ func (this *Installer) Install() error { cmd.WithStderr() err = cmd.Run() if err != nil { - return errors.New(err.Error() + ": " + cmd.Stderr()) + return fmt.Errorf("%w: %s", err, cmd.Stderr()) } remotelogs.Println("NFTABLES", "installed nftables with command '"+cmd.String()+"' successfully") diff --git a/internal/iplibrary/action_firewalld.go b/internal/iplibrary/action_firewalld.go index 6dd5156..192bb28 100644 --- a/internal/iplibrary/action_firewalld.go +++ b/internal/iplibrary/action_firewalld.go @@ -147,7 +147,7 @@ func (this *FirewalldAction) runActionSingleIP(action string, listType IPListTyp cmd.WithStderr() err = cmd.Run() if err != nil { - return errors.New(err.Error() + ", output: " + cmd.Stderr()) + return fmt.Errorf("%w, output: %s", err, cmd.Stderr()) } return nil } diff --git a/internal/iplibrary/action_iptables.go b/internal/iplibrary/action_iptables.go index 8c83309..a77954d 100644 --- a/internal/iplibrary/action_iptables.go +++ b/internal/iplibrary/action_iptables.go @@ -1,7 +1,7 @@ package iplibrary import ( - "errors" + "fmt" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs" "github.com/TeaOSLab/EdgeNode/internal/utils" @@ -128,7 +128,7 @@ func (this *IPTablesAction) runActionSingleIP(action string, listType IPListType if strings.Contains(output, "No chain/target/match") { err = nil } else { - return errors.New(err.Error() + ", output: " + output) + return fmt.Errorf("%w, output: %s", err, output) } } return nil diff --git a/internal/iplibrary/action_script.go b/internal/iplibrary/action_script.go index 731adb3..fce6513 100644 --- a/internal/iplibrary/action_script.go +++ b/internal/iplibrary/action_script.go @@ -1,7 +1,6 @@ package iplibrary import ( - "errors" "fmt" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs" @@ -62,7 +61,7 @@ func (this *ScriptAction) runAction(action string, listType IPListType, item *pb cmd.WithStderr() err := cmd.Run() if err != nil { - return errors.New(err.Error() + ", output: " + cmd.Stderr()) + return fmt.Errorf("%w, output: %s", err, cmd.Stderr()) } return nil } diff --git a/internal/nodes/listener_manager.go b/internal/nodes/listener_manager.go index 6c158aa..c754041 100644 --- a/internal/nodes/listener_manager.go +++ b/internal/nodes/listener_manager.go @@ -1,7 +1,7 @@ package nodes import ( - "errors" + "fmt" "github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" teaconst "github.com/TeaOSLab/EdgeNode/internal/const" @@ -141,7 +141,7 @@ func (this *ListenerManager) Start(nodeConfig *nodeconfigs.NodeConfig) error { var port = addr[portIndex+1:] var processName = this.findProcessNameWithPort(group.IsUDP(), port) if len(processName) > 0 { - err = errors.New(err.Error() + " (the process using port: '" + processName + "')") + err = fmt.Errorf("%w (the process using port: '%s')", err, processName) } } } diff --git a/internal/nodes/node.go b/internal/nodes/node.go index 845fc1c..9203b28 100644 --- a/internal/nodes/node.go +++ b/internal/nodes/node.go @@ -324,7 +324,7 @@ func (this *Node) syncConfig(taskVersion int64) error { if os.IsNotExist(clusterErr) { return errors.New("can not find config file 'configs/api.yaml'") } - return errors.New("check cluster config failed: " + clusterErr.Error()) + return fmt.Errorf("check cluster config failed: %w", clusterErr) } } else { return err diff --git a/internal/utils/clock/manager.go b/internal/utils/clock/manager.go index 4ef4dd5..43f5fc1 100644 --- a/internal/utils/clock/manager.go +++ b/internal/utils/clock/manager.go @@ -4,7 +4,6 @@ package clock import ( "encoding/binary" - "errors" "fmt" "github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs" teaconst "github.com/TeaOSLab/EdgeNode/internal/const" @@ -136,7 +135,7 @@ func (this *ClockManager) syncNtpdate(ntpdate string, server string) error { cmd.WithStderr() err := cmd.Run() if err != nil { - return errors.New(err.Error() + ": " + cmd.Stderr()) + return fmt.Errorf("%w: %s", err, cmd.Stderr()) } return nil diff --git a/internal/utils/service_linux.go b/internal/utils/service_linux.go index 7cb1a56..9e8156c 100644 --- a/internal/utils/service_linux.go +++ b/internal/utils/service_linux.go @@ -5,6 +5,7 @@ package utils import ( "errors" + "fmt" teaconst "github.com/TeaOSLab/EdgeNode/internal/const" executils "github.com/TeaOSLab/EdgeNode/internal/utils/exec" "github.com/iwind/TeaGo/Tea" @@ -156,7 +157,7 @@ WantedBy=multi-user.target` cmd.WithStderr() err = cmd.Run() if err != nil { - return errors.New(err.Error() + ": " + cmd.Stderr()) + return fmt.Errorf("%w: %s", err, cmd.Stderr()) } return nil } diff --git a/internal/waf/waf.go b/internal/waf/waf.go index 609cfe7..4559170 100644 --- a/internal/waf/waf.go +++ b/internal/waf/waf.go @@ -2,13 +2,13 @@ package waf import ( "errors" + "fmt" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs" teaconst "github.com/TeaOSLab/EdgeNode/internal/const" "github.com/TeaOSLab/EdgeNode/internal/waf/checkpoints" "github.com/TeaOSLab/EdgeNode/internal/waf/requests" "github.com/iwind/TeaGo/Tea" "github.com/iwind/TeaGo/files" - "github.com/iwind/TeaGo/types" "gopkg.in/yaml.v3" "net/http" "os" @@ -96,7 +96,7 @@ func (this *WAF) Init() (resultErrors []error) { err := group.Init(this) if err != nil { // 这里我们不阻止其他规则正常加入 - resultErrors = append(resultErrors, errors.New("init group '"+types.String(group.Id)+"' failed: "+err.Error())) + resultErrors = append(resultErrors, fmt.Errorf("init group '%d' failed: %w", group.Id, err)) } } }