Chore: throw more detail dial error

This commit is contained in:
Dreamacro 2019-12-05 17:51:21 +08:00
parent ad53b42a68
commit b8267a69f6
4 changed files with 13 additions and 13 deletions

View File

@ -45,7 +45,7 @@ func (h *Http) DialContext(ctx context.Context, metadata *C.Metadata) (C.Conn, e
}
if err != nil {
return nil, fmt.Errorf("%s connect error", h.addr)
return nil, fmt.Errorf("%s connect error: %w", h.addr, err)
}
tcpKeepAlive(c)
if err := h.shakeHand(metadata, c); err != nil {

View File

@ -61,7 +61,7 @@ type v2rayObfsOption struct {
func (ss *ShadowSocks) DialContext(ctx context.Context, metadata *C.Metadata) (C.Conn, error) {
c, err := dialContext(ctx, "tcp", ss.server)
if err != nil {
return nil, fmt.Errorf("%s connect error: %s", ss.server, err.Error())
return nil, fmt.Errorf("%s connect error: %w", ss.server, err)
}
tcpKeepAlive(c)
switch ss.obfsMode {
@ -74,7 +74,7 @@ func (ss *ShadowSocks) DialContext(ctx context.Context, metadata *C.Metadata) (C
var err error
c, err = v2rayObfs.NewV2rayObfs(c, ss.v2rayOption)
if err != nil {
return nil, fmt.Errorf("%s connect error: %s", ss.server, err.Error())
return nil, fmt.Errorf("%s connect error: %w", ss.server, err)
}
}
c = ss.cipher.StreamConn(c)
@ -95,7 +95,7 @@ func (ss *ShadowSocks) DialUDP(metadata *C.Metadata) (C.PacketConn, net.Addr, er
targetAddr := socks5.ParseAddr(metadata.RemoteAddress())
if targetAddr == nil {
return nil, nil, fmt.Errorf("parse address error: %v:%v", metadata.String(), metadata.DstPort)
return nil, nil, fmt.Errorf("parse address %s error: %s", metadata.String(), metadata.DstPort)
}
pc = ss.cipher.PacketConn(pc)
@ -114,7 +114,7 @@ func NewShadowSocks(option ShadowSocksOption) (*ShadowSocks, error) {
password := option.Password
ciph, err := core.PickCipher(cipher, nil, password)
if err != nil {
return nil, fmt.Errorf("ss %s initialize error: %s", server, err.Error())
return nil, fmt.Errorf("ss %s initialize error: %w", server, err)
}
var v2rayOption *v2rayObfs.Option
@ -136,7 +136,7 @@ func NewShadowSocks(option ShadowSocksOption) (*ShadowSocks, error) {
if option.Plugin == "obfs" {
opts := simpleObfsOption{Host: "bing.com"}
if err := decoder.Decode(option.PluginOpts, &opts); err != nil {
return nil, fmt.Errorf("ss %s initialize obfs error: %s", server, err.Error())
return nil, fmt.Errorf("ss %s initialize obfs error: %w", server, err)
}
if opts.Mode != "tls" && opts.Mode != "http" {
@ -147,7 +147,7 @@ func NewShadowSocks(option ShadowSocksOption) (*ShadowSocks, error) {
} else if option.Plugin == "v2ray-plugin" {
opts := v2rayObfsOption{Host: "bing.com", Mux: true}
if err := decoder.Decode(option.PluginOpts, &opts); err != nil {
return nil, fmt.Errorf("ss %s initialize v2ray-plugin error: %s", server, err.Error())
return nil, fmt.Errorf("ss %s initialize v2ray-plugin error: %w", server, err)
}
if opts.Mode != "websocket" {

View File

@ -30,7 +30,7 @@ type SnellOption struct {
func (s *Snell) DialContext(ctx context.Context, metadata *C.Metadata) (C.Conn, error) {
c, err := dialContext(ctx, "tcp", s.server)
if err != nil {
return nil, fmt.Errorf("%s connect error: %s", s.server, err.Error())
return nil, fmt.Errorf("%s connect error: %w", s.server, err)
}
tcpKeepAlive(c)
switch s.obfsOption.Mode {
@ -53,7 +53,7 @@ func NewSnell(option SnellOption) (*Snell, error) {
decoder := structure.NewDecoder(structure.Option{TagName: "obfs", WeaklyTypedInput: true})
obfsOption := &simpleObfsOption{Host: "bing.com"}
if err := decoder.Decode(option.ObfsOpts, obfsOption); err != nil {
return nil, fmt.Errorf("snell %s initialize obfs error: %s", server, err.Error())
return nil, fmt.Errorf("snell %s initialize obfs error: %w", server, err)
}
if obfsOption.Mode != "tls" && obfsOption.Mode != "http" {

View File

@ -44,7 +44,7 @@ func (ss *Socks5) DialContext(ctx context.Context, metadata *C.Metadata) (C.Conn
}
if err != nil {
return nil, fmt.Errorf("%s connect error", ss.addr)
return nil, fmt.Errorf("%s connect error: %w", ss.addr, err)
}
tcpKeepAlive(c)
var user *socks5.User
@ -65,7 +65,7 @@ func (ss *Socks5) DialUDP(metadata *C.Metadata) (_ C.PacketConn, _ net.Addr, err
defer cancel()
c, err := dialContext(ctx, "tcp", ss.addr)
if err != nil {
err = fmt.Errorf("%s connect error", ss.addr)
err = fmt.Errorf("%s connect error: %w", ss.addr, err)
return
}
@ -92,7 +92,7 @@ func (ss *Socks5) DialUDP(metadata *C.Metadata) (_ C.PacketConn, _ net.Addr, err
bindAddr, err := socks5.ClientHandshake(c, serializesSocksAddr(metadata), socks5.CmdUDPAssociate, user)
if err != nil {
err = fmt.Errorf("%v client hanshake error", err)
err = fmt.Errorf("client hanshake error: %w", err)
return
}
@ -103,7 +103,7 @@ func (ss *Socks5) DialUDP(metadata *C.Metadata) (_ C.PacketConn, _ net.Addr, err
targetAddr := socks5.ParseAddr(metadata.RemoteAddress())
if targetAddr == nil {
return nil, nil, fmt.Errorf("parse address error: %v:%v", metadata.String(), metadata.DstPort)
return nil, nil, fmt.Errorf("parse address %s error: %s", metadata.String(), metadata.DstPort)
}
pc, err := net.ListenPacket("udp", "")