diff --git a/go.mod b/go.mod index a85f206ca96a9..3ebebdccdd3d2 100644 --- a/go.mod +++ b/go.mod @@ -45,7 +45,7 @@ require ( github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2 github.com/pingcap/badger v1.5.1-0.20210831093107-2f6cb8008145 github.com/pingcap/check v0.0.0-20200212061837-5e12011dc712 - github.com/pingcap/errors v0.11.5-0.20210425183316-da1aaba5fb63 + github.com/pingcap/errors v0.11.5-0.20211009033009-93128226aaa3 github.com/pingcap/failpoint v0.0.0-20210316064728-7acb0f0a3dfd github.com/pingcap/fn v0.0.0-20200306044125-d5540d389059 github.com/pingcap/kvproto v0.0.0-20211011060348-d957056f1551 @@ -65,7 +65,7 @@ require ( github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.7.0 github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2 - github.com/tikv/client-go/v2 v2.0.0-alpha.0.20211029104011-2fd3841894de + github.com/tikv/client-go/v2 v2.0.0-alpha.0.20211101035952-9ec50224bea6 github.com/tikv/pd v1.1.0-beta.0.20211029083450-e65f0c55b6ae github.com/twmb/murmur3 v1.1.3 github.com/uber/jaeger-client-go v2.22.1+incompatible diff --git a/go.sum b/go.sum index 959251f13a227..b31db80825f54 100644 --- a/go.sum +++ b/go.sum @@ -570,8 +570,9 @@ github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTw github.com/pingcap/errors v0.11.5-0.20190809092503-95897b64e011/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8= github.com/pingcap/errors v0.11.5-0.20200917111840-a15ef68f753d/go.mod h1:g4vx//d6VakjJ0mk7iLBlKA8LFavV/sAVINT/1PFxeQ= github.com/pingcap/errors v0.11.5-0.20201126102027-b0a155152ca3/go.mod h1:G7x87le1poQzLB/TqvTJI2ILrSgobnq4Ut7luOwvfvI= -github.com/pingcap/errors v0.11.5-0.20210425183316-da1aaba5fb63 h1:+FZIDR/D97YOPik4N4lPDaUcLDF/EQPogxtlHB2ZZRM= github.com/pingcap/errors v0.11.5-0.20210425183316-da1aaba5fb63/go.mod h1:X2r9ueLEUZgtx2cIogM0v4Zj5uvvzhuuiu7Pn8HzMPg= +github.com/pingcap/errors v0.11.5-0.20211009033009-93128226aaa3 h1:8l9lu9RjWkI/VeqrP+Fn3tvZNPu5GYP0rYLLN5Q46go= +github.com/pingcap/errors v0.11.5-0.20211009033009-93128226aaa3/go.mod h1:X2r9ueLEUZgtx2cIogM0v4Zj5uvvzhuuiu7Pn8HzMPg= github.com/pingcap/failpoint v0.0.0-20191029060244-12f4ac2fd11d/go.mod h1:DNS3Qg7bEDhU6EXNHF+XSv/PGznQaMJ5FWvctpm6pQI= github.com/pingcap/failpoint v0.0.0-20200702092429-9f69995143ce/go.mod h1:w4PEZ5y16LeofeeGwdgZB4ddv9bLyDuIX+ljstgKZyk= github.com/pingcap/failpoint v0.0.0-20210316064728-7acb0f0a3dfd h1:I8IeI8MNiZVKnwuXhcIIzz6pREcOSbq18Q31KYIzFVM= @@ -711,8 +712,8 @@ github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2/go.mod h1:2PfK github.com/tidwall/gjson v1.3.5/go.mod h1:P256ACg0Mn+j1RXIDXoss50DeIABTYK1PULOJHhxOls= github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E= github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= -github.com/tikv/client-go/v2 v2.0.0-alpha.0.20211029104011-2fd3841894de h1:DKo2grkDpP9hQHuYbkAz4yxMS1742qBkUd4kwyZK2As= -github.com/tikv/client-go/v2 v2.0.0-alpha.0.20211029104011-2fd3841894de/go.mod h1:gdd4S4uS3/apOF9iet/DIYUdr6J4WzGLWyDgn6SMtg0= +github.com/tikv/client-go/v2 v2.0.0-alpha.0.20211101035952-9ec50224bea6 h1:hRn82rVDw91KBSoMT7eAv8qPIxFMU6+f5K35fP5ULbY= +github.com/tikv/client-go/v2 v2.0.0-alpha.0.20211101035952-9ec50224bea6/go.mod h1:iiwtsCxcbNLK5i9VRYGvdcihgHXTKy2ukWjoaJsrphg= github.com/tikv/pd v1.1.0-beta.0.20211029083450-e65f0c55b6ae h1:PmnkhiOopgMZYDQ7Htj1kt/zwW4MEOUL+Dem6WLZISY= github.com/tikv/pd v1.1.0-beta.0.20211029083450-e65f0c55b6ae/go.mod h1:varH0IE0jJ9E9WN2Ei/N6pajMlPkcXdDEf7f5mmsUVQ= github.com/tklauser/go-sysconf v0.3.4 h1:HT8SVixZd3IzLdfs/xlpq0jeSfTX57g1v6wB1EuzV7M= diff --git a/server/server_test.go b/server/server_test.go index b45f99d42f7f2..f34651791d545 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -2065,9 +2065,10 @@ func (cli *testServerClient) runTestInfoschemaClientErrors(t *C) { errCode: 1365, // div by zero }, { - stmt: "CREATE TABLE test_client_errors2 (a int primary key, b int primary key)", - incrementErrors: true, - errCode: 1068, // multiple pkeys + stmt: "CREATE TABLE test_client_errors2 (a int primary key, b int primary key)", + incrementWarnings: true, + incrementErrors: true, + errCode: 1068, // multiple pkeys }, { stmt: "gibberish", diff --git a/store/driver/error/error.go b/store/driver/error/error.go index 3a9841e7cef7d..8260acd2640bb 100644 --- a/store/driver/error/error.go +++ b/store/driver/error/error.go @@ -15,6 +15,8 @@ package error import ( + stderrs "errors" + "github.com/pingcap/errors" "github.com/pingcap/tidb/errno" "github.com/pingcap/tidb/kv" @@ -64,95 +66,99 @@ var ( // ToTiDBErr checks and converts a tikv error to a tidb error. func ToTiDBErr(err error) error { - originErr := err if err == nil { return nil } - err = errors.Cause(err) if tikverr.IsErrNotFound(err) { return kv.ErrNotExist } - if e, ok := err.(*tikverr.ErrWriteConflictInLatch); ok { - return kv.ErrWriteConflictInTiDB.FastGenByArgs(e.StartTS) + var writeConflictInLatch *tikverr.ErrWriteConflictInLatch + if stderrs.As(err, &writeConflictInLatch) { + return kv.ErrWriteConflictInTiDB.FastGenByArgs(writeConflictInLatch.StartTS) } - if e, ok := err.(*tikverr.ErrTxnTooLarge); ok { - return kv.ErrTxnTooLarge.GenWithStackByArgs(e.Size) + var txnTooLarge *tikverr.ErrTxnTooLarge + if stderrs.As(err, &txnTooLarge) { + return kv.ErrTxnTooLarge.GenWithStackByArgs(txnTooLarge.Size) } - if errors.ErrorEqual(err, tikverr.ErrCannotSetNilValue) { + if stderrs.Is(err, tikverr.ErrCannotSetNilValue) { return kv.ErrCannotSetNilValue } - if e, ok := err.(*tikverr.ErrEntryTooLarge); ok { - return kv.ErrEntryTooLarge.GenWithStackByArgs(e.Limit, e.Size) + var entryTooLarge *tikverr.ErrEntryTooLarge + if stderrs.As(err, &entryTooLarge) { + return kv.ErrEntryTooLarge.GenWithStackByArgs(entryTooLarge.Limit, entryTooLarge.Size) } - if errors.ErrorEqual(err, tikverr.ErrInvalidTxn) { + if stderrs.Is(err, tikverr.ErrInvalidTxn) { return kv.ErrInvalidTxn } - if errors.ErrorEqual(err, tikverr.ErrTiKVServerTimeout) { + if stderrs.Is(err, tikverr.ErrTiKVServerTimeout) { return ErrTiKVServerTimeout } - if e, ok := err.(*tikverr.ErrPDServerTimeout); ok { - if len(e.Error()) == 0 { + var pdServerTimeout *tikverr.ErrPDServerTimeout + if stderrs.As(err, &pdServerTimeout) { + if len(pdServerTimeout.Error()) == 0 { return ErrPDServerTimeout } - return ErrPDServerTimeout.GenWithStackByArgs(e.Error()) + return ErrPDServerTimeout.GenWithStackByArgs(pdServerTimeout.Error()) } - if errors.ErrorEqual(err, tikverr.ErrTiFlashServerTimeout) { + if stderrs.Is(err, tikverr.ErrTiFlashServerTimeout) { return ErrTiFlashServerTimeout } - if errors.ErrorEqual(err, tikverr.ErrQueryInterrupted) { + if stderrs.Is(err, tikverr.ErrQueryInterrupted) { return ErrQueryInterrupted } - if errors.ErrorEqual(err, tikverr.ErrTiKVServerBusy) { + if stderrs.Is(err, tikverr.ErrTiKVServerBusy) { return ErrTiKVServerBusy } - if errors.ErrorEqual(err, tikverr.ErrTiFlashServerBusy) { + if stderrs.Is(err, tikverr.ErrTiFlashServerBusy) { return ErrTiFlashServerBusy } - if e, ok := err.(*tikverr.ErrGCTooEarly); ok { - return ErrGCTooEarly.GenWithStackByArgs(e.TxnStartTS, e.GCSafePoint) + var gcTooEarly *tikverr.ErrGCTooEarly + if stderrs.As(err, &gcTooEarly) { + return ErrGCTooEarly.GenWithStackByArgs(gcTooEarly.TxnStartTS, gcTooEarly.GCSafePoint) } - if errors.ErrorEqual(err, tikverr.ErrTiKVStaleCommand) { + if stderrs.Is(err, tikverr.ErrTiKVStaleCommand) { return ErrTiKVStaleCommand } - if errors.ErrorEqual(err, tikverr.ErrTiKVMaxTimestampNotSynced) { + if stderrs.Is(err, tikverr.ErrTiKVMaxTimestampNotSynced) { return ErrTiKVMaxTimestampNotSynced } - if errors.ErrorEqual(err, tikverr.ErrLockAcquireFailAndNoWaitSet) { + if stderrs.Is(err, tikverr.ErrLockAcquireFailAndNoWaitSet) { return ErrLockAcquireFailAndNoWaitSet } - if errors.ErrorEqual(err, tikverr.ErrResolveLockTimeout) { + if stderrs.Is(err, tikverr.ErrResolveLockTimeout) { return ErrResolveLockTimeout } - if errors.ErrorEqual(err, tikverr.ErrLockWaitTimeout) { + if stderrs.Is(err, tikverr.ErrLockWaitTimeout) { return ErrLockWaitTimeout } - if errors.ErrorEqual(err, tikverr.ErrRegionUnavailable) { + if stderrs.Is(err, tikverr.ErrRegionUnavailable) { return ErrRegionUnavailable } - if e, ok := err.(*tikverr.ErrTokenLimit); ok { - return ErrTokenLimit.GenWithStackByArgs(e.StoreID) + var tokenLimit *tikverr.ErrTokenLimit + if stderrs.As(err, &tokenLimit) { + return ErrTokenLimit.GenWithStackByArgs(tokenLimit.StoreID) } - if errors.ErrorEqual(err, tikverr.ErrUnknown) { + if stderrs.Is(err, tikverr.ErrUnknown) { return ErrUnknown } @@ -160,5 +166,5 @@ func ToTiDBErr(err error) error { return terror.ErrResultUndetermined } - return errors.Trace(originErr) + return errors.Trace(err) }