fix: wrap the error of group user and thrid

pull/2005/head
luhaoling 2 years ago
parent 532f6acb5d
commit 4a544faf26

@ -120,12 +120,12 @@ func (s *groupServer) NotificationUserInfoUpdate(ctx context.Context, req *pbgro
groupIDs = append(groupIDs, member.GroupID) groupIDs = append(groupIDs, member.GroupID)
} }
for _, groupID := range groupIDs { for _, groupID := range groupIDs {
if err := s.Notification.GroupMemberInfoSetNotification(ctx, groupID, req.UserID); err != nil { if err = s.Notification.GroupMemberInfoSetNotification(ctx, groupID, req.UserID); err != nil {
log.ZError(ctx, "NotificationUserInfoUpdate setGroupMemberInfo notification failed", err, "groupID", groupID) return nil, err
} }
} }
if err := s.db.DeleteGroupMemberHash(ctx, groupIDs); err != nil { if err = s.db.DeleteGroupMemberHash(ctx, groupIDs); err != nil {
log.ZError(ctx, "NotificationUserInfoUpdate DeleteGroupMemberHash", err, "groupID", groupIDs) return nil, err
} }
return &pbgroup.NotificationUserInfoUpdateResp{}, nil return &pbgroup.NotificationUserInfoUpdateResp{}, nil

@ -209,7 +209,7 @@ func (t *thirdServer) InitiateFormData(ctx context.Context, req *third.InitiateF
} }
uid, err := uuid.NewRandom() uid, err := uuid.NewRandom()
if err != nil { if err != nil {
return nil, err return nil, errs.Wrap(err, "uuid NewRandom failed")
} }
if key == "" { if key == "" {
date := time.Now().Format("20060102") date := time.Now().Format("20060102")
@ -224,7 +224,7 @@ func (t *thirdServer) InitiateFormData(ctx context.Context, req *third.InitiateF
} }
mateData, err := json.Marshal(&mate) mateData, err := json.Marshal(&mate)
if err != nil { if err != nil {
return nil, err return nil, errs.Wrap(err, "marshal failed")
} }
resp, err := t.s3dataBase.FormData(ctx, key, req.Size, req.ContentType, duration) resp, err := t.s3dataBase.FormData(ctx, key, req.Size, req.ContentType, duration)
if err != nil { if err != nil {

@ -17,6 +17,7 @@ package third
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/OpenIMSDK/tools/errs"
"net/url" "net/url"
"time" "time"
@ -54,9 +55,9 @@ func Start(config *config.GlobalConfig, client discoveryregistry.SvcDiscoveryReg
} }
apiURL := config.Object.ApiURL apiURL := config.Object.ApiURL
if apiURL == "" { if apiURL == "" {
return fmt.Errorf("api url is empty") return errs.Wrap(fmt.Errorf("api is empty"))
} }
if _, parseErr := url.Parse(config.Object.ApiURL); parseErr != nil { if _, err := url.Parse(config.Object.ApiURL); err != nil {
return err return err
} }
if apiURL[len(apiURL)-1] != '/' { if apiURL[len(apiURL)-1] != '/' {

@ -16,7 +16,7 @@ package user
import ( import (
"context" "context"
"errors" "fmt"
"math/rand" "math/rand"
"strings" "strings"
"time" "time"
@ -78,7 +78,7 @@ func Start(config *config.GlobalConfig, client registry.SvcDiscoveryRegistry, se
} }
users := make([]*tablerelation.UserModel, 0) users := make([]*tablerelation.UserModel, 0)
if len(config.IMAdmin.UserID) != len(config.IMAdmin.Nickname) { if len(config.IMAdmin.UserID) != len(config.IMAdmin.Nickname) {
return errors.New("len(s.config.AppNotificationAdmin.AppManagerUid) != len(s.config.AppNotificationAdmin.Nickname)") return errs.Wrap(fmt.Errorf("the count of ImAdmin.UserID is not equal to the count of ImAdmin.Nickname"))
} }
for k, v := range config.IMAdmin.UserID { for k, v := range config.IMAdmin.UserID {
users = append(users, &tablerelation.UserModel{UserID: v, Nickname: config.IMAdmin.Nickname[k], AppMangerLevel: constant.AppNotificationAdmin}) users = append(users, &tablerelation.UserModel{UserID: v, Nickname: config.IMAdmin.Nickname[k], AppMangerLevel: constant.AppNotificationAdmin})
@ -113,9 +113,6 @@ func (s *userServer) GetDesignateUsers(ctx context.Context, req *pbuser.GetDesig
return nil, err return nil, err
} }
resp.UsersInfo = convert.UsersDB2Pb(users) resp.UsersInfo = convert.UsersDB2Pb(users)
if err != nil {
return nil, err
}
return resp, nil return resp, nil
} }
@ -139,7 +136,7 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbuser.UpdateUserI
} }
if req.UserInfo.Nickname != "" || req.UserInfo.FaceURL != "" { if req.UserInfo.Nickname != "" || req.UserInfo.FaceURL != "" {
if err = s.groupRpcClient.NotificationUserInfoUpdate(ctx, req.UserInfo.UserID); err != nil { if err = s.groupRpcClient.NotificationUserInfoUpdate(ctx, req.UserInfo.UserID); err != nil {
log.ZError(ctx, "NotificationUserInfoUpdate", err) return nil, err
} }
} }
for _, friendID := range friends { for _, friendID := range friends {
@ -149,7 +146,7 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbuser.UpdateUserI
return nil, err return nil, err
} }
if err = s.groupRpcClient.NotificationUserInfoUpdate(ctx, req.UserInfo.UserID); err != nil { if err = s.groupRpcClient.NotificationUserInfoUpdate(ctx, req.UserInfo.UserID); err != nil {
log.ZError(ctx, "NotificationUserInfoUpdate", err, "userID", req.UserInfo.UserID) return nil, err
} }
return resp, nil return resp, nil
} }
@ -174,7 +171,7 @@ func (s *userServer) UpdateUserInfoEx(ctx context.Context, req *pbuser.UpdateUse
} }
if req.UserInfo.Nickname != nil || req.UserInfo.FaceURL != nil { if req.UserInfo.Nickname != nil || req.UserInfo.FaceURL != nil {
if err := s.groupRpcClient.NotificationUserInfoUpdate(ctx, req.UserInfo.UserID); err != nil { if err := s.groupRpcClient.NotificationUserInfoUpdate(ctx, req.UserInfo.UserID); err != nil {
log.ZError(ctx, "NotificationUserInfoUpdate", err) return nil, err
} }
} }
for _, friendID := range friends { for _, friendID := range friends {
@ -184,7 +181,7 @@ func (s *userServer) UpdateUserInfoEx(ctx context.Context, req *pbuser.UpdateUse
return nil, err return nil, err
} }
if err := s.groupRpcClient.NotificationUserInfoUpdate(ctx, req.UserInfo.UserID); err != nil { if err := s.groupRpcClient.NotificationUserInfoUpdate(ctx, req.UserInfo.UserID); err != nil {
log.ZError(ctx, "NotificationUserInfoUpdate", err, "userID", req.UserInfo.UserID) return nil, err
} }
return resp, nil return resp, nil
} }

