Bläddra i källkod

refine error message

Darien Raymond 8 år sedan
förälder
incheckning
d627638412

+ 1 - 2
proxy/http/server.go

@@ -94,8 +94,7 @@ func (s *Server) Process(ctx context.Context, network v2net.Network, conn intern
 	}
 	dest, err := parseHost(host, defaultPort)
 	if err != nil {
-		log.Warning("HTTP: Malformed proxy host (", host, "): ", err)
-		return err
+		return errors.Base(err).Message("HTTP: Malformed proxy host: ", host).RequireUserAction()
 	}
 	log.Access(conn.RemoteAddr(), request.URL, log.AccessAccepted, "")
 

+ 1 - 2
proxy/shadowsocks/client.go

@@ -81,8 +81,7 @@ func (v *Client) Process(ctx context.Context, outboundRay ray.OutboundRay, diale
 	user := server.PickUser()
 	rawAccount, err := user.GetTypedAccount()
 	if err != nil {
-		log.Warning("Shadowsocks|Client: Failed to get a valid user account: ", err)
-		return err
+		return errors.Base(err).Message("Shadowsocks|Client: Failed to get a valid user account.").RequireUserAction()
 	}
 	account := rawAccount.(*ShadowsocksAccount)
 	request.User = user

+ 3 - 7
proxy/socks/client.go

@@ -5,7 +5,6 @@ import (
 	"runtime"
 	"time"
 
-	"v2ray.com/core/app/log"
 	"v2ray.com/core/common"
 	"v2ray.com/core/common/buf"
 	"v2ray.com/core/common/errors"
@@ -79,8 +78,7 @@ func (c *Client) Process(ctx context.Context, ray ray.OutboundRay, dialer proxy.
 
 	udpRequest, err := ClientHandshake(request, conn, conn)
 	if err != nil {
-		log.Warning("Socks|Client: Failed to establish connection to server: ", err)
-		return err
+		return errors.Base(err).RequireUserAction().Message("Socks|Client: Failed to establish connection to server.")
 	}
 
 	ctx, cancel := context.WithCancel(ctx)
@@ -99,8 +97,7 @@ func (c *Client) Process(ctx context.Context, ray ray.OutboundRay, dialer proxy.
 	} else if request.Command == protocol.RequestCommandUDP {
 		udpConn, err := dialer.Dial(ctx, udpRequest.Destination())
 		if err != nil {
-			log.Info("Socks|Client: Failed to create UDP connection: ", err)
-			return err
+			return errors.Base(err).Message("Socks|Client: Failed to create UDP connection.")
 		}
 		defer udpConn.Close()
 		requestFunc = func() error {
@@ -116,8 +113,7 @@ func (c *Client) Process(ctx context.Context, ray ray.OutboundRay, dialer proxy.
 	requestDone := signal.ExecuteAsync(requestFunc)
 	responseDone := signal.ExecuteAsync(responseFunc)
 	if err := signal.ErrorOrFinish2(ctx, requestDone, responseDone); err != nil {
-		log.Info("Socks|Client: Connection ends with ", err)
-		return err
+		return errors.Base(err).Message("Socks|Client: Connection ends.")
 	}
 
 	runtime.KeepAlive(timer)

+ 1 - 2
proxy/vmess/outbound/outbound.go

@@ -86,8 +86,7 @@ func (v *Handler) Process(ctx context.Context, outboundRay ray.OutboundRay, dial
 
 	rawAccount, err := request.User.GetTypedAccount()
 	if err != nil {
-		log.Warning("VMess|Outbound: Failed to get user account: ", err)
-		return err
+		return errors.Base(err).RequireUserAction().Message("VMess|Outbound: Failed to get user account.")
 	}
 	account := rawAccount.(*vmess.InternalAccount)
 	request.Security = account.Security

+ 3 - 4
transport/internet/udp/hub.go

@@ -7,6 +7,7 @@ import (
 	"v2ray.com/core/app/log"
 	"v2ray.com/core/common/buf"
 	"v2ray.com/core/common/dice"
+	"v2ray.com/core/common/errors"
 	v2net "v2ray.com/core/common/net"
 	"v2ray.com/core/transport/internet/internal"
 )
@@ -96,13 +97,11 @@ func ListenUDP(address v2net.Address, port v2net.Port, option ListenOption) (*Hu
 	if option.ReceiveOriginalDest {
 		fd, err := internal.GetSysFd(udpConn)
 		if err != nil {
-			log.Warning("UDP|Listener: Failed to get fd: ", err)
-			return nil, err
+			return nil, errors.Base(err).Message("UDP|Listener: Failed to get fd.")
 		}
 		err = SetOriginalDestOptions(fd)
 		if err != nil {
-			log.Warning("UDP|Listener: Failed to set socket options: ", err)
-			return nil, err
+			return nil, errors.Base(err).Message("UDP|Listener: Failed to set socket options.")
 		}
 	}
 	ctx, cancel := context.WithCancel(context.Background())