Skip to content

Commit

Permalink
*: use terror instead of error
Browse files Browse the repository at this point in the history
  • Loading branch information
zimulala committed Nov 10, 2015
1 parent 809f505 commit 3684664
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
5 changes: 3 additions & 2 deletions plan/plans/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/pingcap/tidb/sessionctx/variable"
"github.com/pingcap/tidb/stmt"
"github.com/pingcap/tidb/table"
"github.com/pingcap/tidb/terror"
"github.com/pingcap/tidb/util/charset"
"github.com/pingcap/tidb/util/format"
)
Expand Down Expand Up @@ -414,7 +415,7 @@ func getSessionStatusVar(ctx context.Context, sessionVars *variable.SessionVars,
}

value, err := globalVars.GetGlobalStatusVar(ctx, name)
if err != nil && err != variable.ErrUnknownStatusVar {
if err != nil && terror.UnknownStatusVar.Equal(err) {
return "", errors.Trace(err)
}

Expand All @@ -429,7 +430,7 @@ func getGlobalStatusVar(ctx context.Context, sessionVars *variable.SessionVars,
return value, nil
}

if err != variable.ErrUnknownStatusVar {
if terror.UnknownStatusVar.Equal(err) {
return "", errors.Trace(err)
}

Expand Down
12 changes: 6 additions & 6 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func (s *session) getExecRet(ctx context.Context, sql string) (string, error) {
return "", errors.Trace(err)
}
if row == nil {
return "", errors.New("result is empty")
return "", terror.ExecResultIsEmpty
}
value, err := types.ToString(row.Data[0])
if err != nil {
Expand All @@ -290,8 +290,7 @@ func (s *session) GetGlobalStatusVar(ctx context.Context, name string) (string,
// TODO: get global status variables from store.
v := variable.GetStatusVar(name)
if v == nil {
log.Errorf("get global status var %s is err:%v", name, variable.ErrUnknownStatusVar)
return "", variable.ErrUnknownStatusVar
return "", terror.UnknownStatusVar.Gen("unknown status variable:%s", name)
}

return v.Value, nil
Expand All @@ -302,8 +301,7 @@ func (s *session) SetGlobalStatusVar(ctx context.Context, name string, value str
// TODO: set global status variables from store.
v := variable.GetStatusVar(name)
if v == nil {
log.Errorf("set global status var %s is err:%v", name, variable.ErrUnknownStatusVar)
return variable.ErrUnknownStatusVar
return terror.UnknownStatusVar.Gen("unknown status variable:%s", name)
}
v.Value = value

Expand All @@ -315,7 +313,9 @@ func (s *session) GetGlobalSysVar(ctx context.Context, name string) (string, err
sql := fmt.Sprintf(`SELECT VARIABLE_VALUE FROM %s.%s WHERE VARIABLE_NAME="%s";`, mysql.SystemDB, mysql.GlobalVariablesTable, name)
sysVar, err := s.getExecRet(ctx, sql)
if err != nil {
log.Errorf("get global sys var %s is err:%v", name, err)
if terror.ExecResultIsEmpty.Equal(err) {
return "", terror.ExecResultIsEmpty.Gen("unknown sys variable:%s", name)
}
return "", errors.Trace(err)
}

Expand Down
10 changes: 10 additions & 0 deletions terror/terror.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ var (

CommitNotInTransaction = ClassExecutor.New(CodeCommitNotInTransaction, "commit not in transaction")
RollbackNotInTransaction = ClassExecutor.New(CodeRollbackNotInTransaction, "rollback not in transaction")
ExecResultIsEmpty = ClassExecutor.New(CodeExecResultIsEmpty, "exec result is empty")

UnknownStatusVar = ClassVariable.New(CodeUnknownStatusVar, "unknown status variable")
)

// ErrCode represents a specific error type in a error class.
Expand All @@ -44,6 +47,7 @@ const (
const (
CodeCommitNotInTransaction ErrCode = iota + 1
CodeRollbackNotInTransaction
CodeExecResultIsEmpty
)

// KV error codes.
Expand All @@ -52,6 +56,11 @@ const (
CodeNoDataForHandle
)

// Variable error codes.
const (
CodeUnknownStatusVar ErrCode = iota + 1
)

// ErrClass represents a class of errors.
type ErrClass int

Expand All @@ -63,6 +72,7 @@ const (
ClassExecutor
ClassKV
ClassServer
ClassVariable
// Add more as needed.
)

Expand Down

0 comments on commit 3684664

Please sign in to comment.