Skip to content

Commit

Permalink
Revert "*: using standard error to replace terror (pingcap#19425)" (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
Lingyu Song authored Sep 11, 2020
1 parent ab51272 commit 51d365f
Show file tree
Hide file tree
Showing 22 changed files with 61 additions and 63 deletions.
2 changes: 1 addition & 1 deletion ddl/db_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func (s *testIntegrationSuite2) TestIssue6101(c *C) {
tk.MustExec("create table t1 (quantity decimal(2) unsigned);")
_, err := tk.Exec("insert into t1 values (500), (-500), (~0), (-1);")
terr := errors.Cause(err).(*terror.Error)
c.Assert(terr.Code(), Equals, errors.ErrCode(errno.ErrWarnDataOutOfRange))
c.Assert(terr.Code(), Equals, terror.ErrCode(errno.ErrWarnDataOutOfRange))
tk.MustExec("drop table t1")

tk.MustExec("set sql_mode=''")
Expand Down
5 changes: 2 additions & 3 deletions domain/domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"github.com/pingcap/failpoint"
"github.com/pingcap/parser/ast"
"github.com/pingcap/parser/model"
"github.com/pingcap/parser/terror"
"github.com/pingcap/tidb/ddl"
"github.com/pingcap/tidb/domain/infosync"
"github.com/pingcap/tidb/errno"
Expand Down Expand Up @@ -459,6 +458,6 @@ func (*testSuite) TestSessionPool(c *C) {
}

func (*testSuite) TestErrorCode(c *C) {
c.Assert(int(terror.ToSQLError(ErrInfoSchemaExpired).Code), Equals, errno.ErrInfoSchemaExpired)
c.Assert(int(terror.ToSQLError(ErrInfoSchemaChanged).Code), Equals, errno.ErrInfoSchemaChanged)
c.Assert(int(ErrInfoSchemaExpired.ToSQLError().Code), Equals, errno.ErrInfoSchemaExpired)
c.Assert(int(ErrInfoSchemaChanged.ToSQLError().Code), Equals, errno.ErrInfoSchemaChanged)
}
22 changes: 11 additions & 11 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1248,12 +1248,12 @@ func (s *testSuiteP2) TestUnion(c *C) {
err := tk.ExecToErr("select 1 from (select a from t limit 1 union all select a from t limit 1) tmp")
c.Assert(err, NotNil)
terr := errors.Cause(err).(*terror.Error)
c.Assert(terr.Code(), Equals, errors.ErrCode(mysql.ErrWrongUsage))
c.Assert(terr.Code(), Equals, terror.ErrCode(mysql.ErrWrongUsage))

err = tk.ExecToErr("select 1 from (select a from t order by a union all select a from t limit 1) tmp")
c.Assert(err, NotNil)
terr = errors.Cause(err).(*terror.Error)
c.Assert(terr.Code(), Equals, errors.ErrCode(mysql.ErrWrongUsage))
c.Assert(terr.Code(), Equals, terror.ErrCode(mysql.ErrWrongUsage))

_, err = tk.Exec("(select a from t order by a) union all select a from t limit 1 union all select a from t limit 1")
c.Assert(terror.ErrorEqual(err, plannercore.ErrWrongUsage), IsTrue, Commentf("err %v", err))
Expand Down Expand Up @@ -1642,23 +1642,23 @@ func (s *testSuiteP1) TestJSON(c *C) {
_, err = tk.Exec(`create table test_bad_json(a json default '{}')`)
c.Assert(err, NotNil)
terr = errors.Cause(err).(*terror.Error)
c.Assert(terr.Code(), Equals, errors.ErrCode(mysql.ErrBlobCantHaveDefault))
c.Assert(terr.Code(), Equals, terror.ErrCode(mysql.ErrBlobCantHaveDefault))

_, err = tk.Exec(`create table test_bad_json(a blob default 'hello')`)
c.Assert(err, NotNil)
terr = errors.Cause(err).(*terror.Error)
c.Assert(terr.Code(), Equals, errors.ErrCode(mysql.ErrBlobCantHaveDefault))
c.Assert(terr.Code(), Equals, terror.ErrCode(mysql.ErrBlobCantHaveDefault))

_, err = tk.Exec(`create table test_bad_json(a text default 'world')`)
c.Assert(err, NotNil)
terr = errors.Cause(err).(*terror.Error)
c.Assert(terr.Code(), Equals, errors.ErrCode(mysql.ErrBlobCantHaveDefault))
c.Assert(terr.Code(), Equals, terror.ErrCode(mysql.ErrBlobCantHaveDefault))

// check json fields cannot be used as key.
_, err = tk.Exec(`create table test_bad_json(id int, a json, key (a))`)
c.Assert(err, NotNil)
terr = errors.Cause(err).(*terror.Error)
c.Assert(terr.Code(), Equals, errors.ErrCode(mysql.ErrJSONUsedAsKey))
c.Assert(terr.Code(), Equals, terror.ErrCode(mysql.ErrJSONUsedAsKey))

// check CAST AS JSON.
result = tk.MustQuery(`select CAST('3' AS JSON), CAST('{}' AS JSON), CAST(null AS JSON)`)
Expand Down Expand Up @@ -1756,7 +1756,7 @@ func (s *testSuiteP1) TestGeneratedColumnWrite(c *C) {
if tt.err != 0 {
c.Assert(err, NotNil, Commentf("sql is `%v`", tt.stmt))
terr := errors.Cause(err).(*terror.Error)
c.Assert(terr.Code(), Equals, errors.ErrCode(tt.err), Commentf("sql is %v", tt.stmt))
c.Assert(terr.Code(), Equals, terror.ErrCode(tt.err), Commentf("sql is %v", tt.stmt))
} else {
c.Assert(err, IsNil)
}
Expand Down Expand Up @@ -1927,7 +1927,7 @@ func (s *testSuiteP1) TestGeneratedColumnRead(c *C) {
if tt.err != 0 {
c.Assert(err, NotNil)
terr := errors.Cause(err).(*terror.Error)
c.Assert(terr.Code(), Equals, errors.ErrCode(tt.err))
c.Assert(terr.Code(), Equals, terror.ErrCode(tt.err))
} else {
c.Assert(err, IsNil)
}
Expand Down Expand Up @@ -3295,7 +3295,7 @@ func (s *testSuite) TestContainDotColumn(c *C) {
tk.MustExec("drop table if exists t3")
_, err := tk.Exec("create table t3(s.a char);")
terr := errors.Cause(err).(*terror.Error)
c.Assert(terr.Code(), Equals, errors.ErrCode(mysql.ErrWrongTableName))
c.Assert(terr.Code(), Equals, terror.ErrCode(mysql.ErrWrongTableName))
}

func (s *testSuite) TestCheckIndex(c *C) {
Expand Down Expand Up @@ -4213,7 +4213,7 @@ func (s *testSuiteP2) TestSplitRegion(c *C) {
_, err := tk.Exec(`split table t index idx1 by ("abcd");`)
c.Assert(err, NotNil)
terr := errors.Cause(err).(*terror.Error)
c.Assert(terr.Code(), Equals, errors.ErrCode(mysql.WarnDataTruncated))
c.Assert(terr.Code(), Equals, terror.ErrCode(mysql.WarnDataTruncated))

// Test for split index region.
// Check min value is more than max value.
Expand Down Expand Up @@ -5956,7 +5956,7 @@ func (s *testSplitTable) TestKillTableReader(c *C) {
wg.Add(1)
go func() {
defer wg.Done()
c.Assert(int(terror.ToSQLError(errors.Cause(tk.QueryToErr("select * from t")).(*terror.Error)).Code), Equals, int(executor.ErrQueryInterrupted.Code()))
c.Assert(int(errors.Cause(tk.QueryToErr("select * from t")).(*terror.Error).ToSQLError().Code), Equals, int(executor.ErrQueryInterrupted.Code()))
}()
time.Sleep(1 * time.Second)
atomic.StoreUint32(&tk.Se.GetSessionVars().Killed, 1)
Expand Down
2 changes: 1 addition & 1 deletion executor/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,7 @@ func (e *ShowExec) fetchShowWarnings(errOnly bool) error {
warn := errors.Cause(w.Err)
switch x := warn.(type) {
case *terror.Error:
sqlErr := terror.ToSQLError(x)
sqlErr := x.ToSQLError()
e.appendRow([]interface{}{w.Level, int64(sqlErr.Code), sqlErr.Message})
default:
e.appendRow([]interface{}{w.Level, int64(mysql.ErrUnknown), warn.Error()})
Expand Down
4 changes: 2 additions & 2 deletions executor/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (e *TraceExec) executeChild(ctx context.Context, se sqlexec.SQLExecutor) {
if err != nil {
var errCode uint16
if te, ok := err.(*terror.Error); ok {
errCode = terror.ToSQLError(te).Code
errCode = te.ToSQLError().Code
}
logutil.Eventf(ctx, "execute with error(%d): %s", errCode, err.Error())
} else {
Expand All @@ -161,7 +161,7 @@ func drainRecordSet(ctx context.Context, sctx sessionctx.Context, rs sqlexec.Rec
if err != nil {
var errCode uint16
if te, ok := err.(*terror.Error); ok {
errCode = terror.ToSQLError(te).Code
errCode = te.ToSQLError().Code
}
logutil.Eventf(ctx, "execute with error(%d): %s", errCode, err.Error())
} else {
Expand Down
14 changes: 7 additions & 7 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ func (s *testIntegrationSuite2) TestMathBuiltin(c *C) {
_, err = session.GetRows4Test(ctx, tk.Se, rs)
c.Assert(err, NotNil)
terr := errors.Cause(err).(*terror.Error)
c.Assert(terr.Code(), Equals, errors.ErrCode(mysql.ErrDataOutOfRange))
c.Assert(terr.Code(), Equals, terror.ErrCode(mysql.ErrDataOutOfRange))
c.Assert(rs.Close(), IsNil)

//for exp
Expand All @@ -479,7 +479,7 @@ func (s *testIntegrationSuite2) TestMathBuiltin(c *C) {
_, err = session.GetRows4Test(ctx, tk.Se, rs)
c.Assert(err, NotNil)
terr = errors.Cause(err).(*terror.Error)
c.Assert(terr.Code(), Equals, errors.ErrCode(mysql.ErrDataOutOfRange))
c.Assert(terr.Code(), Equals, terror.ErrCode(mysql.ErrDataOutOfRange))
c.Assert(rs.Close(), IsNil)
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a float)")
Expand All @@ -489,7 +489,7 @@ func (s *testIntegrationSuite2) TestMathBuiltin(c *C) {
_, err = session.GetRows4Test(ctx, tk.Se, rs)
c.Assert(err, NotNil)
terr = errors.Cause(err).(*terror.Error)
c.Assert(terr.Code(), Equals, errors.ErrCode(mysql.ErrDataOutOfRange))
c.Assert(terr.Code(), Equals, terror.ErrCode(mysql.ErrDataOutOfRange))
c.Assert(err.Error(), Equals, "[types:1690]DOUBLE value is out of range in 'exp(test.t.a)'")
c.Assert(rs.Close(), IsNil)

Expand Down Expand Up @@ -529,7 +529,7 @@ func (s *testIntegrationSuite2) TestMathBuiltin(c *C) {
_, err = session.GetRows4Test(ctx, tk.Se, rs)
c.Assert(err, NotNil)
terr = errors.Cause(err).(*terror.Error)
c.Assert(terr.Code(), Equals, errors.ErrCode(mysql.ErrDataOutOfRange))
c.Assert(terr.Code(), Equals, terror.ErrCode(mysql.ErrDataOutOfRange))
c.Assert(rs.Close(), IsNil)

// for round
Expand Down Expand Up @@ -608,7 +608,7 @@ func (s *testIntegrationSuite2) TestMathBuiltin(c *C) {
_, err = session.GetRows4Test(ctx, tk.Se, rs)
c.Assert(err, NotNil)
terr = errors.Cause(err).(*terror.Error)
c.Assert(terr.Code(), Equals, errors.ErrCode(mysql.ErrDataOutOfRange))
c.Assert(terr.Code(), Equals, terror.ErrCode(mysql.ErrDataOutOfRange))
c.Assert(rs.Close(), IsNil)

// for sign
Expand Down Expand Up @@ -1226,7 +1226,7 @@ func (s *testIntegrationSuite2) TestEncryptionBuiltin(c *C) {
_, err = session.GetRows4Test(ctx, tk.Se, rs)
c.Assert(err, NotNil, Commentf("%v", len))
terr := errors.Cause(err).(*terror.Error)
c.Assert(terr.Code(), Equals, errors.ErrCode(mysql.ErrDataOutOfRange), Commentf("%v", len))
c.Assert(terr.Code(), Equals, terror.ErrCode(mysql.ErrDataOutOfRange), Commentf("%v", len))
c.Assert(rs.Close(), IsNil)
}
tk.MustQuery("SELECT RANDOM_BYTES('1');")
Expand Down Expand Up @@ -3691,7 +3691,7 @@ func (s *testIntegrationSuite) TestAggregationBuiltinGroupConcat(c *C) {
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning 1260 Some rows were cut by GROUPCONCAT(test.t.a)"))

_, err := tk.Exec("insert into d select group_concat(a) from t")
c.Assert(errors.Cause(err).(*terror.Error).Code(), Equals, errors.ErrCode(mysql.ErrCutValueGroupConcat))
c.Assert(errors.Cause(err).(*terror.Error).Code(), Equals, terror.ErrCode(mysql.ErrCutValueGroupConcat))

tk.Exec("set sql_mode=''")
tk.MustExec("insert into d select group_concat(a) from t")
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ require (
github.com/pingcap/goleveldb v0.0.0-20191226122134-f82aafb29989
github.com/pingcap/kvproto v0.0.0-20200818080353-7aaed8998596
github.com/pingcap/log v0.0.0-20200828042413-fce0951f1463
github.com/pingcap/parser v0.0.0-20200908132759-b65348b6244c
github.com/pingcap/parser v0.0.0-20200911054040-258297116c4b
github.com/pingcap/sysutil v0.0.0-20200715082929-4c47bcac246a
github.com/pingcap/tidb-tools v4.0.6-0.20200828085514-03575b185007+incompatible
github.com/pingcap/tipb v0.0.0-20200618092958-4fad48b4c8c3
Expand Down
5 changes: 2 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,8 @@ github.com/pingcap/parser v0.0.0-20200603032439-c4ecb4508d2f/go.mod h1:9v0Edh8Ib
github.com/pingcap/parser v0.0.0-20200623164729-3a18f1e5dceb/go.mod h1:vQdbJqobJAgFyiRNNtXahpMoGWwPEuWciVEK5A20NS0=
github.com/pingcap/parser v0.0.0-20200803072748-fdf66528323d/go.mod h1:vQdbJqobJAgFyiRNNtXahpMoGWwPEuWciVEK5A20NS0=
github.com/pingcap/parser v0.0.0-20200901062802-475ea5e2e0a7/go.mod h1:vQdbJqobJAgFyiRNNtXahpMoGWwPEuWciVEK5A20NS0=
github.com/pingcap/parser v0.0.0-20200908132759-b65348b6244c h1:oJn1X+lZwG4LG2DV+73lppFfnfy+3wXUwpoVgtIOQq8=
github.com/pingcap/parser v0.0.0-20200908132759-b65348b6244c/go.mod h1:RlLfMRJwFBSiXd2lUaWdV5pSXtrpyvZM8k5bbZWsheU=
github.com/pingcap/parser v0.0.0-20200911054040-258297116c4b h1:olNvO8UWo7Y+t2oWwB46cDj5pyqosgiQts5t8tZlbSc=
github.com/pingcap/parser v0.0.0-20200911054040-258297116c4b/go.mod h1:vQdbJqobJAgFyiRNNtXahpMoGWwPEuWciVEK5A20NS0=
github.com/pingcap/pd/v4 v4.0.0-rc.1.0.20200422143320-428acd53eba2/go.mod h1:s+utZtXDznOiL24VK0qGmtoHjjXNsscJx3m1n8cC56s=
github.com/pingcap/pd/v4 v4.0.0-rc.2.0.20200520083007-2c251bd8f181/go.mod h1:q4HTx/bA8aKBa4S7L+SQKHvjRPXCRV0tA0yRw0qkZSA=
github.com/pingcap/pd/v4 v4.0.5-0.20200817114353-e465cafe8a91 h1:zCOWP+kIzM6ZsXdu2QoM/W6+3vFZj04MYboMP2Obc0E=
Expand Down Expand Up @@ -609,7 +609,6 @@ github.com/ugorji/go/codec v1.1.5-pre/go.mod h1:tULtS6Gy1AE1yCENaw4Vb//HLH5njI2t
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
github.com/unrolled/render v0.0.0-20171102162132-65450fb6b2d3/go.mod h1:tu82oB5W2ykJRVioYsB+IQKcft7ryBr7w12qMBUPyXg=
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
github.com/urfave/cli v1.22.2 h1:gsqYFH8bb9ekPA12kRo0hfjngWQjkJPlN9R0N78BoUo=
github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/urfave/cli/v2 v2.1.1/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
github.com/urfave/negroni v0.3.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4=
Expand Down
2 changes: 1 addition & 1 deletion kv/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (s testErrorSuite) TestError(c *C) {
ErrWriteConflictInTiDB,
}
for _, err := range kvErrs {
code := terror.ToSQLError(err).Code
code := err.ToSQLError().Code
c.Assert(code != mysql.ErrUnknown && code == uint16(err.Code()), IsTrue, Commentf("err: %v", err))
}
}
4 changes: 3 additions & 1 deletion metrics/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
package metrics

import (
"strconv"

"github.com/pingcap/errors"
"github.com/pingcap/parser/terror"
"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -168,7 +170,7 @@ func ExecuteErrorToLabel(err error) string {
err = errors.Cause(err)
switch x := err.(type) {
case *terror.Error:
return string(x.RFCCode())
return x.Class().String() + ":" + strconv.Itoa(int(x.Code()))
default:
return "unknown"
}
Expand Down
2 changes: 1 addition & 1 deletion planner/core/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (s testErrorSuite) TestError(c *C) {
ErrAmbiguous,
}
for _, err := range kvErrs {
code := terror.ToSQLError(err).Code
code := err.ToSQLError().Code
c.Assert(code != mysql.ErrUnknown && code == uint16(err.Code()), IsTrue, Commentf("err: %v", err))
}
}
2 changes: 1 addition & 1 deletion privilege/privileges/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ func (p *MySQLPrivilege) LoadAll(ctx sessionctx.Context) error {
func noSuchTable(err error) bool {
e1 := errors.Cause(err)
if e2, ok := e1.(*terror.Error); ok {
if terror.ErrCode(e2.Code()) == terror.ErrCode(mysql.ErrNoSuchTable) {
if e2.Code() == terror.ErrCode(mysql.ErrNoSuchTable) {
return true
}
}
Expand Down
4 changes: 2 additions & 2 deletions server/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -1008,12 +1008,12 @@ func (cc *clientConn) writeError(ctx context.Context, e error) error {
)
originErr := errors.Cause(e)
if te, ok = originErr.(*terror.Error); ok {
m = terror.ToSQLError(te)
m = te.ToSQLError()
} else {
e := errors.Cause(originErr)
switch y := e.(type) {
case *terror.Error:
m = terror.ToSQLError(y)
m = y.ToSQLError()
default:
m = mysql.NewErrf(mysql.ErrUnknown, "%s", e.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion sessionctx/variable/sysvar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,6 @@ func (*testSysVarSuite) TestError(c *C) {
ErrUnsupportedIsolationLevel,
}
for _, err := range kvErrs {
c.Assert(terror.ToSQLError(err).Code != mysql.ErrUnknown, IsTrue)
c.Assert(err.ToSQLError().Code != mysql.ErrUnknown, IsTrue)
}
}
4 changes: 2 additions & 2 deletions store/mockstore/mocktikv/cop_handler_dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -814,14 +814,14 @@ func toPBError(err error) *tipb.Error {
perr := new(tipb.Error)
switch x := err.(type) {
case *terror.Error:
sqlErr := terror.ToSQLError(x)
sqlErr := x.ToSQLError()
perr.Code = int32(sqlErr.Code)
perr.Msg = sqlErr.Message
default:
e := errors.Cause(err)
switch y := e.(type) {
case *terror.Error:
tmp := terror.ToSQLError(y)
tmp := y.ToSQLError()
perr.Code = int32(tmp.Code)
perr.Msg = tmp.Message
default:
Expand Down
2 changes: 1 addition & 1 deletion structure/structure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ func (*testTxStructureSuite) TestError(c *C) {
structure.ErrWriteOnSnapshot,
}
for _, err := range kvErrs {
code := terror.ToSQLError(err).Code
code := err.ToSQLError().Code
c.Assert(code != mysql.ErrUnknown && code == uint16(err.Code()), IsTrue, Commentf("err: %v", err))
}
}
35 changes: 17 additions & 18 deletions table/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ package table

import (
. "github.com/pingcap/check"
"github.com/pingcap/parser/terror"
mysql "github.com/pingcap/tidb/errno"
)

Expand All @@ -31,21 +30,21 @@ func (t *testTableSuite) TestSlice(c *C) {
}

func (t *testTableSuite) TestErrorCode(c *C) {
c.Assert(int(terror.ToSQLError(ErrColumnCantNull).Code), Equals, mysql.ErrBadNull)
c.Assert(int(terror.ToSQLError(ErrUnknownColumn).Code), Equals, mysql.ErrBadField)
c.Assert(int(terror.ToSQLError(errDuplicateColumn).Code), Equals, mysql.ErrFieldSpecifiedTwice)
c.Assert(int(terror.ToSQLError(errGetDefaultFailed).Code), Equals, mysql.ErrFieldGetDefaultFailed)
c.Assert(int(terror.ToSQLError(ErrNoDefaultValue).Code), Equals, mysql.ErrNoDefaultForField)
c.Assert(int(terror.ToSQLError(ErrIndexOutBound).Code), Equals, mysql.ErrIndexOutBound)
c.Assert(int(terror.ToSQLError(ErrUnsupportedOp).Code), Equals, mysql.ErrUnsupportedOp)
c.Assert(int(terror.ToSQLError(ErrRowNotFound).Code), Equals, mysql.ErrRowNotFound)
c.Assert(int(terror.ToSQLError(ErrTableStateCantNone).Code), Equals, mysql.ErrTableStateCantNone)
c.Assert(int(terror.ToSQLError(ErrColumnStateCantNone).Code), Equals, mysql.ErrColumnStateCantNone)
c.Assert(int(terror.ToSQLError(ErrColumnStateNonPublic).Code), Equals, mysql.ErrColumnStateNonPublic)
c.Assert(int(terror.ToSQLError(ErrIndexStateCantNone).Code), Equals, mysql.ErrIndexStateCantNone)
c.Assert(int(terror.ToSQLError(ErrInvalidRecordKey).Code), Equals, mysql.ErrInvalidRecordKey)
c.Assert(int(terror.ToSQLError(ErrTruncatedWrongValueForField).Code), Equals, mysql.ErrTruncatedWrongValueForField)
c.Assert(int(terror.ToSQLError(ErrUnknownPartition).Code), Equals, mysql.ErrUnknownPartition)
c.Assert(int(terror.ToSQLError(ErrNoPartitionForGivenValue).Code), Equals, mysql.ErrNoPartitionForGivenValue)
c.Assert(int(terror.ToSQLError(ErrLockOrActiveTransaction).Code), Equals, mysql.ErrLockOrActiveTransaction)
c.Assert(int(ErrColumnCantNull.ToSQLError().Code), Equals, mysql.ErrBadNull)
c.Assert(int(ErrUnknownColumn.ToSQLError().Code), Equals, mysql.ErrBadField)
c.Assert(int(errDuplicateColumn.ToSQLError().Code), Equals, mysql.ErrFieldSpecifiedTwice)
c.Assert(int(errGetDefaultFailed.ToSQLError().Code), Equals, mysql.ErrFieldGetDefaultFailed)
c.Assert(int(ErrNoDefaultValue.ToSQLError().Code), Equals, mysql.ErrNoDefaultForField)
c.Assert(int(ErrIndexOutBound.ToSQLError().Code), Equals, mysql.ErrIndexOutBound)
c.Assert(int(ErrUnsupportedOp.ToSQLError().Code), Equals, mysql.ErrUnsupportedOp)
c.Assert(int(ErrRowNotFound.ToSQLError().Code), Equals, mysql.ErrRowNotFound)
c.Assert(int(ErrTableStateCantNone.ToSQLError().Code), Equals, mysql.ErrTableStateCantNone)
c.Assert(int(ErrColumnStateCantNone.ToSQLError().Code), Equals, mysql.ErrColumnStateCantNone)
c.Assert(int(ErrColumnStateNonPublic.ToSQLError().Code), Equals, mysql.ErrColumnStateNonPublic)
c.Assert(int(ErrIndexStateCantNone.ToSQLError().Code), Equals, mysql.ErrIndexStateCantNone)
c.Assert(int(ErrInvalidRecordKey.ToSQLError().Code), Equals, mysql.ErrInvalidRecordKey)
c.Assert(int(ErrTruncatedWrongValueForField.ToSQLError().Code), Equals, mysql.ErrTruncatedWrongValueForField)
c.Assert(int(ErrUnknownPartition.ToSQLError().Code), Equals, mysql.ErrUnknownPartition)
c.Assert(int(ErrNoPartitionForGivenValue.ToSQLError().Code), Equals, mysql.ErrNoPartitionForGivenValue)
c.Assert(int(ErrLockOrActiveTransaction.ToSQLError().Code), Equals, mysql.ErrLockOrActiveTransaction)
}
2 changes: 1 addition & 1 deletion tablecodec/tablecodec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ func (s *testTableCodecSuite) TestError(c *C) {
errInvalidIndexKey,
}
for _, err := range kvErrs {
code := terror.ToSQLError(err).Code
code := err.ToSQLError().Code
c.Assert(code != mysql.ErrUnknown && code == uint16(err.Code()), IsTrue, Commentf("err: %v", err))
}
}
2 changes: 1 addition & 1 deletion types/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (s testErrorSuite) TestError(c *C) {
ErrWrongValue,
}
for _, err := range kvErrs {
code := terror.ToSQLError(err).Code
code := err.ToSQLError().Code
c.Assert(code != mysql.ErrUnknown && code == uint16(err.Code()), IsTrue, Commentf("err: %v", err))
}
}
2 changes: 1 addition & 1 deletion util/admin/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ func (s *testSuite) TestError(c *C) {
ErrCannotCancelDDLJob,
}
for _, err := range kvErrs {
code := terror.ToSQLError(err).Code
code := err.ToSQLError().Code
c.Assert(code != mysql.ErrUnknown && code == uint16(err.Code()), IsTrue, Commentf("err: %v", err))
}
}
Loading

0 comments on commit 51d365f

Please sign in to comment.