Skip to content

Commit

Permalink
fix: 完善错误信息链传递
Browse files Browse the repository at this point in the history
  • Loading branch information
Redmomn committed Nov 16, 2024
1 parent 05b8689 commit c2b3cc8
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ func (c *QQClient) FastLogin() error {
}
err = c.register()
if err != nil {
return fmt.Errorf("failed to register session: %v", err)
return fmt.Errorf("failed to register session: %w", err)

}
return nil
Expand Down
8 changes: 4 additions & 4 deletions client/highway.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ func (c *QQClient) ensureHighwayServers() error {
}
payload, err := c.sendUniPacketAndWait("HttpConn.0x6ff_501", packet)
if err != nil {
return fmt.Errorf("get highway server: %v", err)
return fmt.Errorf("get highway server: %w", err)
}
resp, err := highway2.ParseHighWayURLReq(payload)
if err != nil {
return fmt.Errorf("parse highway server: %v", err)
return fmt.Errorf("parse highway server: %w", err)
}
c.highwaySession.SigSession = resp.HttpConn.SigSession
c.highwaySession.SessionKey = resp.HttpConn.SessionKey
Expand Down Expand Up @@ -103,12 +103,12 @@ func (c *QQClient) highwayUploadBlock(trans *hw.Transaction, server string, offs
trans.Build(&c.highwaySession, offset, uint32(blksz), blkmd5), blk, server, isEnd,
)
if err != nil {
return fmt.Errorf("send highway packet: %v", err)
return fmt.Errorf("send highway packet: %w", err)
}
defer payload.Close()
resphead, respbody, err := parseHighwayPacket(payload)
if err != nil {
return fmt.Errorf("parse highway packet: %v", err)
return fmt.Errorf("parse highway packet: %w", err)
}
c.debug("Highway Block Result: %d | %d | %x | %v",
resphead.ErrorCode, resphead.MsgSegHead.RetCode.Unwrap(), resphead.BytesRspExtendInfo, respbody)
Expand Down
5 changes: 3 additions & 2 deletions client/internal/highway/bdh.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package highway

import (
"crypto/md5"
"fmt"
"io"
"strconv"
"sync"
Expand Down Expand Up @@ -111,7 +112,7 @@ func (s *Session) uploadSingle(trans *Transaction) ([]byte, error) {
return nil, errors.Wrap(err, "highway upload error")
}
if rspHead.ErrorCode != 0 {
return nil, errors.Errorf("upload failed: %d", rspHead.ErrorCode)
return nil, fmt.Errorf("upload failed: %d", rspHead.ErrorCode)
}
if rspHead.BytesRspExtendInfo != nil {
rspExt = rspHead.BytesRspExtendInfo
Expand Down Expand Up @@ -208,7 +209,7 @@ func (s *Session) Upload(trans *Transaction) ([]byte, error) {
return errors.Wrap(err, "highway upload error")
}
if rspHead.ErrorCode != 0 {
return errors.Errorf("upload failed: %d", rspHead.ErrorCode)
return fmt.Errorf("upload failed: %d", rspHead.ErrorCode)
}
if last && rspHead.BytesRspExtendInfo != nil {
rspExt = rspHead.BytesRspExtendInfo
Expand Down
2 changes: 1 addition & 1 deletion client/internal/highway/highway.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func readResponse(r *binary.NetworkReader) (*highway.RespDataHighwayHead, error)
hl, _ := r.ReadInt32()
a2, _ := r.ReadInt32()
if hl > highwayMaxResponseSize || a2 > highwayMaxResponseSize {
return nil, errors.Errorf("highway response invild. head size: %v body size: %v", hl, a2)
return nil, fmt.Errorf("highway response invild. head size: %v body size: %v", hl, a2)
}
head, _ := r.ReadBytes(int(hl))
_, _ = r.ReadBytes(int(a2)) // skip payload
Expand Down
4 changes: 2 additions & 2 deletions client/internal/network/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ func (t *Transport) readSSOFrame(resp *Response, payload []byte) error {
case -10003:
err = ErrAuthenticationFailed
default:
err = errors.Errorf("return code unsuccessful: %d", retCode)
err = fmt.Errorf("return code unsuccessful: %d", retCode)
}
if err != nil {
return errors.Wrap(err, resp.Message)
return fmt.Errorf("%w: %s", errors.WithStack(err), resp.Message)
}
resp.CommandName = head.ReadStringWithLength("u32", true)
if resp.CommandName == "Heartbeat.Alive" {
Expand Down
6 changes: 3 additions & 3 deletions client/ntlogin.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func parseNtloginResponse(response []byte, sig *auth.SigInfo) (LoginResponse, er
if err != nil {
return LoginResponse{
Success: false,
}, fmt.Errorf("proto decode failed: %s", err)
}, fmt.Errorf("proto decode failed: %w", err)
}

var base login.SsoNTLoginBase
Expand All @@ -123,14 +123,14 @@ func parseNtloginResponse(response []byte, sig *auth.SigInfo) (LoginResponse, er
if err != nil {
return LoginResponse{
Success: false,
}, fmt.Errorf("proto decode failed: %s", err)
}, fmt.Errorf("proto decode failed: %w", err)
}
var body login.SsoNTLoginResponse
err = proto.Unmarshal(base.Body, &body)
if err != nil {
return LoginResponse{
Success: false,
}, fmt.Errorf("proto decode failed: %s", err)
}, fmt.Errorf("proto decode failed: %w", err)
}

if body.Credentials != nil {
Expand Down
2 changes: 1 addition & 1 deletion client/oicq.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (c *QQClient) decodeLoginResponse(buf []byte, sig *auth.SigInfo) (LoginResp
var resp pb.Tlv543
err := proto.Unmarshal(tlv[0x543], &resp)
if err != nil {
err = fmt.Errorf("parsing login response error: %s", err)
err = fmt.Errorf("parsing login response error: %w", err)
c.errorln(err)
return LoginResponse{
Success: false,
Expand Down
2 changes: 1 addition & 1 deletion client/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -1331,7 +1331,7 @@ func (c *QQClient) DeleteUnidirectionalFriend(uin uint32) error {
return errors.Wrap(err, "unmarshal json error")
}
if webRsp.ErrorCode != 0 {
return errors.Errorf("web sso request error: %v", webRsp.ErrorCode)
return fmt.Errorf("web sso request error: %v", webRsp.ErrorCode)
}
return nil
}
Expand Down
3 changes: 2 additions & 1 deletion client/packets/oidb/image_ocr.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package oidb

import (
"fmt"
"strings"

"github.com/LagrangeDev/LagrangeGo/client/packets/pb/service/oidb"
Expand Down Expand Up @@ -55,7 +56,7 @@ func ParseImageOcrResp(data []byte) (*OcrResponse, error) {
return nil, errors.New(rsp.Wording)
}
if rsp.RetCode != 0 {
return nil, errors.Errorf("server error, code: %v msg: %v", rsp.RetCode, rsp.ErrMsg)
return nil, fmt.Errorf("server error, code: %v msg: %v", rsp.RetCode, rsp.ErrMsg)
}
texts := make([]*TextDetection, 0, len(rsp.OcrRspBody.TextDetections))
for _, text := range rsp.OcrRspBody.TextDetections {
Expand Down

0 comments on commit c2b3cc8

Please sign in to comment.