Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize err #395

Merged
merged 19 commits into from
Jan 8, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,281 changes: 2,278 additions & 3 deletions coverage.txt

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.18
require (
dubbo.apache.org/dubbo-go/v3 v3.0.3-rc2
github.com/DATA-DOG/go-sqlmock v1.5.0
github.com/agiledragon/gomonkey v2.0.2+incompatible
github.com/agiledragon/gomonkey/v2 v2.2.0
github.com/apache/dubbo-getty v1.4.9-0.20220825024508-3da63c3257fa
github.com/arana-db/parser v0.2.5
github.com/dubbogo/gost v1.12.6-0.20220824084206-300e27e9e524
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5 h1:rFw4nCn9iMW+Vaj
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c=
github.com/agiledragon/gomonkey v2.0.2+incompatible h1:eXKi9/piiC3cjJD1658mEE2o3NjkJ5vDLgYjCQu0Xlw=
github.com/agiledragon/gomonkey v2.0.2+incompatible/go.mod h1:2NGfXu1a80LLr2cmWXGBDaHEjb1idR6+FVlX5T3D9hw=
github.com/agiledragon/gomonkey/v2 v2.2.0 h1:QJWqpdEhGV/JJy70sZ/LDnhbSlMrqHAWHcNOjz1kyuI=
github.com/agiledragon/gomonkey/v2 v2.2.0/go.mod h1:ap1AmDzcVOAz1YpeJ3TCzIgstoaWLA6jbbgxfB4w2iY=
github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func getJsonConfigResolver(bytes []byte) *koanf.Koanf {
return k
}

//resolverFilePath resolver file path
// resolverFilePath resolver file path
// eg: give a ./conf/seatago.yaml return seatago and yaml
func resolverFilePath(path string) (name, suffix string) {
paths := strings.Split(path, "/")
Expand Down Expand Up @@ -192,7 +192,7 @@ func absolutePath(inPath string) string {
return ""
}

//userHomeDir get gopath
// userHomeDir get gopath
func userHomeDir() string {
if runtime.GOOS == "windows" {
home := os.Getenv("HOMEDRIVE") + os.Getenv("HOMEPATH")
Expand Down
9 changes: 4 additions & 5 deletions pkg/config/parser/configuration_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
package parser

import (
"fmt"
"gopkg.in/yaml.v2"
mooleetzi marked this conversation as resolved.
Show resolved Hide resolved
"io/ioutil"
"path"

"github.com/pkg/errors"
"gopkg.in/yaml.v2"
)

// ConfigurationParser interface
Expand All @@ -33,11 +32,11 @@ type ConfigurationParser interface {
// LoadYMLConfig Load yml config byte from file check file type is *.yml or *.yaml`
func LoadYMLConfig(confProFile string) ([]byte, error) {
if len(confProFile) == 0 {
return nil, errors.Errorf("application configure(provider) file name is nil")
return nil, fmt.Errorf("application configure(provider) file name is nil")
}

if path.Ext(confProFile) != ".yml" && path.Ext(confProFile) != ".yaml" {
return nil, errors.Errorf("application configure file name{%v} suffix must be .yml or .yaml", confProFile)
return nil, fmt.Errorf("application configure file name{%v} suffix must be .yml or .yaml", confProFile)
}

return ioutil.ReadFile(confProFile)
Expand Down
5 changes: 3 additions & 2 deletions pkg/datasource/sql/at.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/seata/seata-go/pkg/datasource/sql/undo"
"github.com/seata/seata-go/pkg/protocol/branch"
"github.com/seata/seata-go/pkg/rm"
serr "github.com/seata/seata-go/pkg/util/errors"
)

const (
Expand Down Expand Up @@ -97,12 +98,12 @@ func (a *ATSourceManager) BranchRollback(ctx context.Context, branchResource rm.
}

if err := undoMgr.RunUndo(ctx, branchResource.Xid, branchResource.BranchId, dbResource.db, dbResource.dbName); err != nil {
transErr, ok := err.(*types.TransactionError)
transErr, ok := err.(*serr.SeataError)
if !ok {
return branch.BranchStatusPhaseoneFailed, err
}

if transErr.Code() == types.ErrorCodeBranchRollbackFailedUnretriable {
if transErr.Code == serr.ErrorCodeBranchRollbackFailedUnretriable {
return branch.BranchStatusPhasetwoRollbackFailedUnretryable, nil
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/datasource/sql/datasource/base/meta_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package base
import (
"context"
"database/sql"
"errors"
"fmt"
"sync"
"time"

Expand Down Expand Up @@ -154,7 +154,7 @@ func (c *BaseTableMetaCache) GetTableMeta(ctx context.Context, dbName, tableName
return *meta, nil
}

return types.TableMeta{}, errors.New("not found table metadata")
return types.TableMeta{}, fmt.Errorf("not found table metadata")
}

v.lastAccess = time.Now()
Expand Down
4 changes: 2 additions & 2 deletions pkg/datasource/sql/datasource/datasource_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package datasource
import (
"context"
"database/sql"
"errors"
"fmt"
"sync"

"github.com/seata/seata-go/pkg/datasource/sql/types"
Expand Down Expand Up @@ -120,7 +120,7 @@ func (dm *BasicSourceManager) RegisterResource(resource rm.Resource) error {

// Unregister a model.Resource from the model.Resource Manager
func (dm *BasicSourceManager) UnregisterResource(resource rm.Resource) error {
return errors.New("unsupport unregister resource")
return fmt.Errorf("unsupport unregister resource")
}

// Get all resources managed by this manager
Expand Down
5 changes: 2 additions & 3 deletions pkg/datasource/sql/datasource/mysql/meta_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ package mysql
import (
"context"
"database/sql"
"fmt"
"sync"
"time"

"github.com/pkg/errors"

"github.com/seata/seata-go/pkg/datasource/sql/datasource/base"
"github.com/seata/seata-go/pkg/datasource/sql/types"
)
Expand Down Expand Up @@ -56,7 +55,7 @@ func (c *TableMetaCache) Init(ctx context.Context, conn *sql.DB) error {
// GetTableMeta get table info from cache or information schema
func (c *TableMetaCache) GetTableMeta(ctx context.Context, dbName, tableName string) (*types.TableMeta, error) {
if tableName == "" {
return nil, errors.New("table name is empty")
return nil, fmt.Errorf("table name is empty")
}

conn, err := c.db.Conn(ctx)
Expand Down
8 changes: 4 additions & 4 deletions pkg/datasource/sql/datasource/mysql/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ package mysql
import (
"context"
"database/sql"
"strings"

"fmt"
"github.com/pkg/errors"
"github.com/seata/seata-go/pkg/datasource/sql/types"
"github.com/seata/seata-go/pkg/datasource/sql/undo/executor"
"strings"
)

const (
Expand Down Expand Up @@ -75,7 +75,7 @@ func (m *mysqlTrigger) LoadOne(ctx context.Context, dbName string, tableName str
}
}
if len(tableMeta.Indexs) == 0 {
return nil, errors.Errorf("Could not found any index in the table: %s", tableName)
return nil, fmt.Errorf("could not found any index in the table: %s", tableName)
}

return &tableMeta, nil
Expand Down Expand Up @@ -146,7 +146,7 @@ func (m *mysqlTrigger) getColumnMetas(ctx context.Context, dbName string, table
}

if len(columnMetas) == 0 {
return nil, errors.New("can't find column")
return nil, fmt.Errorf("can't find column")
}

return columnMetas, nil
Expand Down
3 changes: 1 addition & 2 deletions pkg/datasource/sql/exec/at/executor_at.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"fmt"

"github.com/mitchellh/copystructure"
"github.com/pkg/errors"
"github.com/seata/seata-go/pkg/datasource/sql/parser"
"github.com/seata/seata-go/pkg/datasource/sql/undo"
"github.com/seata/seata-go/pkg/tm"
Expand Down Expand Up @@ -63,7 +62,7 @@ func (e *ATExecutor) ExecWithNamedValue(ctx context.Context, execCtx *types.Exec
}
newBeforeImages, ok := beforeImagesTmp.([]*types.RecordImage)
if !ok {
return nil, errors.New("copy beforeImages failed")
return nil, fmt.Errorf("copy beforeImages failed")
}
execCtx.TxCtx.RoundImages.AppendBeofreImages(newBeforeImages)
}
Expand Down
1 change: 0 additions & 1 deletion pkg/datasource/sql/exec/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package exec
import (
"context"
"database/sql/driver"

mooleetzi marked this conversation as resolved.
Show resolved Hide resolved
"github.com/seata/seata-go/pkg/datasource/sql/parser"
"github.com/seata/seata-go/pkg/datasource/sql/types"
"github.com/seata/seata-go/pkg/datasource/sql/undo"
Expand Down
5 changes: 2 additions & 3 deletions pkg/datasource/sql/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ package sql
import (
"context"
"database/sql/driver"
"fmt"
"sync"

"github.com/pkg/errors"

"github.com/seata/seata-go/pkg/datasource/sql/datasource"
"github.com/seata/seata-go/pkg/protocol/branch"
"github.com/seata/seata-go/pkg/rm"
Expand Down Expand Up @@ -183,7 +182,7 @@ func (tx *Tx) report(success bool) error {
}
dataSourceManager := datasource.GetDataSourceManager(tx.tranCtx.TransactionMode.BranchType())
if dataSourceManager == nil {
return errors.New("get dataSourceManager failed")
return fmt.Errorf("get dataSourceManager failed")
}
retry := REPORT_RETRY_COUNT
for retry > 0 {
Expand Down
57 changes: 0 additions & 57 deletions pkg/datasource/sql/types/error.go

This file was deleted.

7 changes: 3 additions & 4 deletions pkg/datasource/sql/types/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
package types

import (
"fmt"
"reflect"

"github.com/pkg/errors"
)

// ColumnMeta
Expand Down Expand Up @@ -129,7 +128,7 @@ func (m TableMeta) GetPrimaryKeyType() (int32, error) {
}
}
}
return 0, errors.New("get primary key type error")
return 0, fmt.Errorf("get primary key type error")
}

// GetPrimaryKeyTypeStrMap get all PK type to map
Expand All @@ -143,7 +142,7 @@ func (m TableMeta) GetPrimaryKeyTypeStrMap() (map[string]string, error) {
}
}
if len(pkMap) == 0 {
return nil, errors.New("get primary key type error")
return nil, fmt.Errorf("get primary key type error")
}
return pkMap, nil
}
3 changes: 2 additions & 1 deletion pkg/datasource/sql/undo/base/undo.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"database/sql"
"database/sql/driver"
"encoding/json"
"fmt"
"strconv"
"strings"

Expand Down Expand Up @@ -428,7 +429,7 @@ func (m *BaseUndoLogManager) appendInParam(size int, str *strings.Builder) {
func Int64Slice2Str(values interface{}, sep string) (string, error) {
v, ok := values.([]int64)
if !ok {
return "", errors.New("param type is fault")
return "", fmt.Errorf("param type is fault")
}

var valuesText []string
Expand Down
Loading