mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-10-09 18:44:04 -04:00
refactor error messages
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package dokodemo
|
||||
|
||||
//go:generate go run $GOPATH/src/v2ray.com/core/tools/generrorgen/main.go -pkg dokodemo -path Proxy,Dokodemo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"runtime"
|
||||
@@ -10,7 +12,6 @@ import (
|
||||
"v2ray.com/core/app/log"
|
||||
"v2ray.com/core/common"
|
||||
"v2ray.com/core/common/buf"
|
||||
"v2ray.com/core/common/errors"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/signal"
|
||||
"v2ray.com/core/proxy"
|
||||
@@ -26,10 +27,10 @@ type DokodemoDoor struct {
|
||||
func New(ctx context.Context, config *Config) (*DokodemoDoor, error) {
|
||||
space := app.SpaceFromContext(ctx)
|
||||
if space == nil {
|
||||
return nil, errors.New("Dokodemo: No space in context.")
|
||||
return nil, newError("Dokodemo: No space in context.")
|
||||
}
|
||||
if config.NetworkList == nil || config.NetworkList.Size() == 0 {
|
||||
return nil, errors.New("DokodemoDoor: No network specified.")
|
||||
return nil, newError("DokodemoDoor: No network specified.")
|
||||
}
|
||||
d := &DokodemoDoor{
|
||||
config: config,
|
||||
@@ -44,7 +45,7 @@ func (d *DokodemoDoor) Network() net.NetworkList {
|
||||
}
|
||||
|
||||
func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn internet.Connection, dispatcher dispatcher.Interface) error {
|
||||
log.Trace(errors.New("Dokodemo: processing connection from: ", conn.RemoteAddr()).AtDebug())
|
||||
log.Trace(newError("Dokodemo: processing connection from: ", conn.RemoteAddr()).AtDebug())
|
||||
dest := net.Destination{
|
||||
Network: network,
|
||||
Address: d.address,
|
||||
@@ -56,7 +57,7 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn in
|
||||
}
|
||||
}
|
||||
if !dest.IsValid() || dest.Address == nil {
|
||||
return errors.New("unable to get destination").Path("Proxy", "Dokodemo")
|
||||
return newError("unable to get destination")
|
||||
}
|
||||
|
||||
timeout := time.Second * time.Duration(d.config.Timeout)
|
||||
@@ -76,7 +77,7 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn in
|
||||
chunkReader := buf.NewReader(conn)
|
||||
|
||||
if err := buf.PipeUntilEOF(timer, chunkReader, inboundRay.InboundInput()); err != nil {
|
||||
return errors.New("failed to transport request").Base(err).Path("Proxy", "Dokodemo")
|
||||
return newError("failed to transport request").Base(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -86,7 +87,7 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn in
|
||||
v2writer := buf.NewWriter(conn)
|
||||
|
||||
if err := buf.PipeUntilEOF(timer, inboundRay.InboundOutput(), v2writer); err != nil {
|
||||
return errors.New("failed to transport response").Base(err).Path("Proxy", "Dokodemo")
|
||||
return newError("failed to transport response").Base(err)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
@@ -94,7 +95,7 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn in
|
||||
if err := signal.ErrorOrFinish2(ctx, requestDone, responseDone); err != nil {
|
||||
inboundRay.InboundInput().CloseError()
|
||||
inboundRay.InboundOutput().CloseError()
|
||||
return errors.New("connection ends").Base(err).Path("Proxy", "Dokodemo")
|
||||
return newError("connection ends").Base(err)
|
||||
}
|
||||
|
||||
runtime.KeepAlive(timer)
|
||||
|
Reference in New Issue
Block a user