优化错误提示相关代码

This commit is contained in:
刘祥超
2023-08-11 15:26:59 +08:00
parent c098732e51
commit fe00446003
7 changed files with 27 additions and 23 deletions

View File

@@ -1,7 +1,7 @@
package firewallconfigs
import (
"errors"
"fmt"
"regexp"
"strings"
)
@@ -28,12 +28,12 @@ func (this *HTTPFirewallRule) Init() error {
case HTTPFirewallRuleOperatorMatch:
_, err := regexp.Compile(this.Value)
if err != nil {
return errors.New("regexp validate failed: " + err.Error() + ", expression: " + this.Value)
return fmt.Errorf("regexp validate failed: %w, expression: %s", err, this.Value)
}
case HTTPFirewallRuleOperatorNotMatch:
_, err := regexp.Compile(this.Value)
if err != nil {
return errors.New("regexp validate failed: " + err.Error() + ", expression: " + this.Value)
return fmt.Errorf("regexp validate failed: %w, expression: %s", err, this.Value)
}
}

View File

@@ -6,6 +6,7 @@ import (
"crypto/x509"
"encoding/pem"
"errors"
"fmt"
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
"github.com/iwind/TeaGo/lists"
@@ -112,7 +113,7 @@ func (this *SSLCertConfig) Init(ctx context.Context) error {
} else { // 证书+私钥
cert, err := tls.X509KeyPair(this.CertData, this.KeyData)
if err != nil {
return errors.New("load certificate '" + strconv.FormatInt(this.Id, 10) + "' failed:" + err.Error())
return fmt.Errorf("load certificate '%s' failed: %w", strconv.FormatInt(this.Id, 10), err)
}
for index, data := range cert.Certificate {