@ -131,7 +131,7 @@ func getCache[T any](ctx context.Context, rcClient *rockscache.Client, key strin
v, err := rcClient.Fetch2(ctx, key, expire, func() (s string, err error) { v, err := rcClient.Fetch2(ctx, key, expire, func() (s string, err error) {
t, err = fn(ctx) t, err = fn(ctx)
if err != nil { if err != nil {
return "", errs.Wrap(err) return "", err
} }
bs, err := json.Marshal(t) bs, err := json.Marshal(t)
if err != nil { if err != nil {

@ -471,7 +471,7 @@ func (c *msgCache) ParallelSetMessageToCache(ctx context.Context, conversationID
err := wg.Wait() err := wg.Wait()
if err != nil { if err != nil {
return 0, err return 0, errs.Wrap(err, "wg.Wait failed")
} }
return len(msgs), nil return len(msgs), nil

@ -16,6 +16,7 @@ package mgo
import ( import (
"context" "context"
"github.com/OpenIMSDK/tools/errs"
"github.com/OpenIMSDK/tools/mgoutil" "github.com/OpenIMSDK/tools/mgoutil"
"github.com/openimsdk/open-im-server/v3/pkg/common/db/table/relation" "github.com/openimsdk/open-im-server/v3/pkg/common/db/table/relation"
@ -33,7 +34,7 @@ func NewS3Mongo(db *mongo.Database) (relation.ObjectInfoModelInterface, error) {
Options: options.Index().SetUnique(true), Options: options.Index().SetUnique(true),
}) })
if err != nil { if err != nil {
return nil, err return nil, errs.Wrap(err)
} }
return &S3Mongo{coll: coll}, nil return &S3Mongo{coll: coll}, nil
} }

@ -157,7 +157,7 @@ func (u *UserMgo) AddUserCommand(ctx context.Context, userID string, Type int32,
} }
_, err := collection.InsertOne(ctx, doc) _, err := collection.InsertOne(ctx, doc)
return err return errs.Wrap(err)
} }
func (u *UserMgo) DeleteUserCommand(ctx context.Context, userID string, Type int32, UUID string) error { func (u *UserMgo) DeleteUserCommand(ctx context.Context, userID string, Type int32, UUID string) error {
@ -170,7 +170,7 @@ func (u *UserMgo) DeleteUserCommand(ctx context.Context, userID string, Type int
// No records found to update // No records found to update
return errs.Wrap(errs.ErrRecordNotFound) return errs.Wrap(errs.ErrRecordNotFound)
} }
return err return errs.Wrap(err)
} }
func (u *UserMgo) UpdateUserCommand(ctx context.Context, userID string, Type int32, UUID string, val map[string]any) error { func (u *UserMgo) UpdateUserCommand(ctx context.Context, userID string, Type int32, UUID string, val map[string]any) error {
if len(val) == 0 { if len(val) == 0 {
@ -184,7 +184,7 @@ func (u *UserMgo) UpdateUserCommand(ctx context.Context, userID string, Type int
result, err := collection.UpdateOne(ctx, filter, update) result, err := collection.UpdateOne(ctx, filter, update)
if err != nil { if err != nil {
return err return errs.Wrap(err)
} }
if result.MatchedCount == 0 { if result.MatchedCount == 0 {
@ -233,7 +233,7 @@ func (u *UserMgo) GetUserCommand(ctx context.Context, userID string, Type int32)
} }
if err := cursor.Err(); err != nil { if err := cursor.Err(); err != nil {
return nil, err return nil, errs.Wrap(err)
} }
return commands, nil return commands, nil
@ -244,7 +244,7 @@ func (u *UserMgo) GetAllUserCommand(ctx context.Context, userID string) ([]*user
cursor, err := collection.Find(ctx, filter) cursor, err := collection.Find(ctx, filter)
if err != nil { if err != nil {
return nil, err return nil, errs.Wrap(err)
} }
defer cursor.Close(ctx) defer cursor.Close(ctx)
@ -261,7 +261,7 @@ func (u *UserMgo) GetAllUserCommand(ctx context.Context, userID string) ([]*user
} }
if err := cursor.Decode(&document); err != nil { if err := cursor.Decode(&document); err != nil {
return nil, err return nil, errs.Wrap(err)
} }
commandInfo := &user.AllCommandInfoResp{ commandInfo := &user.AllCommandInfoResp{
@ -276,7 +276,7 @@ func (u *UserMgo) GetAllUserCommand(ctx context.Context, userID string) ([]*user
} }
if err := cursor.Err(); err != nil { if err := cursor.Err(); err != nil {
return nil, err return nil, errs.Wrap(err)
} }
return commands, nil return commands, nil
} }

@ -102,12 +102,11 @@ func buildMongoURI(config *config.GlobalConfig) string {
maxPoolSize = fmt.Sprint(config.Mongo.MaxPoolSize) maxPoolSize = fmt.Sprint(config.Mongo.MaxPoolSize)
} }
uriFormat := "mongodb://%s/%s?maxPoolSize=%s"
if username != "" && password != "" { if username != "" && password != "" {
uriFormat = "mongodb://%s:%s@%s/%s?maxPoolSize=%s"
return fmt.Sprintf(uriFormat, username, password, address, database, maxPoolSize) return fmt.Sprintf("mongodb://%s:%s@%s/%s?maxPoolSize=%s", username, password, address, database, maxPoolSize)
} }
return fmt.Sprintf(uriFormat, address, database, maxPoolSize) return fmt.Sprintf("mongodb://%s/%s?maxPoolSize=%s", address, database, maxPoolSize)
} }
func shouldRetry(err error) bool { func shouldRetry(err error) bool {

@ -100,7 +100,7 @@ func (cd *ConnDirect) GetConns(ctx context.Context,
for _, port := range ports { for _, port := range ports {
conn, err := cd.dialServiceWithoutResolver(ctx, fmt.Sprintf(cd.config.Rpc.ListenIP+":%d", port), append(cd.additionalOpts, opts...)...) conn, err := cd.dialServiceWithoutResolver(ctx, fmt.Sprintf(cd.config.Rpc.ListenIP+":%d", port), append(cd.additionalOpts, opts...)...)
if err != nil { if err != nil {
fmt.Printf("connect to port %d failed,serviceName %s, IP %s\n", port, serviceName, cd.config.Rpc.ListenIP) return nil, errs.Wrap(fmt.Errorf("connect to port %d failed,serviceName %s, IP %s\n", port, serviceName, cd.config.Rpc.ListenIP))
} }
connections = append(connections, conn) connections = append(connections, conn)
} }
@ -166,7 +166,7 @@ func (cd *ConnDirect) dialServiceWithoutResolver(ctx context.Context, address st
conn, err := grpc.DialContext(ctx, address, options...) conn, err := grpc.DialContext(ctx, address, options...)
if err != nil { if err != nil {
return nil, err return nil, errs.Wrap(err)
} }
return conn, nil return conn, nil
} }

@ -19,6 +19,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/OpenIMSDK/tools/errs" "github.com/OpenIMSDK/tools/errs"
util "github.com/openimsdk/open-im-server/v3/pkg/util/genutil"
"github.com/OpenIMSDK/protocol/constant" "github.com/OpenIMSDK/protocol/constant"
"github.com/OpenIMSDK/protocol/msg" "github.com/OpenIMSDK/protocol/msg"
@ -135,7 +136,7 @@ type Message struct {
func NewMessage(discov discoveryregistry.SvcDiscoveryRegistry, config *config.GlobalConfig) *Message { func NewMessage(discov discoveryregistry.SvcDiscoveryRegistry, config *config.GlobalConfig) *Message {
conn, err := discov.GetConn(context.Background(), config.RpcRegisterName.OpenImMsgName) conn, err := discov.GetConn(context.Background(), config.RpcRegisterName.OpenImMsgName)
if err != nil { if err != nil {
panic(err) util.ExitWithError(err)
} }
client := msg.NewMsgClient(conn) client := msg.NewMsgClient(conn)
return &Message{discov: discov, conn: conn, Client: client, Config: config} return &Message{discov: discov, conn: conn, Client: client, Config: config}

@ -160,7 +160,7 @@ func NewTask[A interface{ TableName() string }, B any, C any](gormDB *gorm.DB, m
tableName := zero.TableName() tableName := zero.TableName()
coll, err := getColl(obj) coll, err := getColl(obj)
if err != nil { if err != nil {
return fmt.Errorf("get mongo collection %s failed, err: %w", tableName, err) return errs.Wrap(fmt.Errorf("get mongo collection %s failed, err: %w", tableName, err))
} }
var count int var count int
defer func() { defer func() {
@ -173,7 +173,7 @@ func NewTask[A interface{ TableName() string }, B any, C any](gormDB *gorm.DB, m
if mysqlErr, ok := err.(*mysql.MySQLError); ok && mysqlErr.Number == 1146 { if mysqlErr, ok := err.(*mysql.MySQLError); ok && mysqlErr.Number == 1146 {
return nil // table not exist return nil // table not exist
} }
return fmt.Errorf("find mysql table %s failed, err: %w", tableName, err) return errs.Wrap(fmt.Errorf("find mysql table %s failed, err: %w", tableName, err))
} }
if len(res) == 0 { if len(res) == 0 {
return nil return nil
@ -183,7 +183,7 @@ func NewTask[A interface{ TableName() string }, B any, C any](gormDB *gorm.DB, m
temp[i] = convert(res[i]) temp[i] = convert(res[i])
} }
if err := insertMany(coll, temp); err != nil { if err := insertMany(coll, temp); err != nil {
return fmt.Errorf("insert mongo table %s failed, err: %w", tableName, err) return errs.Wrap(fmt.Errorf("insert mongo table %s failed, err: %w", tableName, err))
} }
count += len(res) count += len(res)
if len(res) < batch { if len(res) < batch {
@ -196,7 +196,7 @@ func NewTask[A interface{ TableName() string }, B any, C any](gormDB *gorm.DB, m
func insertMany(coll *mongo.Collection, objs []any) error { func insertMany(coll *mongo.Collection, objs []any) error {
if _, err := coll.InsertMany(context.Background(), objs); err != nil { if _, err := coll.InsertMany(context.Background(), objs); err != nil {
if !mongo.IsDuplicateKeyError(err) { if !mongo.IsDuplicateKeyError(err) {
return err return errs.Wrap(err)
} }
} }
for i := range objs { for i := range objs {

Loading…
Cancel
Save