diff --git a/adapters/outbound/http.go b/adapters/outbound/http.go index 77b835b6..9dc4cf49 100644 --- a/adapters/outbound/http.go +++ b/adapters/outbound/http.go @@ -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 { diff --git a/adapters/outbound/shadowsocks.go b/adapters/outbound/shadowsocks.go index 22d160ba..091f6f37 100644 --- a/adapters/outbound/shadowsocks.go +++ b/adapters/outbound/shadowsocks.go @@ -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" { diff --git a/adapters/outbound/snell.go b/adapters/outbound/snell.go index 6b95aace..ecc0a685 100644 --- a/adapters/outbound/snell.go +++ b/adapters/outbound/snell.go @@ -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" { diff --git a/adapters/outbound/socks5.go b/adapters/outbound/socks5.go index 9355cff1..6551df17 100644 --- a/adapters/outbound/socks5.go +++ b/adapters/outbound/socks5.go @@ -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", "")