diff --git a/ddl/db_integration_test.go b/ddl/db_integration_test.go index 9c469db3a12db..d9a0ab1f6fd89 100644 --- a/ddl/db_integration_test.go +++ b/ddl/db_integration_test.go @@ -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=''") diff --git a/domain/domain_test.go b/domain/domain_test.go index b065c86e52428..1a2618d550c5a 100644 --- a/domain/domain_test.go +++ b/domain/domain_test.go @@ -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" @@ -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) } diff --git a/executor/executor_test.go b/executor/executor_test.go index 7708e1f4f4b79..1a4af061f395c 100644 --- a/executor/executor_test.go +++ b/executor/executor_test.go @@ -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)) @@ -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)`) @@ -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) } @@ -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) } @@ -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) { @@ -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. @@ -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) diff --git a/executor/show.go b/executor/show.go index 305f3172a4ec5..dea0ead1f0e42 100644 --- a/executor/show.go +++ b/executor/show.go @@ -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()}) diff --git a/executor/trace.go b/executor/trace.go index bf9150f357081..3d0e787db5b55 100644 --- a/executor/trace.go +++ b/executor/trace.go @@ -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 { @@ -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 { diff --git a/expression/integration_test.go b/expression/integration_test.go index 640d2d6a761f6..0281e82df9197 100755 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -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 @@ -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)") @@ -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) @@ -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 @@ -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 @@ -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');") @@ -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") diff --git a/go.mod b/go.mod index 7d9e7fa16ef02..9c50b701ff791 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index d6cec4b861e86..97ab05dc79471 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= diff --git a/kv/error_test.go b/kv/error_test.go index 4fd73a0fdf013..a5a608ac4849e 100644 --- a/kv/error_test.go +++ b/kv/error_test.go @@ -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)) } } diff --git a/metrics/server.go b/metrics/server.go index c753f9612638b..250d35b68e061 100644 --- a/metrics/server.go +++ b/metrics/server.go @@ -14,6 +14,8 @@ package metrics import ( + "strconv" + "github.com/pingcap/errors" "github.com/pingcap/parser/terror" "github.com/prometheus/client_golang/prometheus" @@ -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" } diff --git a/planner/core/errors_test.go b/planner/core/errors_test.go index 2f17297484fe4..bce2a3563978d 100644 --- a/planner/core/errors_test.go +++ b/planner/core/errors_test.go @@ -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)) } } diff --git a/privilege/privileges/cache.go b/privilege/privileges/cache.go index 62284687fb929..9d7e2b4404fab 100644 --- a/privilege/privileges/cache.go +++ b/privilege/privileges/cache.go @@ -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 } } diff --git a/server/conn.go b/server/conn.go index 406c90b9a746a..0f541376f8781 100644 --- a/server/conn.go +++ b/server/conn.go @@ -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()) } diff --git a/sessionctx/variable/sysvar_test.go b/sessionctx/variable/sysvar_test.go index 51c6eba70134a..eaf309db70f52 100644 --- a/sessionctx/variable/sysvar_test.go +++ b/sessionctx/variable/sysvar_test.go @@ -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) } } diff --git a/store/mockstore/mocktikv/cop_handler_dag.go b/store/mockstore/mocktikv/cop_handler_dag.go index 6692fd59011a1..086c797ee093f 100644 --- a/store/mockstore/mocktikv/cop_handler_dag.go +++ b/store/mockstore/mocktikv/cop_handler_dag.go @@ -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: diff --git a/structure/structure_test.go b/structure/structure_test.go index 53c7e0dbfb33e..62fdeb8f60159 100644 --- a/structure/structure_test.go +++ b/structure/structure_test.go @@ -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)) } } diff --git a/table/table_test.go b/table/table_test.go index edcfc7d3c2bc9..d3d0e5edd172c 100644 --- a/table/table_test.go +++ b/table/table_test.go @@ -15,7 +15,6 @@ package table import ( . "github.com/pingcap/check" - "github.com/pingcap/parser/terror" mysql "github.com/pingcap/tidb/errno" ) @@ -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) } diff --git a/tablecodec/tablecodec_test.go b/tablecodec/tablecodec_test.go index b56c3cd6b9901..74ad57e626f60 100644 --- a/tablecodec/tablecodec_test.go +++ b/tablecodec/tablecodec_test.go @@ -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)) } } diff --git a/types/errors_test.go b/types/errors_test.go index 56aa43bfc9b98..6f7c92b613f3b 100644 --- a/types/errors_test.go +++ b/types/errors_test.go @@ -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)) } } diff --git a/util/admin/admin_test.go b/util/admin/admin_test.go index 235efbd99d829..28a6a8206fa93 100644 --- a/util/admin/admin_test.go +++ b/util/admin/admin_test.go @@ -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)) } } diff --git a/util/memory/tracker_test.go b/util/memory/tracker_test.go index f9f498cfee1ee..c6b4191595c77 100644 --- a/util/memory/tracker_test.go +++ b/util/memory/tracker_test.go @@ -21,7 +21,6 @@ import ( "github.com/cznic/mathutil" . "github.com/pingcap/check" - "github.com/pingcap/parser/terror" "github.com/pingcap/tidb/errno" "github.com/pingcap/tidb/util/logutil" "github.com/pingcap/tidb/util/testleak" @@ -339,5 +338,5 @@ func BenchmarkConsume(b *testing.B) { } func (s *testSuite) TestErrorCode(c *C) { - c.Assert(int(terror.ToSQLError(errMemExceedThreshold).Code), Equals, errno.ErrMemExceedThreshold) + c.Assert(int(errMemExceedThreshold.ToSQLError().Code), Equals, errno.ErrMemExceedThreshold) } diff --git a/util/testkit/testkit.go b/util/testkit/testkit.go index 00f12ced1c832..1ae061c3b0adc 100644 --- a/util/testkit/testkit.go +++ b/util/testkit/testkit.go @@ -279,7 +279,7 @@ func (tk *TestKit) MustGetErrCode(sql string, errCode int) { originErr := errors.Cause(err) tErr, ok := originErr.(*terror.Error) tk.c.Assert(ok, check.IsTrue, check.Commentf("expect type 'terror.Error', but obtain '%T'", originErr)) - sqlErr := terror.ToSQLError(tErr) + sqlErr := tErr.ToSQLError() tk.c.Assert(int(sqlErr.Code), check.Equals, errCode, check.Commentf("Assertion failed, origin err:\n %v", sqlErr)) }