mirror of
https://github.com/v2fly/v2ray-core.git
synced 2026-07-13 12:40:12 -04:00
refactor error messages
This commit is contained in:
@@ -7,7 +7,6 @@ import (
|
||||
"v2ray.com/core/app/proxyman"
|
||||
"v2ray.com/core/app/proxyman/mux"
|
||||
"v2ray.com/core/common/dice"
|
||||
"v2ray.com/core/common/errors"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/proxy"
|
||||
)
|
||||
@@ -37,7 +36,7 @@ func NewAlwaysOnInboundHandler(ctx context.Context, tag string, receiverConfig *
|
||||
}
|
||||
for port := pr.From; port <= pr.To; port++ {
|
||||
if nl.HasNetwork(net.Network_TCP) {
|
||||
log.Trace(errors.New("creating tcp worker on ", address, ":", port).AtDebug().Path("App", "Proxyman", "Inbound", "AlwaysOnInboundHandler"))
|
||||
log.Trace(newError("creating tcp worker on ", address, ":", port).AtDebug())
|
||||
worker := &tcpWorker{
|
||||
address: address,
|
||||
port: net.Port(port),
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"v2ray.com/core/app/proxyman"
|
||||
"v2ray.com/core/app/proxyman/mux"
|
||||
"v2ray.com/core/common/dice"
|
||||
"v2ray.com/core/common/errors"
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/proxy"
|
||||
)
|
||||
@@ -93,7 +92,7 @@ func (h *DynamicInboundHandler) refresh() error {
|
||||
port := h.allocatePort()
|
||||
p, err := proxy.CreateInboundHandler(ctx, h.proxyConfig)
|
||||
if err != nil {
|
||||
log.Trace(errors.New("failed to create proxy instance").Base(err).Path("App", "Proxyman", "Inbound", "DynamicInboundHandler").AtWarning())
|
||||
log.Trace(newError("failed to create proxy instance").Base(err).AtWarning())
|
||||
continue
|
||||
}
|
||||
nl := p.Network()
|
||||
@@ -108,7 +107,7 @@ func (h *DynamicInboundHandler) refresh() error {
|
||||
dispatcher: h.mux,
|
||||
}
|
||||
if err := worker.Start(); err != nil {
|
||||
log.Trace(errors.New("failed to create TCP worker").Base(err).AtWarning().Path("App", "Proxyman", "Inbound", "DynamicInboundHandler"))
|
||||
log.Trace(newError("failed to create TCP worker").Base(err).AtWarning())
|
||||
continue
|
||||
}
|
||||
workers = append(workers, worker)
|
||||
@@ -124,7 +123,7 @@ func (h *DynamicInboundHandler) refresh() error {
|
||||
dispatcher: h.mux,
|
||||
}
|
||||
if err := worker.Start(); err != nil {
|
||||
log.Trace(errors.New("failed to create UDP worker").Base(err).AtWarning().Path("App", "Proxyman", "Inbound", "DynamicInboundHandler"))
|
||||
log.Trace(newError("failed to create UDP worker").Base(err).AtWarning())
|
||||
continue
|
||||
}
|
||||
workers = append(workers, worker)
|
||||
|
||||
7
app/proxyman/inbound/errors.generated.go
Normal file
7
app/proxyman/inbound/errors.generated.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package inbound
|
||||
|
||||
import "v2ray.com/core/common/errors"
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).Path("App", "Proxyman", "Inbound")
|
||||
}
|
||||
@@ -1,11 +1,12 @@
|
||||
package inbound
|
||||
|
||||
//go:generate go run $GOPATH/src/v2ray.com/core/tools/generrorgen/main.go -pkg inbound -path App,Proxyman,Inbound
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"v2ray.com/core/app/proxyman"
|
||||
"v2ray.com/core/common"
|
||||
"v2ray.com/core/common/errors"
|
||||
)
|
||||
|
||||
type DefaultInboundHandlerManager struct {
|
||||
@@ -26,7 +27,7 @@ func (m *DefaultInboundHandlerManager) AddHandler(ctx context.Context, config *p
|
||||
}
|
||||
receiverSettings, ok := rawReceiverSettings.(*proxyman.ReceiverConfig)
|
||||
if !ok {
|
||||
return errors.New("not a ReceiverConfig").Path("App", "Proxyman", "Inbound", "DefaultInboundHandlerManager")
|
||||
return newError("not a ReceiverConfig")
|
||||
}
|
||||
proxySettings, err := config.ProxySettings.GetInstance()
|
||||
if err != nil {
|
||||
@@ -50,7 +51,7 @@ func (m *DefaultInboundHandlerManager) AddHandler(ctx context.Context, config *p
|
||||
}
|
||||
|
||||
if handler == nil {
|
||||
return errors.New("unknown allocation strategy: ", receiverSettings.AllocationStrategy.Type).Path("App", "Proxyman", "Inbound", "DefaultInboundHandlerManager")
|
||||
return newError("unknown allocation strategy: ", receiverSettings.AllocationStrategy.Type)
|
||||
}
|
||||
|
||||
m.handlers = append(m.handlers, handler)
|
||||
@@ -63,7 +64,7 @@ func (m *DefaultInboundHandlerManager) AddHandler(ctx context.Context, config *p
|
||||
func (m *DefaultInboundHandlerManager) GetHandler(ctx context.Context, tag string) (proxyman.InboundHandler, error) {
|
||||
handler, found := m.taggedHandlers[tag]
|
||||
if !found {
|
||||
return nil, errors.New("handler not found: ", tag).Path("App", "Proxyman", "Inbound", "DefaultInboundHandlerManager")
|
||||
return nil, newError("handler not found: ", tag)
|
||||
}
|
||||
return handler, nil
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
"v2ray.com/core/app/dispatcher"
|
||||
"v2ray.com/core/app/log"
|
||||
"v2ray.com/core/common/buf"
|
||||
"v2ray.com/core/common/errors"
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/proxy"
|
||||
"v2ray.com/core/transport/internet"
|
||||
@@ -54,7 +53,7 @@ func (w *tcpWorker) callback(conn internet.Connection) {
|
||||
ctx = proxy.ContextWithInboundEntryPoint(ctx, v2net.TCPDestination(w.address, w.port))
|
||||
ctx = proxy.ContextWithSource(ctx, v2net.DestinationFromAddr(conn.RemoteAddr()))
|
||||
if err := w.proxy.Process(ctx, v2net.Network_TCP, conn, w.dispatcher); err != nil {
|
||||
log.Trace(errors.New("connection ends").Base(err).Path("App", "Proxyman", "Inbound", "TCPWorker"))
|
||||
log.Trace(newError("connection ends").Base(err))
|
||||
}
|
||||
cancel()
|
||||
conn.Close()
|
||||
@@ -231,7 +230,7 @@ func (w *udpWorker) callback(b *buf.Buffer, source v2net.Destination, originalDe
|
||||
ctx = proxy.ContextWithSource(ctx, source)
|
||||
ctx = proxy.ContextWithInboundEntryPoint(ctx, v2net.UDPDestination(w.address, w.port))
|
||||
if err := w.proxy.Process(ctx, v2net.Network_UDP, conn, w.dispatcher); err != nil {
|
||||
log.Trace(errors.New("connection ends").Base(err).Path("App", "Proxymann", "Inbound", "UDPWorker"))
|
||||
log.Trace(newError("connection ends").Base(err))
|
||||
}
|
||||
w.removeConn(source)
|
||||
cancel()
|
||||
|
||||
Reference in New Issue
Block a user