fix: wrap the error of group user and thrid (#2005)

* fix: wrap the error of group user and thrid

* fix: del the chinese comment

* fix: fix the make_lint error

* fix: fix the ApiTest error
This commit is contained in:
Brabem
2024-03-06 16:20:07 +08:00
committed by GitHub
parent c7dad1a5c1
commit 52b8efba73
13 changed files with 49 additions and 50 deletions
+4 -4
View File
@@ -161,7 +161,7 @@ func NewTask[A interface{ TableName() string }, B any, C any](gormDB *gorm.DB, m
tableName := zero.TableName()
coll, err := getColl(obj)
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
defer func() {
@@ -174,7 +174,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 {
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 {
return nil
@@ -184,7 +184,7 @@ func NewTask[A interface{ TableName() string }, B any, C any](gormDB *gorm.DB, m
temp[i] = convert(res[i])
}
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)
if len(res) < batch {
@@ -197,7 +197,7 @@ func NewTask[A interface{ TableName() string }, B any, C any](gormDB *gorm.DB, m
func insertMany(coll *mongo.Collection, objs []any) error {
if _, err := coll.InsertMany(context.Background(), objs); err != nil {
if !mongo.IsDuplicateKeyError(err) {
return err
return errs.Wrap(err)
}
}
for i := range objs {