From cb03f2bec151033a38dfd17715a42cf3728b0541 Mon Sep 17 00:00:00 2001 From: lysu Date: Wed, 12 Sep 2018 15:42:20 +0800 Subject: [PATCH] move from juju/errors to pkg/errors (#7151) --- Gopkg.lock | 20 +- Gopkg.toml | 6 + cmd/benchfilesort/main.go | 2 +- cmd/benchkv/main.go | 2 +- cmd/benchraw/main.go | 2 +- cmd/explaintest/main.go | 2 +- cmd/importer/config.go | 2 +- cmd/importer/db.go | 2 +- cmd/importer/job.go | 2 +- cmd/importer/main.go | 2 +- cmd/importer/parser.go | 2 +- cmd/importer/stats.go | 2 +- config/config.go | 2 +- ddl/column.go | 22 +- ddl/column_change_test.go | 2 +- ddl/column_test.go | 8 +- ddl/db_change_test.go | 2 +- ddl/db_integration_test.go | 2 +- ddl/db_test.go | 16 +- ddl/ddl.go | 2 +- ddl/ddl_api.go | 202 +++++------ ddl/ddl_worker.go | 6 +- ddl/ddl_worker_test.go | 2 +- ddl/delete_range.go | 2 +- ddl/foreign_key.go | 8 +- ddl/foreign_key_test.go | 2 +- ddl/generated_column.go | 10 +- ddl/index.go | 26 +- ddl/index_change_test.go | 2 +- ddl/mock.go | 2 +- ddl/partition.go | 16 +- ddl/reorg.go | 6 +- ddl/schema.go | 6 +- ddl/session_pool.go | 2 +- ddl/stat.go | 2 +- ddl/syncer.go | 2 +- ddl/table.go | 20 +- ddl/table_test.go | 2 +- ddl/util/util.go | 2 +- distsql/distsql.go | 2 +- distsql/distsql_test.go | 2 +- distsql/request_builder.go | 2 +- distsql/select_result.go | 2 +- distsql/stream.go | 2 +- domain/domain.go | 2 +- domain/domain_test.go | 2 +- domain/info.go | 2 +- executor/adapter.go | 2 +- executor/admin.go | 2 +- executor/aggfuncs/builder.go | 2 +- executor/aggfuncs/func_avg.go | 2 +- executor/aggfuncs/func_bitfuncs.go | 2 +- executor/aggfuncs/func_count.go | 2 +- executor/aggfuncs/func_first_row.go | 2 +- executor/aggfuncs/func_group_concat.go | 2 +- executor/aggfuncs/func_max_min.go | 2 +- executor/aggfuncs/func_sum.go | 2 +- executor/aggregate.go | 2 +- executor/analyze.go | 2 +- executor/batch_checker.go | 2 +- executor/builder.go | 4 +- executor/checksum.go | 2 +- executor/compiler.go | 2 +- executor/ddl.go | 6 +- executor/delete.go | 4 +- executor/distsql.go | 2 +- executor/executor.go | 4 +- executor/executor_test.go | 20 +- executor/grant.go | 2 +- executor/index_lookup_join.go | 2 +- executor/insert.go | 2 +- executor/insert_common.go | 8 +- executor/join.go | 2 +- executor/joiner.go | 2 +- executor/load_data.go | 2 +- executor/load_stats.go | 2 +- executor/merge_join.go | 2 +- executor/point_get.go | 4 +- executor/prepared.go | 2 +- executor/prepared_test.go | 2 +- executor/projection.go | 2 +- executor/replace.go | 2 +- executor/revoke.go | 2 +- executor/set.go | 6 +- executor/show.go | 4 +- executor/show_stats.go | 2 +- executor/show_test.go | 2 +- executor/simple.go | 8 +- executor/simple_test.go | 4 +- executor/sort.go | 2 +- executor/table_reader.go | 2 +- executor/trace.go | 2 +- executor/union_scan.go | 2 +- executor/update.go | 2 +- executor/write.go | 8 +- expression/aggregation/aggregation.go | 2 +- expression/aggregation/avg.go | 2 +- expression/aggregation/bit_and.go | 2 +- expression/aggregation/bit_or.go | 2 +- expression/aggregation/bit_xor.go | 2 +- expression/aggregation/concat.go | 2 +- expression/aggregation/count.go | 2 +- expression/aggregation/first_row.go | 2 +- expression/aggregation/max_min.go | 2 +- expression/aggregation/util.go | 2 +- expression/builtin.go | 2 +- expression/builtin_arithmetic.go | 48 +-- expression/builtin_cast.go | 6 +- expression/builtin_compare.go | 2 +- expression/builtin_compare_test.go | 2 +- expression/builtin_control.go | 2 +- expression/builtin_encryption.go | 16 +- expression/builtin_info.go | 10 +- expression/builtin_json.go | 36 +- expression/builtin_like.go | 6 +- expression/builtin_math.go | 12 +- expression/builtin_miscellaneous.go | 22 +- expression/builtin_op.go | 6 +- expression/builtin_op_test.go | 2 +- expression/builtin_other.go | 2 +- expression/builtin_string.go | 26 +- expression/builtin_string_test.go | 2 +- expression/builtin_test.go | 4 +- expression/builtin_time.go | 70 ++-- expression/builtin_time_test.go | 2 +- expression/chunk_executor.go | 2 +- expression/column.go | 2 +- expression/constant.go | 2 +- expression/constant_propagation.go | 2 +- expression/distsql_builtin.go | 4 +- expression/evaluator.go | 2 +- expression/expr_to_pb.go | 2 +- expression/expression.go | 2 +- expression/helper.go | 2 +- expression/integration_test.go | 38 +- expression/scalar_function.go | 4 +- expression/schema.go | 2 +- expression/simple_rewriter.go | 18 +- expression/util.go | 4 +- infoschema/builder.go | 10 +- infoschema/infoschema.go | 2 +- infoschema/infoschema_test.go | 2 +- infoschema/tables.go | 2 +- kv/buffer_store.go | 2 +- kv/fault_injection_test.go | 2 +- kv/iter.go | 2 +- kv/memdb_buffer.go | 8 +- kv/mock.go | 2 +- kv/txn.go | 2 +- kv/union_iter.go | 2 +- kv/union_store.go | 2 +- kv/utils.go | 2 +- meta/autoid/autoid.go | 8 +- meta/autoid/autoid_test.go | 2 +- meta/meta.go | 2 +- metrics/server.go | 2 +- model/ddl.go | 2 +- model/model.go | 4 +- mysql/locale_format.go | 2 +- owner/manager.go | 2 +- owner/mock.go | 2 +- parser/parser_test.go | 2 +- parser/yy_parser.go | 6 +- plan/cbo_test.go | 2 +- plan/common_plans.go | 4 +- plan/exhaust_physical_plans.go | 2 +- plan/expression_rewriter.go | 32 +- plan/find_best_task.go | 2 +- plan/logical_plan_builder.go | 40 +-- plan/logical_plans.go | 2 +- plan/logical_plans_test.go | 2 +- plan/optimizer.go | 4 +- plan/plan.go | 2 +- plan/plan_to_pb.go | 2 +- plan/planbuilder.go | 38 +- plan/point_get_plan.go | 2 +- plan/preprocess.go | 62 ++-- plan/preprocess_test.go | 4 +- plan/rule_decorrelate.go | 2 +- plan/rule_partition_processor.go | 2 +- plan/stats.go | 2 +- privilege/privileges/cache.go | 6 +- server/conn.go | 6 +- server/conn_stmt.go | 4 +- server/driver_tidb.go | 2 +- server/http_handler.go | 8 +- server/http_status.go | 2 +- server/packetio.go | 4 +- server/server.go | 2 +- server/tidb_test.go | 2 +- server/util.go | 6 +- server/util_test.go | 2 +- session/bootstrap.go | 2 +- session/session.go | 6 +- session/tidb.go | 2 +- session/tidb_test.go | 2 +- session/txn.go | 2 +- sessionctx/binloginfo/binloginfo.go | 4 +- sessionctx/binloginfo/binloginfo_test.go | 2 +- sessionctx/variable/session.go | 2 +- sessionctx/variable/statusvar.go | 2 +- sessionctx/variable/varsutil.go | 48 +-- statistics/bootstrap.go | 2 +- statistics/builder.go | 2 +- statistics/cmsketch.go | 2 +- statistics/cmsketch_test.go | 2 +- statistics/ddl.go | 2 +- statistics/dump.go | 2 +- statistics/feedback.go | 2 +- statistics/fmsketch.go | 2 +- statistics/gc.go | 2 +- statistics/handle.go | 2 +- statistics/handle_test.go | 2 +- statistics/histogram.go | 2 +- statistics/sample.go | 2 +- statistics/selectivity.go | 2 +- statistics/statistics_test.go | 2 +- statistics/table.go | 2 +- statistics/update.go | 2 +- store/mockoracle/oracle.go | 2 +- store/mockstore/mocktikv/aggregate.go | 2 +- store/mockstore/mocktikv/analyze.go | 2 +- store/mockstore/mocktikv/cop_handler_dag.go | 2 +- store/mockstore/mocktikv/executor.go | 2 +- store/mockstore/mocktikv/mock.go | 2 +- store/mockstore/mocktikv/mvcc.go | 2 +- store/mockstore/mocktikv/mvcc_leveldb.go | 2 +- store/mockstore/mocktikv/rpc.go | 2 +- store/mockstore/mocktikv/topn.go | 2 +- store/mockstore/tikv.go | 2 +- store/tikv/2pc.go | 5 +- store/tikv/2pc_fail_test.go | 2 +- store/tikv/2pc_test.go | 2 +- store/tikv/backoff.go | 6 +- store/tikv/client.go | 2 +- store/tikv/coprocessor.go | 2 +- store/tikv/delete_range.go | 2 +- store/tikv/error.go | 2 +- store/tikv/gcworker/gc_worker.go | 2 +- store/tikv/kv.go | 6 +- store/tikv/lock_resolver.go | 2 +- store/tikv/oracle/oracles/pd.go | 2 +- store/tikv/pd_codec.go | 2 +- store/tikv/rawkv.go | 2 +- store/tikv/region_cache.go | 2 +- store/tikv/region_request.go | 2 +- store/tikv/region_request_test.go | 2 +- store/tikv/safepoint.go | 2 +- store/tikv/safepoint_test.go | 8 +- store/tikv/scan.go | 2 +- store/tikv/snapshot.go | 2 +- store/tikv/split_region.go | 2 +- store/tikv/store_test.go | 2 +- store/tikv/test_util.go | 2 +- store/tikv/ticlient_test.go | 2 +- store/tikv/tikvrpc/tikvrpc.go | 2 +- store/tikv/txn.go | 2 +- structure/hash.go | 2 +- structure/list.go | 4 +- structure/string.go | 2 +- structure/type.go | 4 +- table/column.go | 14 +- table/tables/gen_expr.go | 2 +- table/tables/index.go | 4 +- table/tables/partition.go | 2 +- table/tables/tables.go | 8 +- tablecodec/tablecodec.go | 20 +- terror/terror.go | 19 +- terror/terror_test.go | 19 +- tidb-server/main.go | 2 +- types/binary_literal.go | 4 +- types/convert.go | 18 +- types/convert_test.go | 2 +- types/datum.go | 22 +- types/datum_eval.go | 2 +- types/enum.go | 2 +- types/etc.go | 4 +- types/fsp.go | 2 +- types/helper.go | 8 +- types/helper_test.go | 2 +- types/json/binary.go | 6 +- types/json/binary_functions.go | 2 +- types/json/path_expr.go | 14 +- types/mydecimal.go | 2 +- types/mytime.go | 4 +- types/overflow.go | 28 +- types/set.go | 2 +- types/time.go | 124 +++---- util/admin/admin.go | 22 +- util/auth/auth.go | 2 +- util/charset/charset.go | 2 +- util/chunk/list.go | 2 +- util/codec/bytes.go | 2 +- util/codec/codec.go | 2 +- util/codec/decimal.go | 2 +- util/codec/float.go | 2 +- util/codec/number.go | 2 +- util/encrypt/aes.go | 2 +- util/filesort/filesort.go | 2 +- util/kvencoder/kv_encoder.go | 2 +- util/kvencoder/kv_encoder_test.go | 2 +- util/logutil/log.go | 2 +- util/memory/action.go | 2 +- util/misc.go | 2 +- util/misc_test.go | 2 +- util/mock/context.go | 6 +- util/prefix_helper.go | 2 +- util/ranger/detacher.go | 2 +- util/ranger/points.go | 8 +- util/ranger/ranger.go | 2 +- util/ranger/ranger_test.go | 2 +- util/ranger/types.go | 2 +- util/stringutil/string_util.go | 2 +- util/testkit/testkit.go | 2 +- vendor/github.com/juju/errors/LICENSE | 191 ---------- vendor/github.com/juju/errors/doc.go | 81 ----- vendor/github.com/juju/errors/error.go | 145 -------- vendor/github.com/juju/errors/errortypes.go | 284 --------------- vendor/github.com/juju/errors/functions.go | 330 ------------------ vendor/github.com/juju/errors/path.go | 38 -- .../github.com/pingcap/pd/pd-client/client.go | 40 +-- vendor/github.com/pkg/errors/errors.go | 150 +++++--- vendor/github.com/pkg/errors/group.go | 33 ++ vendor/github.com/pkg/errors/juju_adaptor.go | 76 ++++ vendor/github.com/pkg/errors/stack.go | 72 ++-- x-server/conn.go | 2 +- x-server/server.go | 2 +- 327 files changed, 1239 insertions(+), 2134 deletions(-) delete mode 100644 vendor/github.com/juju/errors/LICENSE delete mode 100644 vendor/github.com/juju/errors/doc.go delete mode 100644 vendor/github.com/juju/errors/error.go delete mode 100644 vendor/github.com/juju/errors/errortypes.go delete mode 100644 vendor/github.com/juju/errors/functions.go delete mode 100644 vendor/github.com/juju/errors/path.go create mode 100644 vendor/github.com/pkg/errors/group.go create mode 100644 vendor/github.com/pkg/errors/juju_adaptor.go diff --git a/Gopkg.lock b/Gopkg.lock index 17c60e99682c9..6c299c8305fcc 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -189,13 +189,6 @@ revision = "6b7015e65d366bf3f19b2b2a000a831940f0f7e0" version = "v1.1" -[[projects]] - digest = "1:e8fd2854e80293d75ff2aab6df2ea0887bb604c2119f343dbd63e25dcf9f10ef" - name = "github.com/juju/errors" - packages = ["."] - pruneopts = "NUT" - revision = "b2c7a7da5b2995941048f60146e67702a292e468" - [[projects]] branch = "master" digest = "1:5985ef4caf91ece5d54817c11ea25f182697534f8ae6521eadcd628c142ac4b6" @@ -298,11 +291,11 @@ [[projects]] branch = "master" - digest = "1:6a846fb5ccc09741c0735f9e9897bbc95915314fab98c5ee56680f1a9591d48d" + digest = "1:2c64fe28351dc49da088194d80faceb34186e080a60c649694d094b2ccccacf5" name = "github.com/pingcap/pd" packages = ["pd-client"] pruneopts = "NUT" - revision = "5d1bac04f3eab9842ee0988ed46c483d2ce4e854" + revision = "b5992e356ff447a6fdaa450b3f5ea33afbd11680" [[projects]] branch = "master" @@ -317,12 +310,13 @@ revision = "371b48b15d93924a3a5375019e42b4420bc13d17" [[projects]] - digest = "1:5cf3f025cbee5951a4ee961de067c8a89fc95a5adabead774f82822efabab121" + digest = "1:91fee14a873676b2118c54e08c2e04897ea5c141b55a9b9fb8cf0721458d0d85" name = "github.com/pkg/errors" packages = ["."] pruneopts = "NUT" - revision = "645ef00459ed84a119197bfb8d8205042c6df63d" - version = "v0.8.0" + revision = "9316aeb006f59424c65ff505c217f90c43d6445d" + source = "https://github.com/pingcap/errors.git" + version = "v0.9.0" [[projects]] digest = "1:1ef3c4d6e78616bd3d1b5b7d8899febb9aa1b83d3373fbbdc2804408c7977b57" @@ -537,7 +531,6 @@ "github.com/grpc-ecosystem/go-grpc-middleware", "github.com/grpc-ecosystem/go-grpc-middleware/tracing/opentracing", "github.com/grpc-ecosystem/go-grpc-prometheus", - "github.com/juju/errors", "github.com/ngaut/pools", "github.com/opentracing/basictracer-go", "github.com/opentracing/opentracing-go", @@ -557,6 +550,7 @@ "github.com/pingcap/pd/pd-client", "github.com/pingcap/tipb/go-binlog", "github.com/pingcap/tipb/go-tipb", + "github.com/pkg/errors", "github.com/prometheus/client_golang/prometheus", "github.com/prometheus/client_golang/prometheus/push", "github.com/sirupsen/logrus", diff --git a/Gopkg.toml b/Gopkg.toml index a92fe3b90ec89..cd91b8d52d6ec 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -96,3 +96,9 @@ required = ["github.com/golang/protobuf/jsonpb"] [[constraint]] branch = "master" name = "github.com/pingcap/tipb" + +[[constraint]] + name = "github.com/pkg/errors" + version = "0.9.0" + source = "https://github.com/pingcap/errors.git" + diff --git a/cmd/benchfilesort/main.go b/cmd/benchfilesort/main.go index 29e2dda7de15b..296afe0554bb6 100644 --- a/cmd/benchfilesort/main.go +++ b/cmd/benchfilesort/main.go @@ -24,13 +24,13 @@ import ( "runtime/pprof" "time" - "github.com/juju/errors" "github.com/pingcap/tidb/sessionctx/stmtctx" "github.com/pingcap/tidb/terror" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/codec" "github.com/pingcap/tidb/util/filesort" "github.com/pingcap/tidb/util/logutil" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" ) diff --git a/cmd/benchkv/main.go b/cmd/benchkv/main.go index 184b7e067ab22..06d35ec9a0139 100644 --- a/cmd/benchkv/main.go +++ b/cmd/benchkv/main.go @@ -24,10 +24,10 @@ import ( _ "github.com/go-sql-driver/mysql" - "github.com/juju/errors" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/store/tikv" "github.com/pingcap/tidb/terror" + "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" log "github.com/sirupsen/logrus" "golang.org/x/net/context" diff --git a/cmd/benchraw/main.go b/cmd/benchraw/main.go index 4ad035214833b..fcbc3ec428101 100644 --- a/cmd/benchraw/main.go +++ b/cmd/benchraw/main.go @@ -22,10 +22,10 @@ import ( "sync" "time" - "github.com/juju/errors" "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/store/tikv" "github.com/pingcap/tidb/terror" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" ) diff --git a/cmd/explaintest/main.go b/cmd/explaintest/main.go index 2bb759e55b11e..2da89d708e071 100644 --- a/cmd/explaintest/main.go +++ b/cmd/explaintest/main.go @@ -26,12 +26,12 @@ import ( "flag" "github.com/go-sql-driver/mysql" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/session" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/util/logutil" "github.com/pingcap/tidb/util/mock" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "time" ) diff --git a/cmd/importer/config.go b/cmd/importer/config.go index 2917aca41bdff..62f6eb74ba3a5 100644 --- a/cmd/importer/config.go +++ b/cmd/importer/config.go @@ -18,7 +18,7 @@ import ( "fmt" "github.com/BurntSushi/toml" - "github.com/juju/errors" + "github.com/pkg/errors" ) // NewConfig creates a new config. diff --git a/cmd/importer/db.go b/cmd/importer/db.go index dec7a46ac7a02..5f5d174bc3f45 100644 --- a/cmd/importer/db.go +++ b/cmd/importer/db.go @@ -21,8 +21,8 @@ import ( "strings" _ "github.com/go-sql-driver/mysql" - "github.com/juju/errors" "github.com/pingcap/tidb/mysql" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" ) diff --git a/cmd/importer/job.go b/cmd/importer/job.go index 5840d81288cd8..50d38fd400112 100644 --- a/cmd/importer/job.go +++ b/cmd/importer/job.go @@ -18,7 +18,7 @@ import ( "fmt" "time" - "github.com/juju/errors" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" ) diff --git a/cmd/importer/main.go b/cmd/importer/main.go index 252773e70fd2e..923fd5d655512 100644 --- a/cmd/importer/main.go +++ b/cmd/importer/main.go @@ -17,7 +17,7 @@ import ( "flag" "os" - "github.com/juju/errors" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" ) diff --git a/cmd/importer/parser.go b/cmd/importer/parser.go index 317f22d80097b..760b63b1212e7 100644 --- a/cmd/importer/parser.go +++ b/cmd/importer/parser.go @@ -18,7 +18,6 @@ import ( "strconv" "strings" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/ddl" "github.com/pingcap/tidb/model" @@ -26,6 +25,7 @@ import ( _ "github.com/pingcap/tidb/plan" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/mock" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" ) diff --git a/cmd/importer/stats.go b/cmd/importer/stats.go index fb547f63d319d..89c7738e8d245 100644 --- a/cmd/importer/stats.go +++ b/cmd/importer/stats.go @@ -19,13 +19,13 @@ import ( "math/rand" "time" - "github.com/juju/errors" "github.com/pingcap/tidb/model" stats "github.com/pingcap/tidb/statistics" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/codec" "github.com/pingcap/tidb/util/mock" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" ) diff --git a/config/config.go b/config/config.go index 7f2ce64441a9d..fff33402b6afd 100644 --- a/config/config.go +++ b/config/config.go @@ -20,8 +20,8 @@ import ( "time" "github.com/BurntSushi/toml" - "github.com/juju/errors" "github.com/pingcap/tidb/util/logutil" + "github.com/pkg/errors" tracing "github.com/uber/jaeger-client-go/config" ) diff --git a/ddl/column.go b/ddl/column.go index ff06260ba24ec..ace6ad60c2a83 100644 --- a/ddl/column.go +++ b/ddl/column.go @@ -14,12 +14,12 @@ package ddl import ( - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/ddl/util" "github.com/pingcap/tidb/infoschema" "github.com/pingcap/tidb/meta" "github.com/pingcap/tidb/model" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" ) @@ -93,7 +93,7 @@ func createColumnInfo(tblInfo *model.TableInfo, colInfo *model.ColumnInfo, pos * } else if pos.Tp == ast.ColumnPositionAfter { c := model.FindColumnInfo(cols, pos.RelativeColumn.Name.L) if c == nil { - return nil, 0, infoschema.ErrColumnNotExists.GenByArgs(pos.RelativeColumn, tblInfo.Name) + return nil, 0, infoschema.ErrColumnNotExists.GenWithStackByArgs(pos.RelativeColumn, tblInfo.Name) } // Insert position is after the mentioned column. @@ -139,7 +139,7 @@ func onAddColumn(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64, _ error) { if columnInfo.State == model.StatePublic { // We already have a column with the same column name. job.State = model.JobStateCancelled - return ver, infoschema.ErrColumnExists.GenByArgs(col.Name) + return ver, infoschema.ErrColumnExists.GenWithStackByArgs(col.Name) } } else { columnInfo, offset, err = createColumnInfo(tblInfo, col, pos) @@ -189,7 +189,7 @@ func onAddColumn(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64, _ error) { job.FinishTableJob(model.JobStateDone, model.StatePublic, ver, tblInfo) asyncNotifyEvent(d, &util.Event{Tp: model.ActionAddColumn, TableInfo: tblInfo, ColumnInfo: columnInfo}) default: - err = ErrInvalidColumnState.Gen("invalid column state %v", columnInfo.State) + err = ErrInvalidColumnState.GenWithStack("invalid column state %v", columnInfo.State) } return ver, errors.Trace(err) @@ -212,7 +212,7 @@ func onDropColumn(t *meta.Meta, job *model.Job) (ver int64, _ error) { colInfo := model.FindColumnInfo(tblInfo.Columns, colName.L) if colInfo == nil { job.State = model.JobStateCancelled - return ver, ErrCantDropFieldOrKey.Gen("column %s doesn't exist", colName) + return ver, ErrCantDropFieldOrKey.GenWithStack("column %s doesn't exist", colName) } if err = isDroppableColumn(tblInfo, colName); err != nil { job.State = model.JobStateCancelled @@ -251,7 +251,7 @@ func onDropColumn(t *meta.Meta, job *model.Job) (ver int64, _ error) { // Finish this job. job.FinishTableJob(model.JobStateDone, model.StateNone, ver, tblInfo) default: - err = ErrInvalidTableState.Gen("invalid table state %v", tblInfo.State) + err = ErrInvalidTableState.GenWithStack("invalid table state %v", tblInfo.State) } return ver, errors.Trace(err) } @@ -290,14 +290,14 @@ func doModifyColumn(t *meta.Meta, job *model.Job, newCol *model.ColumnInfo, oldN oldCol := model.FindColumnInfo(tblInfo.Columns, oldName.L) if oldCol == nil || oldCol.State != model.StatePublic { job.State = model.JobStateCancelled - return ver, infoschema.ErrColumnNotExists.GenByArgs(oldName, tblInfo.Name) + return ver, infoschema.ErrColumnNotExists.GenWithStackByArgs(oldName, tblInfo.Name) } // If we want to rename the column name, we need to check whether it already exists. if newCol.Name.L != oldName.L { c := model.FindColumnInfo(tblInfo.Columns, newCol.Name.L) if c != nil { job.State = model.JobStateCancelled - return ver, infoschema.ErrColumnExists.GenByArgs(newCol.Name) + return ver, infoschema.ErrColumnExists.GenWithStackByArgs(newCol.Name) } } @@ -317,13 +317,13 @@ func doModifyColumn(t *meta.Meta, job *model.Job, newCol *model.ColumnInfo, oldN if oldName.L == pos.RelativeColumn.Name.L { // `alter table tableName modify column b int after b` will return ver,ErrColumnNotExists. job.State = model.JobStateCancelled - return ver, infoschema.ErrColumnNotExists.GenByArgs(oldName, tblInfo.Name) + return ver, infoschema.ErrColumnNotExists.GenWithStackByArgs(oldName, tblInfo.Name) } relative := model.FindColumnInfo(tblInfo.Columns, pos.RelativeColumn.Name.L) if relative == nil || relative.State != model.StatePublic { job.State = model.JobStateCancelled - return ver, infoschema.ErrColumnNotExists.GenByArgs(pos.RelativeColumn, tblInfo.Name) + return ver, infoschema.ErrColumnNotExists.GenWithStackByArgs(pos.RelativeColumn, tblInfo.Name) } if relative.Offset < oldPos { @@ -387,7 +387,7 @@ func updateColumn(t *meta.Meta, job *model.Job, newCol *model.ColumnInfo, oldCol oldCol := model.FindColumnInfo(tblInfo.Columns, oldColName.L) if oldCol == nil || oldCol.State != model.StatePublic { job.State = model.JobStateCancelled - return ver, infoschema.ErrColumnNotExists.GenByArgs(newCol.Name, tblInfo.Name) + return ver, infoschema.ErrColumnNotExists.GenWithStackByArgs(newCol.Name, tblInfo.Name) } *oldCol = *newCol diff --git a/ddl/column_change_test.go b/ddl/column_change_test.go index 16977e39ef66a..9ea837ae0a5b1 100644 --- a/ddl/column_change_test.go +++ b/ddl/column_change_test.go @@ -18,7 +18,6 @@ import ( "sync" "time" - "github.com/juju/errors" . "github.com/pingcap/check" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/kv" @@ -31,6 +30,7 @@ import ( "github.com/pingcap/tidb/util/mock" "github.com/pingcap/tidb/util/testleak" "github.com/pingcap/tidb/util/testutil" + "github.com/pkg/errors" "golang.org/x/net/context" ) diff --git a/ddl/column_test.go b/ddl/column_test.go index 00c7cba1267b4..4eea2c9b862d0 100644 --- a/ddl/column_test.go +++ b/ddl/column_test.go @@ -17,7 +17,6 @@ import ( "reflect" "sync" - "github.com/juju/errors" . "github.com/pingcap/check" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/kv" @@ -31,6 +30,7 @@ import ( "github.com/pingcap/tidb/terror" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/testleak" + "github.com/pkg/errors" "golang.org/x/net/context" ) @@ -912,11 +912,11 @@ func (s *testColumnSuite) TestModifyColumn(c *C) { err error }{ {"int", "bigint", nil}, - {"int", "int unsigned", errUnsupportedModifyColumn.GenByArgs("length 10 is less than origin 11")}, + {"int", "int unsigned", errUnsupportedModifyColumn.GenWithStackByArgs("length 10 is less than origin 11")}, {"varchar(10)", "text", nil}, {"varbinary(10)", "blob", nil}, - {"text", "blob", errUnsupportedModifyColumn.GenByArgs("charset binary not match origin utf8")}, - {"varchar(10)", "varchar(8)", errUnsupportedModifyColumn.GenByArgs("length 8 is less than origin 10")}, + {"text", "blob", errUnsupportedModifyColumn.GenWithStackByArgs("charset binary not match origin utf8")}, + {"varchar(10)", "varchar(8)", errUnsupportedModifyColumn.GenWithStackByArgs("length 8 is less than origin 10")}, {"varchar(10)", "varchar(11)", nil}, {"varchar(10) character set utf8 collate utf8_bin", "varchar(10) character set utf8", nil}, } diff --git a/ddl/db_change_test.go b/ddl/db_change_test.go index 416b009d61cd0..33eb71eee0bf0 100644 --- a/ddl/db_change_test.go +++ b/ddl/db_change_test.go @@ -20,7 +20,6 @@ import ( "sync/atomic" "time" - "github.com/juju/errors" . "github.com/pingcap/check" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/ddl" @@ -37,6 +36,7 @@ import ( "github.com/pingcap/tidb/util/admin" "github.com/pingcap/tidb/util/testkit" "github.com/pingcap/tidb/util/testleak" + "github.com/pkg/errors" "golang.org/x/net/context" ) diff --git a/ddl/db_integration_test.go b/ddl/db_integration_test.go index e4a54fccdf1c6..77f03ba8ad119 100644 --- a/ddl/db_integration_test.go +++ b/ddl/db_integration_test.go @@ -16,7 +16,6 @@ package ddl_test import ( "fmt" - "github.com/juju/errors" . "github.com/pingcap/check" "github.com/pingcap/tidb/ddl" "github.com/pingcap/tidb/domain" @@ -31,6 +30,7 @@ import ( "github.com/pingcap/tidb/util/mock" "github.com/pingcap/tidb/util/testkit" "github.com/pingcap/tidb/util/testleak" + "github.com/pkg/errors" ) var _ = Suite(&testIntegrationSuite{}) diff --git a/ddl/db_test.go b/ddl/db_test.go index 42d48a459fc4c..e7a4f3a687fa7 100644 --- a/ddl/db_test.go +++ b/ddl/db_test.go @@ -23,7 +23,6 @@ import ( "sync" "time" - "github.com/juju/errors" . "github.com/pingcap/check" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/ddl" @@ -49,6 +48,7 @@ import ( "github.com/pingcap/tidb/util/testkit" "github.com/pingcap/tidb/util/testleak" "github.com/pingcap/tidb/util/testutil" + "github.com/pkg/errors" "golang.org/x/net/context" ) @@ -818,21 +818,21 @@ func checkDelRangeDone(c *C, ctx sessionctx.Context, idx table.Index) { func (s *testDBSuite) TestAddIndexWithDupCols(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use " + s.schemaName) - err1 := infoschema.ErrColumnExists.GenByArgs("b") - err2 := infoschema.ErrColumnExists.GenByArgs("B") + err1 := infoschema.ErrColumnExists.GenWithStackByArgs("b") + err2 := infoschema.ErrColumnExists.GenWithStackByArgs("B") s.tk.MustExec("create table test_add_index_with_dup (a int, b int)") _, err := s.tk.Exec("create index c on test_add_index_with_dup(b, a, b)") - c.Check(err1.Equal(err), Equals, true) + c.Check(errors.Cause(err1).(*terror.Error).Equal(err), Equals, true) _, err = s.tk.Exec("create index c on test_add_index_with_dup(b, a, B)") - c.Check(err2.Equal(err), Equals, true) + c.Check(errors.Cause(err2).(*terror.Error).Equal(err), Equals, true) _, err = s.tk.Exec("alter table test_add_index_with_dup add index c (b, a, b)") - c.Check(err1.Equal(err), Equals, true) + c.Check(errors.Cause(err1).(*terror.Error).Equal(err), Equals, true) _, err = s.tk.Exec("alter table test_add_index_with_dup add index c (b, a, B)") - c.Check(err2.Equal(err), Equals, true) + c.Check(errors.Cause(err2).(*terror.Error).Equal(err), Equals, true) s.tk.MustExec("drop table test_add_index_with_dup") } @@ -856,7 +856,7 @@ func (s *testDBSuite) TestIssue6101(c *C) { s.tk.MustExec("use " + s.schemaName) s.tk.MustExec("create table t1 (quantity decimal(2) unsigned);") _, err := s.tk.Exec("insert into t1 values (500), (-500), (~0), (-1);") - terr := errors.Trace(err).(*errors.Err).Cause().(*terror.Error) + terr := errors.Cause(err).(*terror.Error) c.Assert(terr.Code(), Equals, terror.ErrCode(tmysql.ErrWarnDataOutOfRange)) s.tk.MustExec("drop table t1") diff --git a/ddl/ddl.go b/ddl/ddl.go index 96e4f83a51fa3..ab2354e145ca1 100644 --- a/ddl/ddl.go +++ b/ddl/ddl.go @@ -23,7 +23,6 @@ import ( "time" "github.com/coreos/etcd/clientv3" - "github.com/juju/errors" "github.com/ngaut/pools" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/ddl/util" @@ -39,6 +38,7 @@ import ( "github.com/pingcap/tidb/sessionctx/variable" "github.com/pingcap/tidb/table" "github.com/pingcap/tidb/terror" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "github.com/twinj/uuid" "golang.org/x/net/context" diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index 7743426c62dbe..7e455013439e9 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -24,7 +24,6 @@ import ( "time" "github.com/cznic/mathutil" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/infoschema" @@ -36,13 +35,14 @@ import ( "github.com/pingcap/tidb/table" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/charset" + "github.com/pkg/errors" ) func (d *ddl) CreateSchema(ctx sessionctx.Context, schema model.CIStr, charsetInfo *ast.CharsetOpt) (err error) { is := d.GetInformationSchema(ctx) _, ok := is.SchemaByName(schema) if ok { - return infoschema.ErrDatabaseExists.GenByArgs(schema) + return infoschema.ErrDatabaseExists.GenWithStackByArgs(schema) } if err = checkTooLongSchema(schema); err != nil { @@ -99,21 +99,21 @@ func (d *ddl) DropSchema(ctx sessionctx.Context, schema model.CIStr) (err error) func checkTooLongSchema(schema model.CIStr) error { if len(schema.L) > mysql.MaxDatabaseNameLength { - return ErrTooLongIdent.GenByArgs(schema) + return ErrTooLongIdent.GenWithStackByArgs(schema) } return nil } func checkTooLongTable(table model.CIStr) error { if len(table.L) > mysql.MaxTableNameLength { - return ErrTooLongIdent.GenByArgs(table) + return ErrTooLongIdent.GenWithStackByArgs(table) } return nil } func checkTooLongIndex(index model.CIStr) error { if len(index.L) > mysql.MaxIndexIdentifierLen { - return ErrTooLongIdent.GenByArgs(index) + return ErrTooLongIdent.GenWithStackByArgs(index) } return nil } @@ -211,7 +211,7 @@ func setCharsetCollationFlenDecimal(tp *types.FieldType) error { } } else { if !charset.ValidCharsetAndCollation(tp.Charset, tp.Collate) { - return errUnsupportedCharset.GenByArgs(tp.Charset, tp.Collate) + return errUnsupportedCharset.GenWithStackByArgs(tp.Charset, tp.Collate) } if len(tp.Collate) == 0 { var err error @@ -270,11 +270,11 @@ func checkColumnDefaultValue(ctx sessionctx.Context, col *table.Column, value in value = `null` } sc := ctx.GetSessionVars().StmtCtx - sc.AppendWarning(errBlobCantHaveDefault.GenByArgs(col.Name.O)) + sc.AppendWarning(errBlobCantHaveDefault.GenWithStackByArgs(col.Name.O)) return hasDefaultValue, value, nil } // In strict SQL mode or default value is not an empty string. - return hasDefaultValue, value, errBlobCantHaveDefault.GenByArgs(col.Name.O) + return hasDefaultValue, value, errBlobCantHaveDefault.GenWithStackByArgs(col.Name.O) } return hasDefaultValue, value, nil } @@ -340,7 +340,7 @@ func columnDefToCol(ctx sessionctx.Context, offset int, colDef *ast.ColumnDef, o case ast.ColumnOptionDefaultValue: value, err := getDefaultValue(ctx, v, colDef.Tp.Tp, colDef.Tp.Decimal) if err != nil { - return nil, nil, ErrColumnBadNull.Gen("invalid default value - %s", err) + return nil, nil, ErrColumnBadNull.GenWithStack("invalid default value - %s", err) } if hasDefaultValue, value, err = checkColumnDefaultValue(ctx, col, value); err != nil { return nil, nil, errors.Trace(err) @@ -353,10 +353,10 @@ func columnDefToCol(ctx sessionctx.Context, offset int, colDef *ast.ColumnDef, o // TODO: Support other time functions. if col.Tp == mysql.TypeTimestamp || col.Tp == mysql.TypeDatetime { if !expression.IsCurrentTimestampExpr(v.Expr) { - return nil, nil, ErrInvalidOnUpdate.GenByArgs(col.Name) + return nil, nil, ErrInvalidOnUpdate.GenWithStackByArgs(col.Name) } } else { - return nil, nil, ErrInvalidOnUpdate.GenByArgs(col.Name) + return nil, nil, ErrInvalidOnUpdate.GenWithStackByArgs(col.Name) } col.Flag |= mysql.OnUpdateNowFlag setOnUpdateNow = true @@ -510,7 +510,7 @@ func checkDefaultValue(ctx sessionctx.Context, c *table.Column, hasDefaultValue if c.GetDefaultValue() != nil { if _, err := table.GetColDefaultValue(ctx, c.ToInfo()); err != nil { - return types.ErrInvalidDefault.GenByArgs(c.Name) + return types.ErrInvalidDefault.GenWithStackByArgs(c.Name) } return nil } @@ -521,7 +521,7 @@ func checkDefaultValue(ctx sessionctx.Context, c *table.Column, hasDefaultValue // Set not null but default null is invalid. if mysql.HasNotNullFlag(c.Flag) { - return types.ErrInvalidDefault.GenByArgs(c.Name) + return types.ErrInvalidDefault.GenWithStackByArgs(c.Name) } return nil @@ -531,7 +531,7 @@ func checkDefaultValue(ctx sessionctx.Context, c *table.Column, hasDefaultValue func checkPriKeyConstraint(col *table.Column, hasDefaultValue, hasNullFlag bool, outPriKeyConstraint *ast.Constraint) error { // Primary key should not be null. if mysql.HasPriKeyFlag(col.Flag) && hasDefaultValue && col.GetDefaultValue() == nil { - return types.ErrInvalidDefault.GenByArgs(col.Name) + return types.ErrInvalidDefault.GenWithStackByArgs(col.Name) } // Set primary key flag for outer primary key constraint. // Such as: create table t1 (id int , age int, primary key(id)) @@ -556,7 +556,7 @@ func checkDuplicateColumn(colDefs []*ast.ColumnDef) error { for _, colDef := range colDefs { nameLower := colDef.Name.Name.L if colNames[nameLower] { - return infoschema.ErrColumnExists.GenByArgs(colDef.Name.Name) + return infoschema.ErrColumnExists.GenWithStackByArgs(colDef.Name.Name) } colNames[nameLower] = true } @@ -592,7 +592,7 @@ func checkGeneratedColumn(colDefs []*ast.ColumnDef) error { func checkTooLongColumn(colDefs []*ast.ColumnDef) error { for _, colDef := range colDefs { if len(colDef.Name.Name.O) > mysql.MaxColumnNameLength { - return ErrTooLongIdent.GenByArgs(colDef.Name.Name) + return ErrTooLongIdent.GenWithStackByArgs(colDef.Name.Name) } } return nil @@ -620,11 +620,11 @@ func checkColumnAttributes(colName string, tp *types.FieldType) error { switch tp.Tp { case mysql.TypeNewDecimal, mysql.TypeDouble, mysql.TypeFloat: if tp.Flen < tp.Decimal { - return types.ErrMBiggerThanD.GenByArgs(colName) + return types.ErrMBiggerThanD.GenWithStackByArgs(colName) } case mysql.TypeDatetime, mysql.TypeDuration, mysql.TypeTimestamp: if tp.Decimal != types.UnspecifiedFsp && (tp.Decimal < types.MinFsp || tp.Decimal > types.MaxFsp) { - return types.ErrTooBigPrecision.GenByArgs(tp.Decimal, colName, types.MaxFsp) + return types.ErrTooBigPrecision.GenWithStackByArgs(tp.Decimal, colName, types.MaxFsp) } } return nil @@ -639,7 +639,7 @@ func checkDuplicateConstraint(namesMap map[string]bool, name string, foreign boo if foreign { return infoschema.ErrCannotAddForeign } - return ErrDupKeyName.Gen("duplicate key name %s", name) + return ErrDupKeyName.GenWithStack("duplicate key name %s", name) } namesMap[nameLower] = true return nil @@ -735,7 +735,7 @@ func buildTableInfo(ctx sessionctx.Context, d *ddl, tableName model.CIStr, cols fk.OnDelete = int(constr.Refer.OnDelete.ReferOpt) fk.OnUpdate = int(constr.Refer.OnUpdate.ReferOpt) if len(fk.Cols) != len(fk.RefCols) { - return nil, infoschema.ErrForeignKeyNotMatch.GenByArgs(tbInfo.Name.O) + return nil, infoschema.ErrForeignKeyNotMatch.GenWithStackByArgs(tbInfo.Name.O) } if len(fk.Cols) == 0 { // TODO: In MySQL, this case will report a parse error. @@ -749,11 +749,11 @@ func buildTableInfo(ctx sessionctx.Context, d *ddl, tableName model.CIStr, cols for _, key := range constr.Keys { col = table.FindCol(cols, key.Column.Name.O) if col == nil { - return nil, errKeyColumnDoesNotExits.Gen("key column %s doesn't exist in table", key.Column.Name) + return nil, errKeyColumnDoesNotExits.GenWithStack("key column %s doesn't exist in table", key.Column.Name) } // Virtual columns cannot be used in primary key. if col.IsGenerated() && !col.GeneratedStored { - return nil, errUnsupportedOnGeneratedColumn.GenByArgs("Defining a virtual generated column as primary key") + return nil, errUnsupportedOnGeneratedColumn.GenWithStackByArgs("Defining a virtual generated column as primary key") } } if len(constr.Keys) == 1 { @@ -785,7 +785,7 @@ func buildTableInfo(ctx sessionctx.Context, d *ddl, tableName model.CIStr, cols idxInfo.Comment, err = validateCommentLength(ctx.GetSessionVars(), constr.Option.Comment, maxCommentLength, - errTooLongIndexComment.GenByArgs(idxInfo.Name.String(), maxCommentLength)) + errTooLongIndexComment.GenWithStackByArgs(idxInfo.Name.String(), maxCommentLength)) if err != nil { return nil, errors.Trace(err) } @@ -809,22 +809,22 @@ func (d *ddl) CreateTableWithLike(ctx sessionctx.Context, ident, referIdent ast. is := d.GetInformationSchema(ctx) _, ok := is.SchemaByName(referIdent.Schema) if !ok { - return infoschema.ErrTableNotExists.GenByArgs(referIdent.Schema, referIdent.Name) + return infoschema.ErrTableNotExists.GenWithStackByArgs(referIdent.Schema, referIdent.Name) } referTbl, err := is.TableByName(referIdent.Schema, referIdent.Name) if err != nil { - return infoschema.ErrTableNotExists.GenByArgs(referIdent.Schema, referIdent.Name) + return infoschema.ErrTableNotExists.GenWithStackByArgs(referIdent.Schema, referIdent.Name) } schema, ok := is.SchemaByName(ident.Schema) if !ok { - return infoschema.ErrDatabaseNotExists.GenByArgs(ident.Schema) + return infoschema.ErrDatabaseNotExists.GenWithStackByArgs(ident.Schema) } if is.TableExists(ident.Schema, ident.Name) { if ifNotExists { - ctx.GetSessionVars().StmtCtx.AppendNote(infoschema.ErrTableExists.GenByArgs(ident)) + ctx.GetSessionVars().StmtCtx.AppendNote(infoschema.ErrTableExists.GenWithStackByArgs(ident)) return nil } - return infoschema.ErrTableExists.GenByArgs(ident) + return infoschema.ErrTableExists.GenWithStackByArgs(ident) } tblInfo := *referTbl.Meta() @@ -858,14 +858,14 @@ func (d *ddl) CreateTable(ctx sessionctx.Context, s *ast.CreateTableStmt) (err e is := d.GetInformationSchema(ctx) schema, ok := is.SchemaByName(ident.Schema) if !ok { - return infoschema.ErrDatabaseNotExists.GenByArgs(ident.Schema) + return infoschema.ErrDatabaseNotExists.GenWithStackByArgs(ident.Schema) } if is.TableExists(ident.Schema, ident.Name) { if s.IfNotExists { - ctx.GetSessionVars().StmtCtx.AppendNote(infoschema.ErrTableExists.GenByArgs(ident)) + ctx.GetSessionVars().StmtCtx.AppendNote(infoschema.ErrTableExists.GenWithStackByArgs(ident)) return nil } - return infoschema.ErrTableExists.GenByArgs(ident) + return infoschema.ErrTableExists.GenWithStackByArgs(ident) } if err = checkTooLongTable(ident.Name); err != nil { return errors.Trace(err) @@ -973,7 +973,7 @@ func (d *ddl) CreateTable(ctx sessionctx.Context, s *ast.CreateTableStmt) (err e func checkCharsetAndCollation(cs string, co string) error { if !charset.ValidCharsetAndCollation(cs, co) { - return ErrUnknownCharacterSet.GenByArgs(cs) + return ErrUnknownCharacterSet.GenWithStackByArgs(cs) } return nil } @@ -1078,7 +1078,7 @@ func (d *ddl) AlterTable(ctx sessionctx.Context, ident ast.Ident, specs []*ast.A case ast.ConstraintForeignKey: err = d.CreateForeignKey(ctx, ident, model.NewCIStr(constr.Name), spec.Constraint.Keys, spec.Constraint.Refer) case ast.ConstraintPrimaryKey: - err = ErrUnsupportedModifyPrimaryKey.GenByArgs("add") + err = ErrUnsupportedModifyPrimaryKey.GenWithStackByArgs("add") default: // Nothing to do now. } @@ -1094,7 +1094,7 @@ func (d *ddl) AlterTable(ctx sessionctx.Context, ident ast.Ident, specs []*ast.A newIdent := ast.Ident{Schema: spec.NewTable.Schema, Name: spec.NewTable.Name} err = d.RenameTable(ctx, ident, newIdent) case ast.AlterTableDropPrimaryKey: - err = ErrUnsupportedModifyPrimaryKey.GenByArgs("drop") + err = ErrUnsupportedModifyPrimaryKey.GenWithStackByArgs("drop") case ast.AlterTableRenameIndex: err = d.RenameIndex(ctx, ident, spec) case ast.AlterTableOption: @@ -1131,11 +1131,11 @@ func (d *ddl) RebaseAutoID(ctx sessionctx.Context, ident ast.Ident, newBase int6 is := d.GetInformationSchema(ctx) schema, ok := is.SchemaByName(ident.Schema) if !ok { - return infoschema.ErrDatabaseNotExists.GenByArgs(ident.Schema) + return infoschema.ErrDatabaseNotExists.GenWithStackByArgs(ident.Schema) } t, err := is.TableByName(ident.Schema, ident.Name) if err != nil { - return errors.Trace(infoschema.ErrTableNotExists.GenByArgs(ident.Schema, ident.Name)) + return errors.Trace(infoschema.ErrTableNotExists.GenWithStackByArgs(ident.Schema, ident.Name)) } autoIncID, err := t.Allocator(ctx).NextGlobalAutoID(t.Meta().ID) if err != nil { @@ -1179,11 +1179,11 @@ func (d *ddl) getSchemaAndTableByIdent(ctx sessionctx.Context, tableIdent ast.Id is := d.GetInformationSchema(ctx) schema, ok := is.SchemaByName(tableIdent.Schema) if !ok { - return nil, nil, infoschema.ErrDatabaseNotExists.GenByArgs(tableIdent.Schema) + return nil, nil, infoschema.ErrDatabaseNotExists.GenWithStackByArgs(tableIdent.Schema) } t, err = is.TableByName(tableIdent.Schema, tableIdent.Name) if err != nil { - return nil, nil, infoschema.ErrTableNotExists.GenByArgs(tableIdent.Schema, tableIdent.Name) + return nil, nil, infoschema.ErrTableNotExists.GenWithStackByArgs(tableIdent.Schema, tableIdent.Name) } return schema, t, nil } @@ -1192,7 +1192,7 @@ func checkColumnConstraint(constraints []*ast.ColumnOption) error { for _, constraint := range constraints { switch constraint.Tp { case ast.ColumnOptionAutoIncrement, ast.ColumnOptionPrimaryKey, ast.ColumnOptionUniqKey: - return errUnsupportedAddColumn.Gen("unsupported add column constraint - %v", constraint.Tp) + return errUnsupportedAddColumn.GenWithStack("unsupported add column constraint - %v", constraint.Tp) } } @@ -1220,7 +1220,7 @@ func (d *ddl) AddColumn(ctx sessionctx.Context, ti ast.Ident, spec *ast.AlterTab } t, err := is.TableByName(ti.Schema, ti.Name) if err != nil { - return errors.Trace(infoschema.ErrTableNotExists.GenByArgs(ti.Schema, ti.Name)) + return errors.Trace(infoschema.ErrTableNotExists.GenWithStackByArgs(ti.Schema, ti.Name)) } if err = checkAddColumnTooManyColumns(len(t.Cols()) + 1); err != nil { return errors.Trace(err) @@ -1228,7 +1228,7 @@ func (d *ddl) AddColumn(ctx sessionctx.Context, ti ast.Ident, spec *ast.AlterTab // Check whether added column has existed. col := table.FindCol(t.Cols(), colName) if col != nil { - return infoschema.ErrColumnExists.GenByArgs(colName) + return infoschema.ErrColumnExists.GenWithStackByArgs(colName) } // If new column is a generated column, do validation. @@ -1249,7 +1249,7 @@ func (d *ddl) AddColumn(ctx sessionctx.Context, ti ast.Ident, spec *ast.AlterTab } if len(colName) > mysql.MaxColumnNameLength { - return ErrTooLongIdent.GenByArgs(colName) + return ErrTooLongIdent.GenWithStackByArgs(colName) } // Ingore table constraints now, maybe return error later. @@ -1295,11 +1295,11 @@ func (d *ddl) AddTablePartitions(ctx sessionctx.Context, ident ast.Ident, spec * is := d.infoHandle.Get() schema, ok := is.SchemaByName(ident.Schema) if !ok { - return errors.Trace(infoschema.ErrDatabaseNotExists.GenByArgs(schema)) + return errors.Trace(infoschema.ErrDatabaseNotExists.GenWithStackByArgs(schema)) } t, err := is.TableByName(ident.Schema, ident.Name) if err != nil { - return errors.Trace(infoschema.ErrTableNotExists.GenByArgs(ident.Schema, ident.Name)) + return errors.Trace(infoschema.ErrTableNotExists.GenWithStackByArgs(ident.Schema, ident.Name)) } meta := t.Meta() @@ -1343,11 +1343,11 @@ func (d *ddl) DropTablePartition(ctx sessionctx.Context, ident ast.Ident, spec * is := d.infoHandle.Get() schema, ok := is.SchemaByName(ident.Schema) if !ok { - return errors.Trace(infoschema.ErrDatabaseNotExists.GenByArgs(schema)) + return errors.Trace(infoschema.ErrDatabaseNotExists.GenWithStackByArgs(schema)) } t, err := is.TableByName(ident.Schema, ident.Name) if err != nil { - return errors.Trace(infoschema.ErrTableNotExists.GenByArgs(ident.Schema, ident.Name)) + return errors.Trace(infoschema.ErrTableNotExists.GenWithStackByArgs(ident.Schema, ident.Name)) } meta := t.Meta() if meta.GetPartitionInfo() == nil { @@ -1383,13 +1383,13 @@ func (d *ddl) DropColumn(ctx sessionctx.Context, ti ast.Ident, colName model.CIS } t, err := is.TableByName(ti.Schema, ti.Name) if err != nil { - return errors.Trace(infoschema.ErrTableNotExists.GenByArgs(ti.Schema, ti.Name)) + return errors.Trace(infoschema.ErrTableNotExists.GenWithStackByArgs(ti.Schema, ti.Name)) } // Check whether dropped column has existed. col := table.FindCol(t.Cols(), colName.L) if col == nil { - return ErrCantDropFieldOrKey.Gen("column %s doesn't exist", colName) + return ErrCantDropFieldOrKey.GenWithStack("column %s doesn't exist", colName) } tblInfo := t.Meta() @@ -1421,25 +1421,25 @@ func (d *ddl) DropColumn(ctx sessionctx.Context, ti ast.Ident, colName model.CIS func modifiable(origin *types.FieldType, to *types.FieldType) error { if to.Flen > 0 && to.Flen < origin.Flen { msg := fmt.Sprintf("length %d is less than origin %d", to.Flen, origin.Flen) - return errUnsupportedModifyColumn.GenByArgs(msg) + return errUnsupportedModifyColumn.GenWithStackByArgs(msg) } if to.Decimal > 0 && to.Decimal < origin.Decimal { msg := fmt.Sprintf("decimal %d is less than origin %d", to.Decimal, origin.Decimal) - return errUnsupportedModifyColumn.GenByArgs(msg) + return errUnsupportedModifyColumn.GenWithStackByArgs(msg) } if to.Charset != origin.Charset { msg := fmt.Sprintf("charset %s not match origin %s", to.Charset, origin.Charset) - return errUnsupportedModifyColumn.GenByArgs(msg) + return errUnsupportedModifyColumn.GenWithStackByArgs(msg) } if to.Collate != origin.Collate { msg := fmt.Sprintf("collate %s not match origin %s", to.Collate, origin.Collate) - return errUnsupportedModifyColumn.GenByArgs(msg) + return errUnsupportedModifyColumn.GenWithStackByArgs(msg) } toUnsigned := mysql.HasUnsignedFlag(to.Flag) originUnsigned := mysql.HasUnsignedFlag(origin.Flag) if originUnsigned != toUnsigned { msg := fmt.Sprintf("unsigned %v not match origin %v", toUnsigned, originUnsigned) - return errUnsupportedModifyColumn.GenByArgs(msg) + return errUnsupportedModifyColumn.GenWithStackByArgs(msg) } switch origin.Tp { case mysql.TypeVarchar, mysql.TypeString, mysql.TypeVarString, @@ -1455,20 +1455,20 @@ func modifiable(origin *types.FieldType, to *types.FieldType) error { return nil } case mysql.TypeEnum: - return errUnsupportedModifyColumn.GenByArgs("modify enum column is not supported") + return errUnsupportedModifyColumn.GenWithStackByArgs("modify enum column is not supported") default: if origin.Tp == to.Tp { return nil } } msg := fmt.Sprintf("type %v not match origin %v", to.Tp, origin.Tp) - return errUnsupportedModifyColumn.GenByArgs(msg) + return errUnsupportedModifyColumn.GenWithStackByArgs(msg) } func setDefaultValue(ctx sessionctx.Context, col *table.Column, option *ast.ColumnOption) error { value, err := getDefaultValue(ctx, option, col.Tp, col.Decimal) if err != nil { - return ErrColumnBadNull.Gen("invalid default value - %s", err) + return ErrColumnBadNull.GenWithStack("invalid default value - %s", err) } err = col.SetDefaultValue(value) if err != nil { @@ -1497,7 +1497,7 @@ func setDefaultAndComment(ctx sessionctx.Context, col *table.Column, options []* case ast.ColumnOptionDefaultValue: value, err := getDefaultValue(ctx, opt, col.Tp, col.Decimal) if err != nil { - return ErrColumnBadNull.Gen("invalid default value - %s", err) + return ErrColumnBadNull.GenWithStack("invalid default value - %s", err) } if hasDefaultValue, value, err = checkColumnDefaultValue(ctx, col, value); err != nil { return errors.Trace(err) @@ -1517,15 +1517,15 @@ func setDefaultAndComment(ctx sessionctx.Context, col *table.Column, options []* case ast.ColumnOptionAutoIncrement: col.Flag |= mysql.AutoIncrementFlag case ast.ColumnOptionPrimaryKey, ast.ColumnOptionUniqKey: - return errUnsupportedModifyColumn.Gen("unsupported modify column constraint - %v", opt.Tp) + return errUnsupportedModifyColumn.GenWithStack("unsupported modify column constraint - %v", opt.Tp) case ast.ColumnOptionOnUpdate: // TODO: Support other time functions. if col.Tp == mysql.TypeTimestamp || col.Tp == mysql.TypeDatetime { if !expression.IsCurrentTimestampExpr(opt.Expr) { - return ErrInvalidOnUpdate.GenByArgs(col.Name) + return ErrInvalidOnUpdate.GenWithStackByArgs(col.Name) } } else { - return ErrInvalidOnUpdate.GenByArgs(col.Name) + return ErrInvalidOnUpdate.GenWithStackByArgs(col.Name) } col.Flag |= mysql.OnUpdateNowFlag setOnUpdateNow = true @@ -1540,7 +1540,7 @@ func setDefaultAndComment(ctx sessionctx.Context, col *table.Column, options []* } default: // TODO: Support other types. - return errors.Trace(errUnsupportedModifyColumn.GenByArgs(opt.Tp)) + return errors.Trace(errUnsupportedModifyColumn.GenWithStackByArgs(opt.Tp)) } } @@ -1567,19 +1567,19 @@ func (d *ddl) getModifiableColumnJob(ctx sessionctx.Context, ident ast.Ident, or } t, err := is.TableByName(ident.Schema, ident.Name) if err != nil { - return nil, errors.Trace(infoschema.ErrTableNotExists.GenByArgs(ident.Schema, ident.Name)) + return nil, errors.Trace(infoschema.ErrTableNotExists.GenWithStackByArgs(ident.Schema, ident.Name)) } col := table.FindCol(t.Cols(), originalColName.L) if col == nil { - return nil, infoschema.ErrColumnNotExists.GenByArgs(originalColName, ident.Name) + return nil, infoschema.ErrColumnNotExists.GenWithStackByArgs(originalColName, ident.Name) } newColName := specNewColumn.Name.Name // If we want to rename the column name, we need to check whether it already exists. if newColName.L != originalColName.L { c := table.FindCol(t.Cols(), newColName.L) if c != nil { - return nil, infoschema.ErrColumnExists.GenByArgs(newColName) + return nil, infoschema.ErrColumnExists.GenWithStackByArgs(newColName) } } @@ -1632,12 +1632,12 @@ func (d *ddl) getModifiableColumnJob(ctx sessionctx.Context, ident ast.Ident, or // We don't support modifying column from not_auto_increment to auto_increment. if !mysql.HasAutoIncrementFlag(col.Flag) && mysql.HasAutoIncrementFlag(newCol.Flag) { - return nil, errUnsupportedModifyColumn.GenByArgs("set auto_increment") + return nil, errUnsupportedModifyColumn.GenWithStackByArgs("set auto_increment") } // We don't support modifying the type definitions from 'null' to 'not null' now. if !mysql.HasNotNullFlag(col.Flag) && mysql.HasNotNullFlag(newCol.Flag) { - return nil, errUnsupportedModifyColumn.GenByArgs("null to not null") + return nil, errUnsupportedModifyColumn.GenWithStackByArgs("null to not null") } // As same with MySQL, we don't support modifying the stored status for generated columns. if err = checkModifyGeneratedColumn(t.Cols(), col, newCol); err != nil { @@ -1660,16 +1660,16 @@ func (d *ddl) getModifiableColumnJob(ctx sessionctx.Context, ident ast.Ident, or func (d *ddl) ChangeColumn(ctx sessionctx.Context, ident ast.Ident, spec *ast.AlterTableSpec) error { specNewColumn := spec.NewColumns[0] if len(specNewColumn.Name.Schema.O) != 0 && ident.Schema.L != specNewColumn.Name.Schema.L { - return ErrWrongDBName.GenByArgs(specNewColumn.Name.Schema.O) + return ErrWrongDBName.GenWithStackByArgs(specNewColumn.Name.Schema.O) } if len(spec.OldColumnName.Schema.O) != 0 && ident.Schema.L != spec.OldColumnName.Schema.L { - return ErrWrongDBName.GenByArgs(spec.OldColumnName.Schema.O) + return ErrWrongDBName.GenWithStackByArgs(spec.OldColumnName.Schema.O) } if len(specNewColumn.Name.Table.O) != 0 && ident.Name.L != specNewColumn.Name.Table.L { - return ErrWrongTableName.GenByArgs(specNewColumn.Name.Table.O) + return ErrWrongTableName.GenWithStackByArgs(specNewColumn.Name.Table.O) } if len(spec.OldColumnName.Table.O) != 0 && ident.Name.L != spec.OldColumnName.Table.L { - return ErrWrongTableName.GenByArgs(spec.OldColumnName.Table.O) + return ErrWrongTableName.GenWithStackByArgs(spec.OldColumnName.Table.O) } job, err := d.getModifiableColumnJob(ctx, ident, spec.OldColumnName.Name, spec) @@ -1687,10 +1687,10 @@ func (d *ddl) ChangeColumn(ctx sessionctx.Context, ident ast.Ident, spec *ast.Al func (d *ddl) ModifyColumn(ctx sessionctx.Context, ident ast.Ident, spec *ast.AlterTableSpec) error { specNewColumn := spec.NewColumns[0] if len(specNewColumn.Name.Schema.O) != 0 && ident.Schema.L != specNewColumn.Name.Schema.L { - return ErrWrongDBName.GenByArgs(specNewColumn.Name.Schema.O) + return ErrWrongDBName.GenWithStackByArgs(specNewColumn.Name.Schema.O) } if len(specNewColumn.Name.Table.O) != 0 && ident.Name.L != specNewColumn.Name.Table.L { - return ErrWrongTableName.GenByArgs(specNewColumn.Name.Table.O) + return ErrWrongTableName.GenWithStackByArgs(specNewColumn.Name.Table.O) } originalColName := specNewColumn.Name.Name @@ -1709,18 +1709,18 @@ func (d *ddl) AlterColumn(ctx sessionctx.Context, ident ast.Ident, spec *ast.Alt is := d.infoHandle.Get() schema, ok := is.SchemaByName(ident.Schema) if !ok { - return infoschema.ErrTableNotExists.GenByArgs(ident.Schema, ident.Name) + return infoschema.ErrTableNotExists.GenWithStackByArgs(ident.Schema, ident.Name) } t, err := is.TableByName(ident.Schema, ident.Name) if err != nil { - return infoschema.ErrTableNotExists.GenByArgs(ident.Schema, ident.Name) + return infoschema.ErrTableNotExists.GenWithStackByArgs(ident.Schema, ident.Name) } colName := specNewColumn.Name.Name // Check whether alter column has existed. col := table.FindCol(t.Cols(), colName.L) if col == nil { - return errBadField.GenByArgs(colName, ident.Name) + return errBadField.GenWithStackByArgs(colName, ident.Name) } // Clean the NoDefaultValueFlag value. @@ -1756,12 +1756,12 @@ func (d *ddl) AlterTableComment(ctx sessionctx.Context, ident ast.Ident, spec *a is := d.infoHandle.Get() schema, ok := is.SchemaByName(ident.Schema) if !ok { - return infoschema.ErrDatabaseNotExists.GenByArgs(ident.Schema) + return infoschema.ErrDatabaseNotExists.GenWithStackByArgs(ident.Schema) } tb, err := is.TableByName(ident.Schema, ident.Name) if err != nil { - return errors.Trace(infoschema.ErrTableNotExists.GenByArgs(ident.Schema, ident.Name)) + return errors.Trace(infoschema.ErrTableNotExists.GenWithStackByArgs(ident.Schema, ident.Name)) } job := &model.Job{ @@ -1784,12 +1784,12 @@ func (d *ddl) RenameIndex(ctx sessionctx.Context, ident ast.Ident, spec *ast.Alt is := d.infoHandle.Get() schema, ok := is.SchemaByName(ident.Schema) if !ok { - return infoschema.ErrDatabaseNotExists.GenByArgs(ident.Schema) + return infoschema.ErrDatabaseNotExists.GenWithStackByArgs(ident.Schema) } tb, err := is.TableByName(ident.Schema, ident.Name) if err != nil { - return errors.Trace(infoschema.ErrTableNotExists.GenByArgs(ident.Schema, ident.Name)) + return errors.Trace(infoschema.ErrTableNotExists.GenWithStackByArgs(ident.Schema, ident.Name)) } duplicate, err := validateRenameIndex(spec.FromKey, spec.ToKey, tb.Meta()) if duplicate { @@ -1817,12 +1817,12 @@ func (d *ddl) DropTable(ctx sessionctx.Context, ti ast.Ident) (err error) { is := d.GetInformationSchema(ctx) schema, ok := is.SchemaByName(ti.Schema) if !ok { - return infoschema.ErrDatabaseNotExists.GenByArgs(ti.Schema) + return infoschema.ErrDatabaseNotExists.GenWithStackByArgs(ti.Schema) } tb, err := is.TableByName(ti.Schema, ti.Name) if err != nil { - return errors.Trace(infoschema.ErrTableNotExists.GenByArgs(ti.Schema, ti.Name)) + return errors.Trace(infoschema.ErrTableNotExists.GenWithStackByArgs(ti.Schema, ti.Name)) } job := &model.Job{ @@ -1841,11 +1841,11 @@ func (d *ddl) TruncateTable(ctx sessionctx.Context, ti ast.Ident) error { is := d.GetInformationSchema(ctx) schema, ok := is.SchemaByName(ti.Schema) if !ok { - return infoschema.ErrDatabaseNotExists.GenByArgs(ti.Schema) + return infoschema.ErrDatabaseNotExists.GenWithStackByArgs(ti.Schema) } tb, err := is.TableByName(ti.Schema, ti.Name) if err != nil { - return errors.Trace(infoschema.ErrTableNotExists.GenByArgs(ti.Schema, ti.Name)) + return errors.Trace(infoschema.ErrTableNotExists.GenWithStackByArgs(ti.Schema, ti.Name)) } newTableID, err := d.genGlobalID() if err != nil { @@ -1867,11 +1867,11 @@ func (d *ddl) RenameTable(ctx sessionctx.Context, oldIdent, newIdent ast.Ident) is := d.GetInformationSchema(ctx) oldSchema, ok := is.SchemaByName(oldIdent.Schema) if !ok { - return errFileNotFound.GenByArgs(oldIdent.Schema, oldIdent.Name) + return errFileNotFound.GenWithStackByArgs(oldIdent.Schema, oldIdent.Name) } oldTbl, err := is.TableByName(oldIdent.Schema, oldIdent.Name) if err != nil { - return errFileNotFound.GenByArgs(oldIdent.Schema, oldIdent.Name) + return errFileNotFound.GenWithStackByArgs(oldIdent.Schema, oldIdent.Name) } if newIdent.Schema.L == oldIdent.Schema.L && newIdent.Name.L == oldIdent.Name.L { // oldIdent is equal to newIdent, do nothing @@ -1879,10 +1879,10 @@ func (d *ddl) RenameTable(ctx sessionctx.Context, oldIdent, newIdent ast.Ident) } newSchema, ok := is.SchemaByName(newIdent.Schema) if !ok { - return errErrorOnRename.GenByArgs(oldIdent.Schema, oldIdent.Name, newIdent.Schema, newIdent.Name) + return errErrorOnRename.GenWithStackByArgs(oldIdent.Schema, oldIdent.Name, newIdent.Schema, newIdent.Name) } if is.TableExists(newIdent.Schema, newIdent.Name) { - return infoschema.ErrTableExists.GenByArgs(newIdent) + return infoschema.ErrTableExists.GenWithStackByArgs(newIdent) } job := &model.Job{ @@ -1917,11 +1917,11 @@ func (d *ddl) CreateIndex(ctx sessionctx.Context, ti ast.Ident, unique bool, ind is := d.infoHandle.Get() schema, ok := is.SchemaByName(ti.Schema) if !ok { - return infoschema.ErrDatabaseNotExists.GenByArgs(ti.Schema) + return infoschema.ErrDatabaseNotExists.GenWithStackByArgs(ti.Schema) } t, err := is.TableByName(ti.Schema, ti.Name) if err != nil { - return errors.Trace(infoschema.ErrTableNotExists.GenByArgs(ti.Schema, ti.Name)) + return errors.Trace(infoschema.ErrTableNotExists.GenWithStackByArgs(ti.Schema, ti.Name)) } // Deal with anonymous index. @@ -1930,7 +1930,7 @@ func (d *ddl) CreateIndex(ctx sessionctx.Context, ti ast.Ident, unique bool, ind } if indexInfo := findIndexByName(indexName.L, t.Meta().Indices); indexInfo != nil { - return ErrDupKeyName.Gen("index already exist %s", indexName) + return ErrDupKeyName.GenWithStack("index already exist %s", indexName) } if err = checkTooLongIndex(indexName); err != nil { @@ -1942,7 +1942,7 @@ func (d *ddl) CreateIndex(ctx sessionctx.Context, ti ast.Ident, unique bool, ind indexOption.Comment, err = validateCommentLength(ctx.GetSessionVars(), indexOption.Comment, maxCommentLength, - errTooLongIndexComment.GenByArgs(indexName.String(), maxCommentLength)) + errTooLongIndexComment.GenWithStackByArgs(indexName.String(), maxCommentLength)) if err != nil { return errors.Trace(err) } @@ -1988,12 +1988,12 @@ func (d *ddl) CreateForeignKey(ctx sessionctx.Context, ti ast.Ident, fkName mode is := d.infoHandle.Get() schema, ok := is.SchemaByName(ti.Schema) if !ok { - return infoschema.ErrDatabaseNotExists.GenByArgs(ti.Schema) + return infoschema.ErrDatabaseNotExists.GenWithStackByArgs(ti.Schema) } t, err := is.TableByName(ti.Schema, ti.Name) if err != nil { - return errors.Trace(infoschema.ErrTableNotExists.GenByArgs(ti.Schema, ti.Name)) + return errors.Trace(infoschema.ErrTableNotExists.GenWithStackByArgs(ti.Schema, ti.Name)) } fkInfo, err := buildFKInfo(fkName, keys, refer) @@ -2019,12 +2019,12 @@ func (d *ddl) DropForeignKey(ctx sessionctx.Context, ti ast.Ident, fkName model. is := d.infoHandle.Get() schema, ok := is.SchemaByName(ti.Schema) if !ok { - return infoschema.ErrDatabaseNotExists.GenByArgs(ti.Schema) + return infoschema.ErrDatabaseNotExists.GenWithStackByArgs(ti.Schema) } t, err := is.TableByName(ti.Schema, ti.Name) if err != nil { - return errors.Trace(infoschema.ErrTableNotExists.GenByArgs(ti.Schema, ti.Name)) + return errors.Trace(infoschema.ErrTableNotExists.GenWithStackByArgs(ti.Schema, ti.Name)) } job := &model.Job{ @@ -2048,11 +2048,11 @@ func (d *ddl) DropIndex(ctx sessionctx.Context, ti ast.Ident, indexName model.CI } t, err := is.TableByName(ti.Schema, ti.Name) if err != nil { - return errors.Trace(infoschema.ErrTableNotExists.GenByArgs(ti.Schema, ti.Name)) + return errors.Trace(infoschema.ErrTableNotExists.GenWithStackByArgs(ti.Schema, ti.Name)) } if indexInfo := findIndexByName(indexName.L, t.Meta().Indices); indexInfo == nil { - return ErrCantDropFieldOrKey.Gen("index %s doesn't exist", indexName) + return ErrCantDropFieldOrKey.GenWithStack("index %s doesn't exist", indexName) } job := &model.Job{ @@ -2073,18 +2073,18 @@ func isDroppableColumn(tblInfo *model.TableInfo, colName model.CIStr) error { for _, col := range tblInfo.Columns { for dep := range col.Dependences { if dep == colName.L { - return errDependentByGeneratedColumn.GenByArgs(dep) + return errDependentByGeneratedColumn.GenWithStackByArgs(dep) } } } if len(tblInfo.Columns) == 1 { - return ErrCantRemoveAllFields.Gen("can't drop only column %s in table %s", + return ErrCantRemoveAllFields.GenWithStack("can't drop only column %s in table %s", colName, tblInfo.Name) } // We don't support dropping column with index covered now. // We must drop the index first, then drop the column. if isColumnWithIndex(colName.L, tblInfo.Indices) { - return errCantDropColWithIndex.Gen("can't drop column %s with index covered now", colName) + return errCantDropColWithIndex.GenWithStack("can't drop column %s with index covered now", colName) } return nil } @@ -2120,7 +2120,7 @@ func buildPartitionInfo(meta *model.TableInfo, d *ddl, spec *ast.AlterTableSpec) continue } buf.Reset() - return nil, infoschema.ErrColumnNotExists.GenByArgs(buf.String(), "partition function") + return nil, infoschema.ErrColumnNotExists.GenWithStackByArgs(buf.String(), "partition function") } } pid, err1 := d.genGlobalID() diff --git a/ddl/ddl_worker.go b/ddl/ddl_worker.go index 6b836c6839622..fa68e6c502656 100644 --- a/ddl/ddl_worker.go +++ b/ddl/ddl_worker.go @@ -19,7 +19,6 @@ import ( "sync/atomic" "time" - "github.com/juju/errors" "github.com/ngaut/pools" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/meta" @@ -29,6 +28,7 @@ import ( "github.com/pingcap/tidb/sessionctx/binloginfo" "github.com/pingcap/tidb/terror" "github.com/pingcap/tidb/util" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" ) @@ -272,7 +272,7 @@ func (w *worker) deleteRange(job *model.Job) error { if job.Version <= currentVersion { err = w.delRangeManager.addDelRangeJob(job) } else { - err = errInvalidJobVersion.GenByArgs(job.Version, currentVersion) + err = errInvalidJobVersion.GenWithStackByArgs(job.Version, currentVersion) } return errors.Trace(err) } @@ -519,7 +519,7 @@ func (w *worker) runDDLJob(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64, default: // Invalid job, cancel it. job.State = model.JobStateCancelled - err = errInvalidDDLJob.Gen("invalid ddl job %v", job) + err = errInvalidDDLJob.GenWithStack("invalid ddl job %v", job) } // Save errors in job, so that others can know errors happened. diff --git a/ddl/ddl_worker_test.go b/ddl/ddl_worker_test.go index 1b41e6e3d2e0d..b6038bd5ce9ae 100644 --- a/ddl/ddl_worker_test.go +++ b/ddl/ddl_worker_test.go @@ -17,7 +17,6 @@ import ( "sync" "time" - "github.com/juju/errors" . "github.com/pingcap/check" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/kv" @@ -30,6 +29,7 @@ import ( "github.com/pingcap/tidb/util/mock" "github.com/pingcap/tidb/util/sqlexec" "github.com/pingcap/tidb/util/testleak" + "github.com/pkg/errors" "golang.org/x/net/context" ) diff --git a/ddl/delete_range.go b/ddl/delete_range.go index 1fb90bc838a2c..aa1bf30640ad3 100644 --- a/ddl/delete_range.go +++ b/ddl/delete_range.go @@ -20,7 +20,6 @@ import ( "math" "sync" - "github.com/juju/errors" "github.com/pingcap/tidb/ddl/util" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/model" @@ -28,6 +27,7 @@ import ( "github.com/pingcap/tidb/tablecodec" "github.com/pingcap/tidb/terror" "github.com/pingcap/tidb/util/sqlexec" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" ) diff --git a/ddl/foreign_key.go b/ddl/foreign_key.go index f1bf6770e8ad5..e9aa4c0eb43ad 100644 --- a/ddl/foreign_key.go +++ b/ddl/foreign_key.go @@ -14,10 +14,10 @@ package ddl import ( - "github.com/juju/errors" "github.com/pingcap/tidb/infoschema" "github.com/pingcap/tidb/meta" "github.com/pingcap/tidb/model" + "github.com/pkg/errors" ) func onCreateForeignKey(t *meta.Meta, job *model.Job) (ver int64, _ error) { @@ -50,7 +50,7 @@ func onCreateForeignKey(t *meta.Meta, job *model.Job) (ver int64, _ error) { job.FinishTableJob(model.JobStateDone, model.StatePublic, ver, tblInfo) return ver, nil default: - return ver, ErrInvalidForeignKeyState.Gen("invalid fk state %v", fkInfo.State) + return ver, ErrInvalidForeignKeyState.GenWithStack("invalid fk state %v", fkInfo.State) } } @@ -81,7 +81,7 @@ func onDropForeignKey(t *meta.Meta, job *model.Job) (ver int64, _ error) { if !found { job.State = model.JobStateCancelled - return ver, infoschema.ErrForeignKeyNotExists.GenByArgs(fkName) + return ver, infoschema.ErrForeignKeyNotExists.GenWithStackByArgs(fkName) } nfks := tblInfo.ForeignKeys[:0] @@ -106,7 +106,7 @@ func onDropForeignKey(t *meta.Meta, job *model.Job) (ver int64, _ error) { job.FinishTableJob(model.JobStateDone, model.StateNone, ver, tblInfo) return ver, nil default: - return ver, ErrInvalidForeignKeyState.Gen("invalid fk state %v", fkInfo.State) + return ver, ErrInvalidForeignKeyState.GenWithStack("invalid fk state %v", fkInfo.State) } } diff --git a/ddl/foreign_key_test.go b/ddl/foreign_key_test.go index 3ee54201ee7a5..7fdde31834477 100644 --- a/ddl/foreign_key_test.go +++ b/ddl/foreign_key_test.go @@ -17,7 +17,6 @@ import ( "strings" "sync" - "github.com/juju/errors" . "github.com/pingcap/check" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/kv" @@ -25,6 +24,7 @@ import ( "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/table" "github.com/pingcap/tidb/util/testleak" + "github.com/pkg/errors" "golang.org/x/net/context" ) diff --git a/ddl/generated_column.go b/ddl/generated_column.go index f1029d5e18ea1..899249a9fb658 100644 --- a/ddl/generated_column.go +++ b/ddl/generated_column.go @@ -14,9 +14,9 @@ package ddl import ( - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/table" + "github.com/pkg/errors" ) // columnGenerationInDDL is a struct for validating generated columns in DDL. @@ -35,11 +35,11 @@ func verifyColumnGeneration(colName2Generation map[string]columnGenerationInDDL, if attr.generated && attribute.position <= attr.position { // A generated column definition can refer to other // generated columns occurring earilier in the table. - err := errGeneratedColumnNonPrior.GenByArgs() + err := errGeneratedColumnNonPrior.GenWithStackByArgs() return errors.Trace(err) } } else { - err := errBadField.GenByArgs(depCol, "generated column function") + err := errBadField.GenWithStackByArgs(depCol, "generated column function") return errors.Trace(err) } } @@ -53,7 +53,7 @@ func verifyColumnGeneration(colName2Generation map[string]columnGenerationInDDL, func columnNamesCover(normalColNames map[string]struct{}, dependColNames map[string]struct{}) error { for name := range dependColNames { if _, ok := normalColNames[name]; !ok { - return errBadField.GenByArgs(name, "generated column function") + return errBadField.GenWithStackByArgs(name, "generated column function") } } return nil @@ -113,7 +113,7 @@ func checkModifyGeneratedColumn(originCols []*table.Column, oldCol, newCol *tabl } } if stored[0] != stored[1] { - return errUnsupportedOnGeneratedColumn.GenByArgs("Changing the STORED status") + return errUnsupportedOnGeneratedColumn.GenWithStackByArgs("Changing the STORED status") } // rule 2. var colName2Generation = make(map[string]columnGenerationInDDL, len(originCols)) diff --git a/ddl/index.go b/ddl/index.go index 3ac0d9f4fe7b3..6c73bc7cd8b2e 100644 --- a/ddl/index.go +++ b/ddl/index.go @@ -19,7 +19,6 @@ import ( "sync/atomic" "time" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/infoschema" "github.com/pingcap/tidb/kv" @@ -35,6 +34,7 @@ import ( "github.com/pingcap/tidb/tablecodec" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" ) @@ -51,16 +51,16 @@ func buildIndexColumns(columns []*model.ColumnInfo, idxColNames []*ast.IndexColN for _, ic := range idxColNames { col := model.FindColumnInfo(columns, ic.Column.Name.O) if col == nil { - return nil, errKeyColumnDoesNotExits.Gen("column does not exist: %s", ic.Column.Name) + return nil, errKeyColumnDoesNotExits.GenWithStack("column does not exist: %s", ic.Column.Name) } if col.Flen == 0 { - return nil, errors.Trace(errWrongKeyColumn.GenByArgs(ic.Column.Name)) + return nil, errors.Trace(errWrongKeyColumn.GenWithStackByArgs(ic.Column.Name)) } // JSON column cannot index. if col.FieldType.Tp == mysql.TypeJSON { - return nil, errors.Trace(errJSONUsedAsKey.GenByArgs(col.Name.O)) + return nil, errors.Trace(errJSONUsedAsKey.GenWithStackByArgs(col.Name.O)) } // Length must be specified for BLOB and TEXT column indexes. @@ -100,7 +100,7 @@ func buildIndexColumns(columns []*model.ColumnInfo, idxColNames []*ast.IndexColN if length, ok := mysql.DefaultLengthOfMysqlTypes[col.FieldType.Tp]; ok { sumLength += length } else { - return nil, errUnknownTypeLength.GenByArgs(col.FieldType.Tp) + return nil, errUnknownTypeLength.GenWithStackByArgs(col.FieldType.Tp) } // Special case for time fraction. @@ -109,7 +109,7 @@ func buildIndexColumns(columns []*model.ColumnInfo, idxColNames []*ast.IndexColN if length, ok := mysql.DefaultLengthOfTimeFraction[col.FieldType.Decimal]; ok { sumLength += length } else { - return nil, errUnknownFractionLength.GenByArgs(col.FieldType.Tp, col.FieldType.Decimal) + return nil, errUnknownFractionLength.GenWithStackByArgs(col.FieldType.Tp, col.FieldType.Decimal) } } } @@ -180,7 +180,7 @@ func dropIndexColumnFlag(tblInfo *model.TableInfo, indexInfo *model.IndexInfo) { func validateRenameIndex(from, to model.CIStr, tbl *model.TableInfo) (ignore bool, err error) { if fromIdx := findIndexByName(from.L, tbl.Indices); fromIdx == nil { - return false, errors.Trace(infoschema.ErrKeyNotExists.GenByArgs(from.O, tbl.Name)) + return false, errors.Trace(infoschema.ErrKeyNotExists.GenWithStackByArgs(from.O, tbl.Name)) } // Take case-sensitivity into account, if `FromKey` and `ToKey` are the same, nothing need to be changed if from.O == to.O { @@ -190,7 +190,7 @@ func validateRenameIndex(from, to model.CIStr, tbl *model.TableInfo) (ignore boo // e.g: from `inDex` to `IndEX`. Otherwise, we try to rename an index to another different index which already exists, // that's illegal by rule. if toIdx := findIndexByName(to.L, tbl.Indices); toIdx != nil && from.L != to.L { - return false, errors.Trace(infoschema.ErrKeyNameDuplicate.GenByArgs(toIdx.Name.O)) + return false, errors.Trace(infoschema.ErrKeyNameDuplicate.GenWithStackByArgs(toIdx.Name.O)) } return false, nil } @@ -258,7 +258,7 @@ func (w *worker) onCreateIndex(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int indexInfo := findIndexByName(indexName.L, tblInfo.Indices) if indexInfo != nil && indexInfo.State == model.StatePublic { job.State = model.JobStateCancelled - return ver, ErrDupKeyName.Gen("index already exist %s", indexName) + return ver, ErrDupKeyName.GenWithStack("index already exist %s", indexName) } if indexInfo == nil { @@ -349,7 +349,7 @@ func (w *worker) onCreateIndex(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int // Finish this job. job.FinishTableJob(model.JobStateDone, model.StatePublic, ver, tblInfo) default: - err = ErrInvalidIndexState.Gen("invalid index state %v", tblInfo.State) + err = ErrInvalidIndexState.GenWithStack("invalid index state %v", tblInfo.State) } return ver, errors.Trace(err) @@ -371,7 +371,7 @@ func convert2RollbackJob(t *meta.Meta, job *model.Job, tblInfo *model.TableInfo, } if kv.ErrKeyExists.Equal(err) { - return ver, kv.ErrKeyExists.Gen("Duplicate for key %s", indexInfo.Name.O) + return ver, kv.ErrKeyExists.GenWithStack("Duplicate for key %s", indexInfo.Name.O) } return ver, errors.Trace(err) @@ -393,7 +393,7 @@ func onDropIndex(t *meta.Meta, job *model.Job) (ver int64, _ error) { indexInfo := findIndexByName(indexName.L, tblInfo.Indices) if indexInfo == nil { job.State = model.JobStateCancelled - return ver, ErrCantDropFieldOrKey.Gen("index %s doesn't exist", indexName) + return ver, ErrCantDropFieldOrKey.GenWithStack("index %s doesn't exist", indexName) } originalState := indexInfo.State @@ -439,7 +439,7 @@ func onDropIndex(t *meta.Meta, job *model.Job) (ver int64, _ error) { job.Args = append(job.Args, indexInfo.ID, getPartitionIDs(tblInfo)) } default: - err = ErrInvalidTableState.Gen("invalid table state %v", tblInfo.State) + err = ErrInvalidTableState.GenWithStack("invalid table state %v", tblInfo.State) } return ver, errors.Trace(err) } diff --git a/ddl/index_change_test.go b/ddl/index_change_test.go index cb3939f867ed6..ec7d1ca73b3fa 100644 --- a/ddl/index_change_test.go +++ b/ddl/index_change_test.go @@ -14,7 +14,6 @@ package ddl import ( - "github.com/juju/errors" . "github.com/pingcap/check" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/meta" @@ -24,6 +23,7 @@ import ( "github.com/pingcap/tidb/table" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/testleak" + "github.com/pkg/errors" "golang.org/x/net/context" ) diff --git a/ddl/mock.go b/ddl/mock.go index 70562e9a496cd..3ab786fd0138c 100644 --- a/ddl/mock.go +++ b/ddl/mock.go @@ -18,10 +18,10 @@ import ( "time" "github.com/coreos/etcd/clientv3" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/model" "github.com/pingcap/tidb/sessionctx" + "github.com/pkg/errors" "golang.org/x/net/context" ) diff --git a/ddl/partition.go b/ddl/partition.go index ad4bc93edd38e..b1110209c3e3b 100644 --- a/ddl/partition.go +++ b/ddl/partition.go @@ -19,7 +19,6 @@ import ( "strconv" "strings" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/meta" @@ -30,6 +29,7 @@ import ( "github.com/pingcap/tidb/table" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" + "github.com/pkg/errors" ) const ( @@ -70,7 +70,7 @@ func buildTablePartitionInfo(ctx sessionctx.Context, d *ddl, s *ast.CreateTableS if s.Partition.Tp == model.PartitionTypeRange { if s.Partition.ColumnNames == nil && len(def.LessThan) != 1 { - return nil, ErrTooManyValues.GenByArgs(s.Partition.Tp.String()) + return nil, ErrTooManyValues.GenWithStackByArgs(s.Partition.Tp.String()) } buf := new(bytes.Buffer) // Range columns partitions support multi-column partitions. @@ -96,7 +96,7 @@ func checkPartitionNameUnique(tbInfo *model.TableInfo, pi *model.PartitionInfo) newPars := pi.Definitions for _, newPar := range newPars { if _, ok := partNames[newPar.Name.L]; ok { - return ErrSameNamePartition.GenByArgs(newPar.Name) + return ErrSameNamePartition.GenWithStackByArgs(newPar.Name) } partNames[newPar.Name.L] = struct{}{} } @@ -160,7 +160,7 @@ func checkPartitionFuncType(ctx sessionctx.Context, s *ast.CreateTableStmt, cols name := strings.Replace(col.Name.String(), ".", "`.`", -1) // Range partitioning key supported types: tinyint, smallint, mediumint, int and bigint. if !validRangePartitionType(col) && fmt.Sprintf("`%s`", name) == exprStr { - return errors.Trace(ErrNotAllowedTypeInPartition.GenByArgs(exprStr)) + return errors.Trace(ErrNotAllowedTypeInPartition.GenWithStackByArgs(exprStr)) } } } @@ -173,7 +173,7 @@ func checkPartitionFuncType(ctx sessionctx.Context, s *ast.CreateTableStmt, cols if e.GetType().EvalType() == types.ETInt { return nil } - return ErrPartitionFuncNotAllowed.GenByArgs("PARTITION") + return ErrPartitionFuncNotAllowed.GenWithStackByArgs("PARTITION") } // checkCreatePartitionValue checks whether `less than value` is strictly increasing for each partition. @@ -252,7 +252,7 @@ func getRangeValue(ctx sessionctx.Context, tblInfo *model.TableInfo, str string, } } } - return 0, false, ErrNotAllowedTypeInPartition.GenByArgs(str) + return 0, false, ErrNotAllowedTypeInPartition.GenWithStackByArgs(str) } // validRangePartitionType checks the type supported by the range partitioning key. @@ -276,7 +276,7 @@ func checkDropTablePartition(meta *model.TableInfo, partName string) error { return nil } } - return errors.Trace(ErrDropPartitionNonExistent.GenByArgs(partName)) + return errors.Trace(ErrDropPartitionNonExistent.GenWithStackByArgs(partName)) } // removePartitionInfo each ddl job deletes a partition. @@ -373,7 +373,7 @@ func checkRangePartitioningKeysConstraints(ctx sessionctx.Context, s *ast.Create // Every unique key on the table must use every column in the table's partitioning expression. // See https://dev.mysql.com/doc/refman/5.7/en/partitioning-limitations-partitioning-keys-unique-keys.html. if !checkConstraintIncludePartKey(partkeys, con) { - return ErrUniqueKeyNeedAllFieldsInPf.GenByArgs(primarykey) + return ErrUniqueKeyNeedAllFieldsInPf.GenWithStackByArgs(primarykey) } } return nil diff --git a/ddl/reorg.go b/ddl/reorg.go index bb9170cc34c82..66730b5a826d9 100644 --- a/ddl/reorg.go +++ b/ddl/reorg.go @@ -18,7 +18,6 @@ import ( "sync/atomic" "time" - "github.com/juju/errors" "github.com/pingcap/tidb/distsql" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/meta" @@ -33,6 +32,7 @@ import ( "github.com/pingcap/tidb/util/mock" "github.com/pingcap/tidb/util/ranger" "github.com/pingcap/tipb/go-tipb" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" ) @@ -159,7 +159,7 @@ func (w *worker) runReorgJob(t *meta.Meta, reorgInfo *reorgInfo, lease time.Dura func (w *worker) isReorgRunnable(d *ddlCtx) error { if isChanClosed(w.quitCh) { // Worker is closed. So it can't do the reorganizational job. - return errInvalidWorker.Gen("worker is closed") + return errInvalidWorker.GenWithStack("worker is closed") } if w.reorgCtx.isReorgCanceled() { @@ -342,7 +342,7 @@ func getReorgInfo(d *ddlCtx, t *meta.Meta, job *model.Job, tbl table.Table) (*re if err != nil { return nil, errors.Trace(err) } else if ver.Ver <= 0 { - return nil, errInvalidStoreVer.Gen("invalid storage current version %d", ver.Ver) + return nil, errInvalidStoreVer.GenWithStack("invalid storage current version %d", ver.Ver) } tblInfo := tbl.Meta() pid = tblInfo.ID diff --git a/ddl/schema.go b/ddl/schema.go index 961a28e03411e..8e3272c033e1c 100644 --- a/ddl/schema.go +++ b/ddl/schema.go @@ -14,10 +14,10 @@ package ddl import ( - "github.com/juju/errors" "github.com/pingcap/tidb/infoschema" "github.com/pingcap/tidb/meta" "github.com/pingcap/tidb/model" + "github.com/pkg/errors" ) func onCreateSchema(t *meta.Meta, job *model.Job) (ver int64, _ error) { @@ -42,7 +42,7 @@ func onCreateSchema(t *meta.Meta, job *model.Job) (ver int64, _ error) { if db.ID != schemaID { // The database already exists, can't create it, we should cancel this job now. job.State = model.JobStateCancelled - return ver, infoschema.ErrDatabaseExists.GenByArgs(db.Name) + return ver, infoschema.ErrDatabaseExists.GenWithStackByArgs(db.Name) } dbInfo = db } @@ -77,7 +77,7 @@ func onDropSchema(t *meta.Meta, job *model.Job) (ver int64, _ error) { } if dbInfo == nil { job.State = model.JobStateCancelled - return ver, infoschema.ErrDatabaseDropExists.GenByArgs("") + return ver, infoschema.ErrDatabaseDropExists.GenWithStackByArgs("") } ver, err = updateSchemaVersion(t, job) diff --git a/ddl/session_pool.go b/ddl/session_pool.go index 87e4349272120..2fa4f39ce6966 100644 --- a/ddl/session_pool.go +++ b/ddl/session_pool.go @@ -16,11 +16,11 @@ package ddl import ( "sync" - "github.com/juju/errors" "github.com/ngaut/pools" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/util/mock" + "github.com/pkg/errors" ) // sessionPool is used to new session. diff --git a/ddl/stat.go b/ddl/stat.go index 63917f0f88e16..c8dd15aaefcfd 100644 --- a/ddl/stat.go +++ b/ddl/stat.go @@ -14,10 +14,10 @@ package ddl import ( - "github.com/juju/errors" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/sessionctx/variable" "github.com/pingcap/tidb/util/admin" + "github.com/pkg/errors" ) var ( diff --git a/ddl/syncer.go b/ddl/syncer.go index f077346183042..d7a911f15805f 100644 --- a/ddl/syncer.go +++ b/ddl/syncer.go @@ -22,9 +22,9 @@ import ( "github.com/coreos/etcd/clientv3" "github.com/coreos/etcd/clientv3/concurrency" - "github.com/juju/errors" "github.com/pingcap/tidb/metrics" "github.com/pingcap/tidb/owner" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" ) diff --git a/ddl/table.go b/ddl/table.go index d17afcadd9f50..930f871ff43d2 100644 --- a/ddl/table.go +++ b/ddl/table.go @@ -18,7 +18,6 @@ import ( "strconv" "strings" - "github.com/juju/errors" "github.com/pingcap/tidb/ddl/util" "github.com/pingcap/tidb/infoschema" "github.com/pingcap/tidb/kv" @@ -27,6 +26,7 @@ import ( "github.com/pingcap/tidb/model" "github.com/pingcap/tidb/table" "github.com/pingcap/tidb/tablecodec" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" ) @@ -76,7 +76,7 @@ func onCreateTable(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64, _ error) asyncNotifyEvent(d, &util.Event{Tp: model.ActionCreateTable, TableInfo: tbInfo}) return ver, nil default: - return ver, ErrInvalidTableState.Gen("invalid table state %v", tbInfo.State) + return ver, ErrInvalidTableState.GenWithStack("invalid table state %v", tbInfo.State) } } @@ -89,7 +89,7 @@ func onDropTable(t *meta.Meta, job *model.Job) (ver int64, _ error) { if err != nil { if meta.ErrDBNotExists.Equal(err) { job.State = model.JobStateCancelled - return ver, errors.Trace(infoschema.ErrDatabaseNotExists.GenByArgs( + return ver, errors.Trace(infoschema.ErrDatabaseNotExists.GenWithStackByArgs( fmt.Sprintf("(Schema ID %d)", schemaID), )) } @@ -99,7 +99,7 @@ func onDropTable(t *meta.Meta, job *model.Job) (ver int64, _ error) { // Check the table. if tblInfo == nil { job.State = model.JobStateCancelled - return ver, errors.Trace(infoschema.ErrTableNotExists.GenByArgs( + return ver, errors.Trace(infoschema.ErrTableNotExists.GenWithStackByArgs( fmt.Sprintf("(Schema ID %d)", schemaID), fmt.Sprintf("(Table ID %d)", tableID), )) @@ -131,7 +131,7 @@ func onDropTable(t *meta.Meta, job *model.Job) (ver int64, _ error) { startKey := tablecodec.EncodeTablePrefix(tableID) job.Args = append(job.Args, startKey, getPartitionIDs(tblInfo)) default: - err = ErrInvalidTableState.Gen("invalid table state %v", tblInfo.State) + err = ErrInvalidTableState.GenWithStack("invalid table state %v", tblInfo.State) } return ver, errors.Trace(err) @@ -165,14 +165,14 @@ func getTableInfo(t *meta.Meta, job *model.Job, schemaID int64) (*model.TableInf if err != nil { if meta.ErrDBNotExists.Equal(err) { job.State = model.JobStateCancelled - return nil, errors.Trace(infoschema.ErrDatabaseNotExists.GenByArgs( + return nil, errors.Trace(infoschema.ErrDatabaseNotExists.GenWithStackByArgs( fmt.Sprintf("(Schema ID %d)", schemaID), )) } return nil, errors.Trace(err) } else if tblInfo == nil { job.State = model.JobStateCancelled - return nil, errors.Trace(infoschema.ErrTableNotExists.GenByArgs( + return nil, errors.Trace(infoschema.ErrTableNotExists.GenWithStackByArgs( fmt.Sprintf("(Schema ID %d)", schemaID), fmt.Sprintf("(Table ID %d)", tableID), )) @@ -180,7 +180,7 @@ func getTableInfo(t *meta.Meta, job *model.Job, schemaID int64) (*model.TableInf if tblInfo.State != model.StatePublic { job.State = model.JobStateCancelled - return nil, ErrInvalidTableState.Gen("table %s is not in public, but %s", tblInfo.Name, tblInfo.State) + return nil, ErrInvalidTableState.GenWithStack("table %s is not in public, but %s", tblInfo.Name, tblInfo.State) } return tblInfo, nil @@ -388,7 +388,7 @@ func checkTableNotExists(t *meta.Meta, job *model.Job, schemaID int64, tableName if err != nil { if meta.ErrDBNotExists.Equal(err) { job.State = model.JobStateCancelled - return infoschema.ErrDatabaseNotExists.GenByArgs("") + return infoschema.ErrDatabaseNotExists.GenWithStackByArgs("") } return errors.Trace(err) } @@ -398,7 +398,7 @@ func checkTableNotExists(t *meta.Meta, job *model.Job, schemaID int64, tableName if tbl.Name.L == tableName { // This table already exists and can't be created, we should cancel this job now. job.State = model.JobStateCancelled - return infoschema.ErrTableExists.GenByArgs(tbl.Name) + return infoschema.ErrTableExists.GenWithStackByArgs(tbl.Name) } } diff --git a/ddl/table_test.go b/ddl/table_test.go index 3b3994700610f..7fef7c9bd50b5 100644 --- a/ddl/table_test.go +++ b/ddl/table_test.go @@ -16,7 +16,6 @@ package ddl import ( "fmt" - "github.com/juju/errors" . "github.com/pingcap/check" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/meta" @@ -27,6 +26,7 @@ import ( "github.com/pingcap/tidb/table" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/testleak" + "github.com/pkg/errors" "golang.org/x/net/context" ) diff --git a/ddl/util/util.go b/ddl/util/util.go index db3e09fdb3d3f..83f6aa600ab54 100644 --- a/ddl/util/util.go +++ b/ddl/util/util.go @@ -17,12 +17,12 @@ import ( "encoding/hex" "fmt" - "github.com/juju/errors" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/terror" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/sqlexec" + "github.com/pkg/errors" "golang.org/x/net/context" ) diff --git a/distsql/distsql.go b/distsql/distsql.go index 4034978581471..b681fbc816bdf 100644 --- a/distsql/distsql.go +++ b/distsql/distsql.go @@ -14,12 +14,12 @@ package distsql import ( - "github.com/juju/errors" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/metrics" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/statistics" "github.com/pingcap/tidb/types" + "github.com/pkg/errors" "golang.org/x/net/context" ) diff --git a/distsql/distsql_test.go b/distsql/distsql_test.go index 40e4419f7d025..e914382417a8a 100644 --- a/distsql/distsql_test.go +++ b/distsql/distsql_test.go @@ -18,7 +18,6 @@ import ( "testing" "time" - "github.com/juju/errors" . "github.com/pingcap/check" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/mysql" @@ -31,6 +30,7 @@ import ( "github.com/pingcap/tidb/util/codec" "github.com/pingcap/tidb/util/execdetails" "github.com/pingcap/tipb/go-tipb" + "github.com/pkg/errors" "golang.org/x/net/context" ) diff --git a/distsql/request_builder.go b/distsql/request_builder.go index 07899b0158084..5dddc206171d3 100644 --- a/distsql/request_builder.go +++ b/distsql/request_builder.go @@ -16,7 +16,6 @@ package distsql import ( "math" - "github.com/juju/errors" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/sessionctx/stmtctx" @@ -27,6 +26,7 @@ import ( "github.com/pingcap/tidb/util/codec" "github.com/pingcap/tidb/util/ranger" "github.com/pingcap/tipb/go-tipb" + "github.com/pkg/errors" ) // RequestBuilder is used to build a "kv.Request". diff --git a/distsql/select_result.go b/distsql/select_result.go index 77e3b2839cc18..aca9ee0e9f561 100644 --- a/distsql/select_result.go +++ b/distsql/select_result.go @@ -16,7 +16,6 @@ package distsql import ( "time" - "github.com/juju/errors" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/metrics" "github.com/pingcap/tidb/sessionctx" @@ -26,6 +25,7 @@ import ( "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/codec" "github.com/pingcap/tipb/go-tipb" + "github.com/pkg/errors" "golang.org/x/net/context" ) diff --git a/distsql/stream.go b/distsql/stream.go index b6411ab9064f7..f5bd33583ccd6 100644 --- a/distsql/stream.go +++ b/distsql/stream.go @@ -14,7 +14,6 @@ package distsql import ( - "github.com/juju/errors" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/metrics" "github.com/pingcap/tidb/sessionctx" @@ -24,6 +23,7 @@ import ( "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/codec" "github.com/pingcap/tipb/go-tipb" + "github.com/pkg/errors" "golang.org/x/net/context" ) diff --git a/domain/domain.go b/domain/domain.go index 6e5ba7104ead5..99fc4c546bb44 100644 --- a/domain/domain.go +++ b/domain/domain.go @@ -23,7 +23,6 @@ import ( "github.com/coreos/etcd/clientv3" "github.com/grpc-ecosystem/go-grpc-prometheus" - "github.com/juju/errors" "github.com/ngaut/pools" "github.com/pingcap/tidb/ddl" "github.com/pingcap/tidb/infoschema" @@ -38,6 +37,7 @@ import ( "github.com/pingcap/tidb/statistics" "github.com/pingcap/tidb/terror" "github.com/pingcap/tidb/util" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" "google.golang.org/grpc" diff --git a/domain/domain_test.go b/domain/domain_test.go index 84bc1b2292d2d..2b0856ec0ff29 100644 --- a/domain/domain_test.go +++ b/domain/domain_test.go @@ -17,7 +17,6 @@ import ( "testing" "time" - "github.com/juju/errors" "github.com/ngaut/pools" . "github.com/pingcap/check" "github.com/pingcap/tidb/ast" @@ -25,6 +24,7 @@ import ( "github.com/pingcap/tidb/store/mockstore" "github.com/pingcap/tidb/util/mock" "github.com/pingcap/tidb/util/testleak" + "github.com/pkg/errors" ) func TestT(t *testing.T) { diff --git a/domain/info.go b/domain/info.go index 3e066b0eacf59..7d11e63436957 100644 --- a/domain/info.go +++ b/domain/info.go @@ -20,13 +20,13 @@ import ( "github.com/coreos/etcd/clientv3" "github.com/coreos/etcd/clientv3/concurrency" - "github.com/juju/errors" "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/ddl" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/owner" "github.com/pingcap/tidb/util/hack" "github.com/pingcap/tidb/util/printer" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" ) diff --git a/executor/adapter.go b/executor/adapter.go index 642bdb2b86c16..379039dc36a39 100644 --- a/executor/adapter.go +++ b/executor/adapter.go @@ -19,7 +19,6 @@ import ( "strings" "time" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/domain" @@ -34,6 +33,7 @@ import ( "github.com/pingcap/tidb/terror" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/logutil" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" ) diff --git a/executor/admin.go b/executor/admin.go index 2faf6278eeaee..572eb451adc4b 100644 --- a/executor/admin.go +++ b/executor/admin.go @@ -16,7 +16,6 @@ package executor import ( "math" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/distsql" "github.com/pingcap/tidb/infoschema" @@ -32,6 +31,7 @@ import ( "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/ranger" "github.com/pingcap/tipb/go-tipb" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" ) diff --git a/executor/aggfuncs/builder.go b/executor/aggfuncs/builder.go index 30391b78ddb69..7ba78f94585e6 100644 --- a/executor/aggfuncs/builder.go +++ b/executor/aggfuncs/builder.go @@ -17,7 +17,6 @@ import ( "fmt" "strconv" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/expression/aggregation" @@ -26,6 +25,7 @@ import ( "github.com/pingcap/tidb/sessionctx/variable" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" + "github.com/pkg/errors" ) // Build is used to build a specific AggFunc implementation according to the diff --git a/executor/aggfuncs/func_avg.go b/executor/aggfuncs/func_avg.go index d14116efcf4a3..139d60845273f 100644 --- a/executor/aggfuncs/func_avg.go +++ b/executor/aggfuncs/func_avg.go @@ -14,11 +14,11 @@ package aggfuncs import ( - "github.com/juju/errors" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/set" + "github.com/pkg/errors" ) // All the following avg function implementations return the decimal result, diff --git a/executor/aggfuncs/func_bitfuncs.go b/executor/aggfuncs/func_bitfuncs.go index d30e27bff3a1b..3379a9b695ff5 100644 --- a/executor/aggfuncs/func_bitfuncs.go +++ b/executor/aggfuncs/func_bitfuncs.go @@ -16,9 +16,9 @@ package aggfuncs import ( "math" - "github.com/juju/errors" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/util/chunk" + "github.com/pkg/errors" ) type baseBitAggFunc struct { diff --git a/executor/aggfuncs/func_count.go b/executor/aggfuncs/func_count.go index 7e76f5b7a97c0..ee57b1be64665 100644 --- a/executor/aggfuncs/func_count.go +++ b/executor/aggfuncs/func_count.go @@ -4,13 +4,13 @@ import ( "encoding/binary" "unsafe" - "github.com/juju/errors" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/types/json" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/set" + "github.com/pkg/errors" ) type baseCount struct { diff --git a/executor/aggfuncs/func_first_row.go b/executor/aggfuncs/func_first_row.go index 92d39bc9efc8d..0da037dc1e7bd 100644 --- a/executor/aggfuncs/func_first_row.go +++ b/executor/aggfuncs/func_first_row.go @@ -14,12 +14,12 @@ package aggfuncs import ( - "github.com/juju/errors" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/types/json" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/stringutil" + "github.com/pkg/errors" ) type basePartialResult4FirstRow struct { diff --git a/executor/aggfuncs/func_group_concat.go b/executor/aggfuncs/func_group_concat.go index f3a1b90f3d8b0..67af7f0018f16 100644 --- a/executor/aggfuncs/func_group_concat.go +++ b/executor/aggfuncs/func_group_concat.go @@ -17,11 +17,11 @@ import ( "bytes" "github.com/cznic/mathutil" - "github.com/juju/errors" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/set" + "github.com/pkg/errors" ) type baseGroupConcat4String struct { diff --git a/executor/aggfuncs/func_max_min.go b/executor/aggfuncs/func_max_min.go index c15c79e417298..3bceaa346e683 100644 --- a/executor/aggfuncs/func_max_min.go +++ b/executor/aggfuncs/func_max_min.go @@ -14,12 +14,12 @@ package aggfuncs import ( - "github.com/juju/errors" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/types/json" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/stringutil" + "github.com/pkg/errors" ) type partialResult4MaxMinInt struct { diff --git a/executor/aggfuncs/func_sum.go b/executor/aggfuncs/func_sum.go index e55d882a3d12e..e38fbc415b9c8 100644 --- a/executor/aggfuncs/func_sum.go +++ b/executor/aggfuncs/func_sum.go @@ -14,11 +14,11 @@ package aggfuncs import ( - "github.com/juju/errors" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/set" + "github.com/pkg/errors" ) type partialResult4SumFloat64 struct { diff --git a/executor/aggregate.go b/executor/aggregate.go index 4d1facd10e5b6..b2c6753539f3e 100644 --- a/executor/aggregate.go +++ b/executor/aggregate.go @@ -16,7 +16,6 @@ package executor import ( "sync" - "github.com/juju/errors" "github.com/pingcap/tidb/executor/aggfuncs" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/mysql" @@ -26,6 +25,7 @@ import ( "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/codec" "github.com/pingcap/tidb/util/set" + "github.com/pkg/errors" "github.com/spaolacci/murmur3" "golang.org/x/net/context" ) diff --git a/executor/analyze.go b/executor/analyze.go index 46b825706791a..12e49ff22649d 100644 --- a/executor/analyze.go +++ b/executor/analyze.go @@ -17,7 +17,6 @@ import ( "runtime" "strconv" - "github.com/juju/errors" "github.com/pingcap/tidb/distsql" "github.com/pingcap/tidb/domain" "github.com/pingcap/tidb/metrics" @@ -30,6 +29,7 @@ import ( "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/ranger" "github.com/pingcap/tipb/go-tipb" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" ) diff --git a/executor/batch_checker.go b/executor/batch_checker.go index ff132e191c500..3180e51403bc2 100644 --- a/executor/batch_checker.go +++ b/executor/batch_checker.go @@ -14,7 +14,6 @@ package executor import ( - "github.com/juju/errors" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/model" "github.com/pingcap/tidb/sessionctx" @@ -22,6 +21,7 @@ import ( "github.com/pingcap/tidb/table/tables" "github.com/pingcap/tidb/tablecodec" "github.com/pingcap/tidb/types" + "github.com/pkg/errors" ) type keyValue struct { diff --git a/executor/builder.go b/executor/builder.go index ceb0245c8a17f..51b6c1773814a 100644 --- a/executor/builder.go +++ b/executor/builder.go @@ -23,7 +23,6 @@ import ( "time" "github.com/cznic/sortutil" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/distsql" "github.com/pingcap/tidb/domain" @@ -45,6 +44,7 @@ import ( "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/ranger" "github.com/pingcap/tipb/go-tipb" + "github.com/pkg/errors" "golang.org/x/net/context" ) @@ -162,7 +162,7 @@ func (b *executorBuilder) build(p plan.Plan) Executor { case *plan.PhysicalIndexLookUpReader: return b.buildIndexLookUpReader(v) default: - b.err = ErrUnknownPlan.Gen("Unknown Plan %T", p) + b.err = ErrUnknownPlan.GenWithStack("Unknown Plan %T", p) return nil } } diff --git a/executor/checksum.go b/executor/checksum.go index 2a33e8efe8bea..04c5d18dc2dcd 100644 --- a/executor/checksum.go +++ b/executor/checksum.go @@ -16,7 +16,6 @@ package executor import ( "strconv" - "github.com/juju/errors" "github.com/pingcap/tidb/distsql" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/model" @@ -25,6 +24,7 @@ import ( "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/ranger" "github.com/pingcap/tipb/go-tipb" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" ) diff --git a/executor/compiler.go b/executor/compiler.go index 0df8f3ae8f4cc..be46979631d5e 100644 --- a/executor/compiler.go +++ b/executor/compiler.go @@ -16,7 +16,6 @@ package executor import ( "fmt" - "github.com/juju/errors" "github.com/opentracing/opentracing-go" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/config" @@ -24,6 +23,7 @@ import ( "github.com/pingcap/tidb/metrics" "github.com/pingcap/tidb/plan" "github.com/pingcap/tidb/sessionctx" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" ) diff --git a/executor/ddl.go b/executor/ddl.go index 0f19c49d1a98b..d972c69a7b18e 100644 --- a/executor/ddl.go +++ b/executor/ddl.go @@ -17,7 +17,6 @@ import ( "fmt" "strings" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/domain" @@ -28,6 +27,7 @@ import ( "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/sqlexec" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" ) @@ -168,7 +168,7 @@ func (e *DDLExec) executeDropDatabase(s *ast.DropDatabaseStmt) error { if s.IfExists { err = nil } else { - err = infoschema.ErrDatabaseDropExists.GenByArgs(s.Name) + err = infoschema.ErrDatabaseDropExists.GenWithStackByArgs(s.Name) } } sessionVars := e.ctx.GetSessionVars() @@ -246,7 +246,7 @@ func (e *DDLExec) executeDropTable(s *ast.DropTableStmt) error { } } if len(notExistTables) > 0 && !s.IfExists { - return infoschema.ErrTableDropExists.GenByArgs(strings.Join(notExistTables, ",")) + return infoschema.ErrTableDropExists.GenWithStackByArgs(strings.Join(notExistTables, ",")) } return nil } diff --git a/executor/delete.go b/executor/delete.go index 77f37e73c27b8..c60e8b9200018 100644 --- a/executor/delete.go +++ b/executor/delete.go @@ -14,13 +14,13 @@ package executor import ( - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/table" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" + "github.com/pkg/errors" "golang.org/x/net/context" ) @@ -121,7 +121,7 @@ func (e *DeleteExec) deleteSingleTableByChunk(ctx context.Context) error { e.ctx.StmtCommit() if err = e.ctx.NewTxn(); err != nil { // We should return a special error for batch insert. - return ErrBatchInsertFail.Gen("BatchDelete failed with error: %v", err) + return ErrBatchInsertFail.GenWithStack("BatchDelete failed with error: %v", err) } rowCount = 0 } diff --git a/executor/distsql.go b/executor/distsql.go index b16c04aad1901..115afa73694f6 100644 --- a/executor/distsql.go +++ b/executor/distsql.go @@ -22,7 +22,6 @@ import ( "time" "unsafe" - "github.com/juju/errors" "github.com/pingcap/tidb/distsql" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/kv" @@ -39,6 +38,7 @@ import ( "github.com/pingcap/tidb/util/memory" "github.com/pingcap/tidb/util/ranger" "github.com/pingcap/tipb/go-tipb" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" ) diff --git a/executor/executor.go b/executor/executor.go index 7932c0a90a2aa..812eda2bcd02e 100644 --- a/executor/executor.go +++ b/executor/executor.go @@ -20,7 +20,6 @@ import ( "sync/atomic" "github.com/cznic/mathutil" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/infoschema" @@ -34,6 +33,7 @@ import ( "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/admin" "github.com/pingcap/tidb/util/chunk" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" ) @@ -385,7 +385,7 @@ func (e *CheckTableExec) Next(ctx context.Context, chk *chunk.Chunk) error { if err != nil { log.Warnf("%v error:%v", t.Name, errors.ErrorStack(err)) if admin.ErrDataInConsistent.Equal(err) { - return ErrAdminCheckTable.Gen("%v err:%v", t.Name, err) + return ErrAdminCheckTable.GenWithStack("%v err:%v", t.Name, err) } return errors.Errorf("%v err:%v", t.Name, err) diff --git a/executor/executor_test.go b/executor/executor_test.go index cfb63ca36583c..e45effd90f412 100644 --- a/executor/executor_test.go +++ b/executor/executor_test.go @@ -26,7 +26,6 @@ import ( "time" gofail "github.com/etcd-io/gofail/runtime" - "github.com/juju/errors" . "github.com/pingcap/check" pb "github.com/pingcap/kvproto/pkg/kvrpcpb" "github.com/pingcap/tidb/config" @@ -59,6 +58,7 @@ import ( "github.com/pingcap/tidb/util/testkit" "github.com/pingcap/tidb/util/testleak" "github.com/pingcap/tidb/util/testutil" + "github.com/pkg/errors" "golang.org/x/net/context" ) @@ -990,12 +990,12 @@ func (s *testSuite) TestUnion(c *C) { _, err := tk.Exec("select 1 from (select a from t limit 1 union all select a from t limit 1) tmp") c.Assert(err, NotNil) - terr := errors.Trace(err).(*errors.Err).Cause().(*terror.Error) + terr := errors.Cause(err).(*terror.Error) c.Assert(terr.Code(), Equals, terror.ErrCode(mysql.ErrWrongUsage)) _, err = tk.Exec("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.Trace(err).(*errors.Err).Cause().(*terror.Error) + terr = errors.Cause(err).(*terror.Error) 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") @@ -1283,23 +1283,23 @@ func (s *testSuite) TestJSON(c *C) { _, err = tk.Exec(`create table test_bad_json(a json default '{}')`) c.Assert(err, NotNil) - terr = errors.Trace(err).(*errors.Err).Cause().(*terror.Error) + terr = errors.Cause(err).(*terror.Error) 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.Trace(err).(*errors.Err).Cause().(*terror.Error) + terr = errors.Cause(err).(*terror.Error) 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.Trace(err).(*errors.Err).Cause().(*terror.Error) + terr = errors.Cause(err).(*terror.Error) 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.Trace(err).(*errors.Err).Cause().(*terror.Error) + terr = errors.Cause(err).(*terror.Error) c.Assert(terr.Code(), Equals, terror.ErrCode(mysql.ErrJSONUsedAsKey)) // check CAST AS JSON. @@ -1378,7 +1378,7 @@ func (s *testSuite) TestGeneratedColumnWrite(c *C) { _, err := tk.Exec(tt.stmt) if tt.err != 0 { c.Assert(err, NotNil, Commentf("sql is `%v`", tt.stmt)) - terr := errors.Trace(err).(*errors.Err).Cause().(*terror.Error) + terr := errors.Cause(err).(*terror.Error) c.Assert(terr.Code(), Equals, terror.ErrCode(tt.err), Commentf("sql is %v", tt.stmt)) } else { c.Assert(err, IsNil) @@ -1513,7 +1513,7 @@ func (s *testSuite) TestGeneratedColumnRead(c *C) { _, err := tk.Exec(tt.stmt) if tt.err != 0 { c.Assert(err, NotNil) - terr := errors.Trace(err).(*errors.Err).Cause().(*terror.Error) + terr := errors.Cause(err).(*terror.Error) c.Assert(terr.Code(), Equals, terror.ErrCode(tt.err)) } else { c.Assert(err, IsNil) @@ -2651,7 +2651,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.Trace(err).(*errors.Err).Cause().(*terror.Error) + terr := errors.Cause(err).(*terror.Error) c.Assert(terr.Code(), Equals, terror.ErrCode(mysql.ErrWrongTableName)) } diff --git a/executor/grant.go b/executor/grant.go index 5d82141cc8cea..8bff64ddba034 100644 --- a/executor/grant.go +++ b/executor/grant.go @@ -17,7 +17,6 @@ import ( "fmt" "strings" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/domain" "github.com/pingcap/tidb/infoschema" @@ -27,6 +26,7 @@ import ( "github.com/pingcap/tidb/table" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/sqlexec" + "github.com/pkg/errors" "golang.org/x/net/context" ) diff --git a/executor/index_lookup_join.go b/executor/index_lookup_join.go index 92378d80a1e07..cf380e9534494 100644 --- a/executor/index_lookup_join.go +++ b/executor/index_lookup_join.go @@ -20,7 +20,6 @@ import ( "sync" "unsafe" - "github.com/juju/errors" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/sessionctx" @@ -32,6 +31,7 @@ import ( "github.com/pingcap/tidb/util/memory" "github.com/pingcap/tidb/util/mvmap" "github.com/pingcap/tidb/util/ranger" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" ) diff --git a/executor/insert.go b/executor/insert.go index 6587b9650e020..380e7e954e43c 100644 --- a/executor/insert.go +++ b/executor/insert.go @@ -14,7 +14,6 @@ package executor import ( - "github.com/juju/errors" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/mysql" @@ -22,6 +21,7 @@ import ( "github.com/pingcap/tidb/tablecodec" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" ) diff --git a/executor/insert_common.go b/executor/insert_common.go index c011c1aa6fe37..8a4d7856dc93a 100644 --- a/executor/insert_common.go +++ b/executor/insert_common.go @@ -16,7 +16,6 @@ package executor import ( "fmt" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/kv" @@ -25,6 +24,7 @@ import ( "github.com/pingcap/tidb/table" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" ) @@ -176,11 +176,11 @@ func (e *InsertValues) handleErr(col *table.Column, val *types.Datum, rowIdx int } if types.ErrOverflow.Equal(err) { - return types.ErrWarnDataOutOfRange.GenByArgs(col.Name.O, rowIdx+1) + return types.ErrWarnDataOutOfRange.GenWithStackByArgs(col.Name.O, rowIdx+1) } if types.ErrTruncated.Equal(err) { valStr, _ := val.ToString() - return table.ErrTruncatedWrongValueForField.GenByArgs(types.TypeStr(col.Tp), valStr, col.Name.O, rowIdx+1) + return table.ErrTruncatedWrongValueForField.GenWithStackByArgs(types.TypeStr(col.Tp), valStr, col.Name.O, rowIdx+1) } return e.filterErr(err) } @@ -283,7 +283,7 @@ func (e *InsertValues) insertRowsFromSelect(ctx context.Context, cols []*table.C rows = rows[:0] if err := e.ctx.NewTxn(); err != nil { // We should return a special error for batch insert. - return ErrBatchInsertFail.Gen("BatchInsert failed with error: %v", err) + return ErrBatchInsertFail.GenWithStack("BatchInsert failed with error: %v", err) } if !sessVars.LightningMode { sessVars.GetWriteStmtBufs().BufStore = kv.NewBufferStore(e.ctx.Txn(), kv.TempTxnMemBufCap) diff --git a/executor/join.go b/executor/join.go index 9480dfe5ef572..a1f1191da76c5 100644 --- a/executor/join.go +++ b/executor/join.go @@ -19,7 +19,6 @@ import ( "sync/atomic" "unsafe" - "github.com/juju/errors" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/plan" "github.com/pingcap/tidb/terror" @@ -28,6 +27,7 @@ import ( "github.com/pingcap/tidb/util/codec" "github.com/pingcap/tidb/util/memory" "github.com/pingcap/tidb/util/mvmap" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" ) diff --git a/executor/joiner.go b/executor/joiner.go index 5afa69676e34b..f720be555fb28 100644 --- a/executor/joiner.go +++ b/executor/joiner.go @@ -14,12 +14,12 @@ package executor import ( - "github.com/juju/errors" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/plan" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" + "github.com/pkg/errors" ) var ( diff --git a/executor/load_data.go b/executor/load_data.go index 46e9eb99c9c0a..2d5b2b018f66b 100644 --- a/executor/load_data.go +++ b/executor/load_data.go @@ -18,12 +18,12 @@ import ( "fmt" "strings" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/table" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" ) diff --git a/executor/load_stats.go b/executor/load_stats.go index 66c456dd7edfb..edad12113f5bc 100644 --- a/executor/load_stats.go +++ b/executor/load_stats.go @@ -16,11 +16,11 @@ package executor import ( "encoding/json" - "github.com/juju/errors" "github.com/pingcap/tidb/domain" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/statistics" "github.com/pingcap/tidb/util/chunk" + "github.com/pkg/errors" "golang.org/x/net/context" ) diff --git a/executor/merge_join.go b/executor/merge_join.go index 893b29529267c..134be86d410c8 100644 --- a/executor/merge_join.go +++ b/executor/merge_join.go @@ -14,11 +14,11 @@ package executor import ( - "github.com/juju/errors" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/sessionctx/stmtctx" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/memory" + "github.com/pkg/errors" "golang.org/x/net/context" ) diff --git a/executor/point_get.go b/executor/point_get.go index d0d751fe2ced2..f74dea4fb9b35 100644 --- a/executor/point_get.go +++ b/executor/point_get.go @@ -14,7 +14,6 @@ package executor import ( - "github.com/juju/errors" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/model" @@ -27,6 +26,7 @@ import ( "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/codec" + "github.com/pkg/errors" "golang.org/x/net/context" ) @@ -102,7 +102,7 @@ func (e *PointGetExecutor) Next(ctx context.Context, chk *chunk.Chunk) error { } if len(val) == 0 { if e.idxInfo != nil { - return kv.ErrNotExist.Gen("inconsistent extra index %s, handle %d not found in table", + return kv.ErrNotExist.GenWithStack("inconsistent extra index %s, handle %d not found in table", e.idxInfo.Name.O, e.handle) } return nil diff --git a/executor/prepared.go b/executor/prepared.go index b1f0c1e3f9c0e..95400dd2d2bde 100644 --- a/executor/prepared.go +++ b/executor/prepared.go @@ -18,7 +18,6 @@ import ( "sort" "fmt" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/expression" @@ -31,6 +30,7 @@ import ( "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/memory" "github.com/pingcap/tidb/util/sqlexec" + "github.com/pkg/errors" "golang.org/x/net/context" ) diff --git a/executor/prepared_test.go b/executor/prepared_test.go index c22bbcdb699aa..feb0e10829bab 100644 --- a/executor/prepared_test.go +++ b/executor/prepared_test.go @@ -17,12 +17,12 @@ import ( "math" "strings" - "github.com/juju/errors" . "github.com/pingcap/check" "github.com/pingcap/tidb/executor" "github.com/pingcap/tidb/plan" "github.com/pingcap/tidb/terror" "github.com/pingcap/tidb/util/testkit" + "github.com/pkg/errors" "golang.org/x/net/context" ) diff --git a/executor/projection.go b/executor/projection.go index 8df62681283a3..83609ed6f1893 100644 --- a/executor/projection.go +++ b/executor/projection.go @@ -14,10 +14,10 @@ package executor import ( - "github.com/juju/errors" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/util/chunk" + "github.com/pkg/errors" "golang.org/x/net/context" ) diff --git a/executor/replace.go b/executor/replace.go index 1debefb3cf9e5..cbff58f7e9fb9 100644 --- a/executor/replace.go +++ b/executor/replace.go @@ -14,11 +14,11 @@ package executor import ( - "github.com/juju/errors" "github.com/pingcap/tidb/table/tables" "github.com/pingcap/tidb/tablecodec" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" ) diff --git a/executor/revoke.go b/executor/revoke.go index 405dd79422a07..3f2edb6c7249b 100644 --- a/executor/revoke.go +++ b/executor/revoke.go @@ -16,7 +16,6 @@ package executor import ( "fmt" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/domain" "github.com/pingcap/tidb/infoschema" @@ -25,6 +24,7 @@ import ( "github.com/pingcap/tidb/table" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/sqlexec" + "github.com/pkg/errors" "golang.org/x/net/context" ) diff --git a/executor/set.go b/executor/set.go index 29f783a96f47a..76562a6a4f8f9 100644 --- a/executor/set.go +++ b/executor/set.go @@ -18,7 +18,6 @@ import ( "strings" "time" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/domain" "github.com/pingcap/tidb/expression" @@ -29,6 +28,7 @@ import ( "github.com/pingcap/tidb/util/charset" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/sqlexec" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" ) @@ -114,7 +114,7 @@ func (e *SetExecutor) setSysVariable(name string, v *expression.VarAssignment) e sessionVars := e.ctx.GetSessionVars() sysVar := variable.GetSysVar(name) if sysVar == nil { - return variable.UnknownSystemVar.GenByArgs(name) + return variable.UnknownSystemVar.GenWithStackByArgs(name) } if sysVar.Scope == variable.ScopeNone { return errors.Errorf("Variable '%s' is a read only variable", name) @@ -201,7 +201,7 @@ func validateSnapshot(ctx sessionctx.Context, snapshotTS uint64) error { } safePointTS := variable.GoTimeToTS(safePointTime) if safePointTS > snapshotTS { - return variable.ErrSnapshotTooOld.GenByArgs(safePointString) + return variable.ErrSnapshotTooOld.GenWithStackByArgs(safePointString) } return nil } diff --git a/executor/show.go b/executor/show.go index 1b2c21f81549f..a03c76370150d 100644 --- a/executor/show.go +++ b/executor/show.go @@ -22,7 +22,6 @@ import ( "time" "github.com/cznic/mathutil" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/infoschema" "github.com/pingcap/tidb/model" @@ -38,6 +37,7 @@ import ( "github.com/pingcap/tidb/util/charset" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/format" + "github.com/pkg/errors" "golang.org/x/net/context" ) @@ -661,7 +661,7 @@ func (e *ShowExec) fetchShowCreateTable() error { func (e *ShowExec) fetchShowCreateDatabase() error { db, ok := e.is.SchemaByName(e.DBName) if !ok { - return infoschema.ErrDatabaseNotExists.GenByArgs(e.DBName.O) + return infoschema.ErrDatabaseNotExists.GenWithStackByArgs(e.DBName.O) } var buf bytes.Buffer diff --git a/executor/show_stats.go b/executor/show_stats.go index 3cc82f941b5c0..6c8c4f0ddc258 100644 --- a/executor/show_stats.go +++ b/executor/show_stats.go @@ -16,12 +16,12 @@ package executor import ( "time" - "github.com/juju/errors" "github.com/pingcap/tidb/domain" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/statistics" "github.com/pingcap/tidb/store/tikv/oracle" "github.com/pingcap/tidb/types" + "github.com/pkg/errors" ) func (e *ShowExec) fetchShowStatsMeta() error { diff --git a/executor/show_test.go b/executor/show_test.go index a3f8e4ac7604a..b79be5f383697 100644 --- a/executor/show_test.go +++ b/executor/show_test.go @@ -18,7 +18,6 @@ import ( "strconv" "time" - "github.com/juju/errors" . "github.com/pingcap/check" "github.com/pingcap/tidb/domain" "github.com/pingcap/tidb/meta/autoid" @@ -32,6 +31,7 @@ import ( "github.com/pingcap/tidb/util/auth" "github.com/pingcap/tidb/util/testkit" "github.com/pingcap/tidb/util/testutil" + "github.com/pkg/errors" "golang.org/x/net/context" ) diff --git a/executor/simple.go b/executor/simple.go index a0b3deb17ad4d..7c3c1c5dc0030 100644 --- a/executor/simple.go +++ b/executor/simple.go @@ -17,7 +17,6 @@ import ( "fmt" "strings" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/domain" @@ -30,6 +29,7 @@ import ( "github.com/pingcap/tidb/util/auth" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/sqlexec" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" ) @@ -87,7 +87,7 @@ func (e *SimpleExec) executeUse(s *ast.UseStmt) error { dbname := model.NewCIStr(s.DBName) dbinfo, exists := e.is.SchemaByName(dbname) if !exists { - return infoschema.ErrDatabaseNotExists.GenByArgs(dbname) + return infoschema.ErrDatabaseNotExists.GenWithStackByArgs(dbname) } e.ctx.GetSessionVars().CurrentDB = dbname.O // character_set_database is the character set used by the default database. @@ -210,7 +210,7 @@ func (e *SimpleExec) executeAlterUser(s *ast.AlterUserStmt) error { if err != nil { return errors.Trace(err) } - return ErrCannotUser.GenByArgs("ALTER USER", strings.Join(failedUsers, ",")) + return ErrCannotUser.GenWithStackByArgs("ALTER USER", strings.Join(failedUsers, ",")) } domain.GetDomain(e.ctx).NotifyUpdatePrivilege(e.ctx) return nil @@ -269,7 +269,7 @@ func (e *SimpleExec) executeDropUser(s *ast.DropUserStmt) error { } } if len(failedUsers) > 0 { - return ErrCannotUser.GenByArgs("DROP USER", strings.Join(failedUsers, ",")) + return ErrCannotUser.GenWithStackByArgs("DROP USER", strings.Join(failedUsers, ",")) } domain.GetDomain(e.ctx).NotifyUpdatePrivilege(e.ctx) return nil diff --git a/executor/simple_test.go b/executor/simple_test.go index 208fcb79caaf2..a154304076d2c 100644 --- a/executor/simple_test.go +++ b/executor/simple_test.go @@ -187,7 +187,7 @@ func (s *testSuite) TestUser(c *C) { // Test drop user meet error _, err = tk.Exec(dropUserSQL) - c.Assert(terror.ErrorEqual(err, executor.ErrCannotUser.GenByArgs("DROP USER", "")), IsTrue, Commentf("err %v", err)) + c.Assert(terror.ErrorEqual(err, executor.ErrCannotUser.GenWithStackByArgs("DROP USER", "")), IsTrue, Commentf("err %v", err)) createUserSQL = `CREATE USER 'test1'@'localhost'` tk.MustExec(createUserSQL) @@ -196,7 +196,7 @@ func (s *testSuite) TestUser(c *C) { dropUserSQL = `DROP USER 'test1'@'localhost', 'test2'@'localhost', 'test3'@'localhost';` _, err = tk.Exec(dropUserSQL) - c.Assert(terror.ErrorEqual(err, executor.ErrCannotUser.GenByArgs("DROP USER", "")), IsTrue, Commentf("err %v", err)) + c.Assert(terror.ErrorEqual(err, executor.ErrCannotUser.GenWithStackByArgs("DROP USER", "")), IsTrue, Commentf("err %v", err)) } func (s *testSuite) TestSetPwd(c *C) { diff --git a/executor/sort.go b/executor/sort.go index b1fff62b58932..9f38ab13edbf2 100644 --- a/executor/sort.go +++ b/executor/sort.go @@ -17,12 +17,12 @@ import ( "container/heap" "sort" - "github.com/juju/errors" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/plan" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/memory" + "github.com/pkg/errors" "golang.org/x/net/context" ) diff --git a/executor/table_reader.go b/executor/table_reader.go index b3aa6a1c3f0cf..c46d8278e83e5 100644 --- a/executor/table_reader.go +++ b/executor/table_reader.go @@ -14,7 +14,6 @@ package executor import ( - "github.com/juju/errors" "github.com/pingcap/tidb/distsql" "github.com/pingcap/tidb/model" "github.com/pingcap/tidb/plan" @@ -23,6 +22,7 @@ import ( "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/ranger" tipb "github.com/pingcap/tipb/go-tipb" + "github.com/pkg/errors" "golang.org/x/net/context" ) diff --git a/executor/trace.go b/executor/trace.go index 23d1cd570e778..aa368bcee8759 100644 --- a/executor/trace.go +++ b/executor/trace.go @@ -16,13 +16,13 @@ package executor import ( "time" - "github.com/juju/errors" "github.com/opentracing/basictracer-go" opentracing "github.com/opentracing/opentracing-go" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/plan" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/tracing" + "github.com/pkg/errors" "golang.org/x/net/context" ) diff --git a/executor/union_scan.go b/executor/union_scan.go index 5efdd74d80a1f..7a15525c8373c 100644 --- a/executor/union_scan.go +++ b/executor/union_scan.go @@ -16,12 +16,12 @@ package executor import ( "sort" - "github.com/juju/errors" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/model" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" + "github.com/pkg/errors" "golang.org/x/net/context" ) diff --git a/executor/update.go b/executor/update.go index 39be67de247fb..4ab7fc345e0fb 100644 --- a/executor/update.go +++ b/executor/update.go @@ -14,13 +14,13 @@ package executor import ( - "github.com/juju/errors" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/model" "github.com/pingcap/tidb/table" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" + "github.com/pkg/errors" "golang.org/x/net/context" ) diff --git a/executor/write.go b/executor/write.go index bb7f40e1dbb1e..dc4c993182720 100644 --- a/executor/write.go +++ b/executor/write.go @@ -16,7 +16,6 @@ package executor import ( "strings" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/mysql" @@ -24,6 +23,8 @@ import ( "github.com/pingcap/tidb/table" "github.com/pingcap/tidb/table/tables" "github.com/pingcap/tidb/types" + "github.com/pkg/errors" + log "github.com/sirupsen/logrus" ) var ( @@ -182,8 +183,9 @@ func updateRecord(ctx sessionctx.Context, h int64, oldData, newData []types.Datu // types.ErrDataTooLong is produced in types.ProduceStrWithSpecifiedTp, there is no column info in there, // so we reset the error msg here, and wrap old err with errors.Wrap. func resetErrDataTooLong(colName string, rowIdx int, err error) error { - newErr := types.ErrDataTooLong.Gen("Data too long for column '%v' at row %v", colName, rowIdx) - return errors.Wrap(err, newErr) + newErr := types.ErrDataTooLong.GenWithStack("Data too long for column '%v' at row %v", colName, rowIdx) + log.Error(err) + return errors.Trace(newErr) } func getTableOffset(schema *expression.Schema, handleCol *expression.Column) int { diff --git a/expression/aggregation/aggregation.go b/expression/aggregation/aggregation.go index 8798ab9dbf5d0..deec3c931b71f 100644 --- a/expression/aggregation/aggregation.go +++ b/expression/aggregation/aggregation.go @@ -16,7 +16,6 @@ package aggregation import ( "bytes" "fmt" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/model" @@ -27,6 +26,7 @@ import ( "github.com/pingcap/tidb/util/charset" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tipb/go-tipb" + "github.com/pkg/errors" ) // Aggregation stands for aggregate functions. diff --git a/expression/aggregation/avg.go b/expression/aggregation/avg.go index 2ec1ffa532d47..b934e6be2eb6a 100644 --- a/expression/aggregation/avg.go +++ b/expression/aggregation/avg.go @@ -15,12 +15,12 @@ package aggregation import ( "github.com/cznic/mathutil" - "github.com/juju/errors" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/sessionctx/stmtctx" "github.com/pingcap/tidb/terror" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" + "github.com/pkg/errors" ) type avgFunction struct { diff --git a/expression/aggregation/bit_and.go b/expression/aggregation/bit_and.go index 5d619038bc658..6fe2ef8f3ceba 100644 --- a/expression/aggregation/bit_and.go +++ b/expression/aggregation/bit_and.go @@ -16,10 +16,10 @@ package aggregation import ( "math" - "github.com/juju/errors" "github.com/pingcap/tidb/sessionctx/stmtctx" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" + "github.com/pkg/errors" ) type bitAndFunction struct { diff --git a/expression/aggregation/bit_or.go b/expression/aggregation/bit_or.go index 20445de5e6ac9..2ac5ab4a5e6df 100644 --- a/expression/aggregation/bit_or.go +++ b/expression/aggregation/bit_or.go @@ -14,10 +14,10 @@ package aggregation import ( - "github.com/juju/errors" "github.com/pingcap/tidb/sessionctx/stmtctx" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" + "github.com/pkg/errors" ) type bitOrFunction struct { diff --git a/expression/aggregation/bit_xor.go b/expression/aggregation/bit_xor.go index 5b82d5f533a69..8cbfdeeb5a159 100644 --- a/expression/aggregation/bit_xor.go +++ b/expression/aggregation/bit_xor.go @@ -14,10 +14,10 @@ package aggregation import ( - "github.com/juju/errors" "github.com/pingcap/tidb/sessionctx/stmtctx" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" + "github.com/pkg/errors" ) type bitXorFunction struct { diff --git a/expression/aggregation/concat.go b/expression/aggregation/concat.go index d2ee465feabbf..c411d6b340526 100644 --- a/expression/aggregation/concat.go +++ b/expression/aggregation/concat.go @@ -18,11 +18,11 @@ import ( "fmt" "github.com/cznic/mathutil" - "github.com/juju/errors" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/sessionctx/stmtctx" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" + "github.com/pkg/errors" ) type concatFunction struct { diff --git a/expression/aggregation/count.go b/expression/aggregation/count.go index b5529d07be5f8..5a40d27bda188 100644 --- a/expression/aggregation/count.go +++ b/expression/aggregation/count.go @@ -14,10 +14,10 @@ package aggregation import ( - "github.com/juju/errors" "github.com/pingcap/tidb/sessionctx/stmtctx" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" + "github.com/pkg/errors" ) type countFunction struct { diff --git a/expression/aggregation/first_row.go b/expression/aggregation/first_row.go index d46dd668edc8c..89601eb674826 100644 --- a/expression/aggregation/first_row.go +++ b/expression/aggregation/first_row.go @@ -14,10 +14,10 @@ package aggregation import ( - "github.com/juju/errors" "github.com/pingcap/tidb/sessionctx/stmtctx" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" + "github.com/pkg/errors" ) type firstRowFunction struct { diff --git a/expression/aggregation/max_min.go b/expression/aggregation/max_min.go index 12ea61aa39899..3e919c224ba98 100644 --- a/expression/aggregation/max_min.go +++ b/expression/aggregation/max_min.go @@ -14,10 +14,10 @@ package aggregation import ( - "github.com/juju/errors" "github.com/pingcap/tidb/sessionctx/stmtctx" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" + "github.com/pkg/errors" ) type maxMinFunction struct { diff --git a/expression/aggregation/util.go b/expression/aggregation/util.go index 90a4a075563ba..eb9b297364974 100644 --- a/expression/aggregation/util.go +++ b/expression/aggregation/util.go @@ -14,11 +14,11 @@ package aggregation import ( - "github.com/juju/errors" "github.com/pingcap/tidb/sessionctx/stmtctx" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/codec" "github.com/pingcap/tidb/util/mvmap" + "github.com/pkg/errors" ) // distinctChecker stores existing keys and checks if given data is distinct. diff --git a/expression/builtin.go b/expression/builtin.go index 8ddbff4f340c3..ba165008278f9 100644 --- a/expression/builtin.go +++ b/expression/builtin.go @@ -298,7 +298,7 @@ type baseFunctionClass struct { func (b *baseFunctionClass) verifyArgs(args []Expression) error { l := len(args) if l < b.minArgs || (b.maxArgs != -1 && l > b.maxArgs) { - return ErrIncorrectParameterCount.GenByArgs(b.funcName) + return ErrIncorrectParameterCount.GenWithStackByArgs(b.funcName) } return nil } diff --git a/expression/builtin_arithmetic.go b/expression/builtin_arithmetic.go index 4e7117b637e10..de20e3b4a10b7 100644 --- a/expression/builtin_arithmetic.go +++ b/expression/builtin_arithmetic.go @@ -18,13 +18,13 @@ import ( "math" "github.com/cznic/mathutil" - "github.com/juju/errors" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/terror" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tipb/go-tipb" + "github.com/pkg/errors" ) var ( @@ -205,25 +205,25 @@ func (s *builtinArithmeticPlusIntSig) evalInt(row chunk.Row) (val int64, isNull switch { case isLHSUnsigned && isRHSUnsigned: if uint64(a) > math.MaxUint64-uint64(b) { - return 0, true, types.ErrOverflow.GenByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%s + %s)", s.args[0].String(), s.args[1].String())) + return 0, true, types.ErrOverflow.GenWithStackByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%s + %s)", s.args[0].String(), s.args[1].String())) } case isLHSUnsigned && !isRHSUnsigned: if b < 0 && uint64(-b) > uint64(a) { - return 0, true, types.ErrOverflow.GenByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%s + %s)", s.args[0].String(), s.args[1].String())) + return 0, true, types.ErrOverflow.GenWithStackByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%s + %s)", s.args[0].String(), s.args[1].String())) } if b > 0 && uint64(a) > math.MaxUint64-uint64(b) { - return 0, true, types.ErrOverflow.GenByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%s + %s)", s.args[0].String(), s.args[1].String())) + return 0, true, types.ErrOverflow.GenWithStackByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%s + %s)", s.args[0].String(), s.args[1].String())) } case !isLHSUnsigned && isRHSUnsigned: if a < 0 && uint64(-a) > uint64(b) { - return 0, true, types.ErrOverflow.GenByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%s + %s)", s.args[0].String(), s.args[1].String())) + return 0, true, types.ErrOverflow.GenWithStackByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%s + %s)", s.args[0].String(), s.args[1].String())) } if a > 0 && uint64(b) > math.MaxInt64-uint64(a) { - return 0, true, types.ErrOverflow.GenByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%s + %s)", s.args[0].String(), s.args[1].String())) + return 0, true, types.ErrOverflow.GenWithStackByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%s + %s)", s.args[0].String(), s.args[1].String())) } case !isLHSUnsigned && !isRHSUnsigned: if (a > 0 && b > math.MaxInt64-a) || (a < 0 && b < math.MinInt64-a) { - return 0, true, types.ErrOverflow.GenByArgs("BIGINT", fmt.Sprintf("(%s + %s)", s.args[0].String(), s.args[1].String())) + return 0, true, types.ErrOverflow.GenWithStackByArgs("BIGINT", fmt.Sprintf("(%s + %s)", s.args[0].String(), s.args[1].String())) } } @@ -277,7 +277,7 @@ func (s *builtinArithmeticPlusRealSig) evalReal(row chunk.Row) (float64, bool, e return 0, isNull, errors.Trace(err) } if (a > 0 && b > math.MaxFloat64-a) || (a < 0 && b < -math.MaxFloat64-a) { - return 0, true, types.ErrOverflow.GenByArgs("DOUBLE", fmt.Sprintf("(%s + %s)", s.args[0].String(), s.args[1].String())) + return 0, true, types.ErrOverflow.GenWithStackByArgs("DOUBLE", fmt.Sprintf("(%s + %s)", s.args[0].String(), s.args[1].String())) } return a + b, false, nil } @@ -337,7 +337,7 @@ func (s *builtinArithmeticMinusRealSig) evalReal(row chunk.Row) (float64, bool, return 0, isNull, errors.Trace(err) } if (a > 0 && -b > math.MaxFloat64-a) || (a < 0 && -b < -math.MaxFloat64-a) { - return 0, true, types.ErrOverflow.GenByArgs("DOUBLE", fmt.Sprintf("(%s - %s)", s.args[0].String(), s.args[1].String())) + return 0, true, types.ErrOverflow.GenWithStackByArgs("DOUBLE", fmt.Sprintf("(%s - %s)", s.args[0].String(), s.args[1].String())) } return a - b, false, nil } @@ -395,34 +395,34 @@ func (s *builtinArithmeticMinusIntSig) evalInt(row chunk.Row) (val int64, isNull if forceToSigned && mysql.HasUnsignedFlag(s.args[0].GetType().Flag) { if a < 0 || (a > math.MaxInt64) { - return 0, true, types.ErrOverflow.GenByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%s - %s)", s.args[0].String(), s.args[1].String())) + return 0, true, types.ErrOverflow.GenWithStackByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%s - %s)", s.args[0].String(), s.args[1].String())) } } if forceToSigned && mysql.HasUnsignedFlag(s.args[1].GetType().Flag) { if b < 0 || (b > math.MaxInt64) { - return 0, true, types.ErrOverflow.GenByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%s - %s)", s.args[0].String(), s.args[1].String())) + return 0, true, types.ErrOverflow.GenWithStackByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%s - %s)", s.args[0].String(), s.args[1].String())) } } switch { case isLHSUnsigned && isRHSUnsigned: if uint64(a) < uint64(b) { - return 0, true, types.ErrOverflow.GenByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%s - %s)", s.args[0].String(), s.args[1].String())) + return 0, true, types.ErrOverflow.GenWithStackByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%s - %s)", s.args[0].String(), s.args[1].String())) } case isLHSUnsigned && !isRHSUnsigned: if b >= 0 && uint64(a) < uint64(b) { - return 0, true, types.ErrOverflow.GenByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%s - %s)", s.args[0].String(), s.args[1].String())) + return 0, true, types.ErrOverflow.GenWithStackByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%s - %s)", s.args[0].String(), s.args[1].String())) } if b < 0 && uint64(a) > math.MaxUint64-uint64(-b) { - return 0, true, types.ErrOverflow.GenByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%s - %s)", s.args[0].String(), s.args[1].String())) + return 0, true, types.ErrOverflow.GenWithStackByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%s - %s)", s.args[0].String(), s.args[1].String())) } case !isLHSUnsigned && isRHSUnsigned: if uint64(a-math.MinInt64) < uint64(b) { - return 0, true, types.ErrOverflow.GenByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%s - %s)", s.args[0].String(), s.args[1].String())) + return 0, true, types.ErrOverflow.GenWithStackByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%s - %s)", s.args[0].String(), s.args[1].String())) } case !isLHSUnsigned && !isRHSUnsigned: if (a > 0 && -b > math.MaxInt64-a) || (a < 0 && -b < math.MinInt64-a) { - return 0, true, types.ErrOverflow.GenByArgs("BIGINT", fmt.Sprintf("(%s - %s)", s.args[0].String(), s.args[1].String())) + return 0, true, types.ErrOverflow.GenWithStackByArgs("BIGINT", fmt.Sprintf("(%s - %s)", s.args[0].String(), s.args[1].String())) } } return a - b, false, nil @@ -509,7 +509,7 @@ func (s *builtinArithmeticMultiplyRealSig) evalReal(row chunk.Row) (float64, boo } result := a * b if math.IsInf(result, 0) { - return 0, true, types.ErrOverflow.GenByArgs("DOUBLE", fmt.Sprintf("(%s * %s)", s.args[0].String(), s.args[1].String())) + return 0, true, types.ErrOverflow.GenWithStackByArgs("DOUBLE", fmt.Sprintf("(%s * %s)", s.args[0].String(), s.args[1].String())) } return result, false, nil } @@ -544,7 +544,7 @@ func (s *builtinArithmeticMultiplyIntUnsignedSig) evalInt(row chunk.Row) (val in unsignedB := uint64(b) result := unsignedA * unsignedB if unsignedA != 0 && result/unsignedA != unsignedB { - return 0, true, types.ErrOverflow.GenByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%s * %s)", s.args[0].String(), s.args[1].String())) + return 0, true, types.ErrOverflow.GenWithStackByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%s * %s)", s.args[0].String(), s.args[1].String())) } return int64(result), false, nil } @@ -560,7 +560,7 @@ func (s *builtinArithmeticMultiplyIntSig) evalInt(row chunk.Row) (val int64, isN } result := a * b if a != 0 && result/a != b { - return 0, true, types.ErrOverflow.GenByArgs("BIGINT", fmt.Sprintf("(%s * %s)", s.args[0].String(), s.args[1].String())) + return 0, true, types.ErrOverflow.GenWithStackByArgs("BIGINT", fmt.Sprintf("(%s * %s)", s.args[0].String(), s.args[1].String())) } return result, false, nil } @@ -619,7 +619,7 @@ func (s *builtinArithmeticDivideRealSig) evalReal(row chunk.Row) (float64, bool, } result := a / b if math.IsInf(result, 0) { - return 0, true, types.ErrOverflow.GenByArgs("DOUBLE", fmt.Sprintf("(%s / %s)", s.args[0].String(), s.args[1].String())) + return 0, true, types.ErrOverflow.GenWithStackByArgs("DOUBLE", fmt.Sprintf("(%s / %s)", s.args[0].String(), s.args[1].String())) } return result, false, nil } @@ -739,7 +739,7 @@ func (s *builtinArithmeticIntDivideDecimalSig) evalInt(row chunk.Row) (ret int64 err = nil } if terror.ErrorEqual(err, types.ErrOverflow) { - newErr := errTruncatedWrongValue.GenByArgs("DECIMAL", arg) + newErr := errTruncatedWrongValue.GenWithStackByArgs("DECIMAL", arg) err = sc.HandleOverflow(newErr, newErr) } if isNull || err != nil { @@ -753,10 +753,10 @@ func (s *builtinArithmeticIntDivideDecimalSig) evalInt(row chunk.Row) (ret int64 return 0, true, errors.Trace(handleDivisionByZeroError(s.ctx)) } if err == types.ErrTruncated { - err = sc.HandleTruncate(errTruncatedWrongValue.GenByArgs("DECIMAL", c)) + err = sc.HandleTruncate(errTruncatedWrongValue.GenWithStackByArgs("DECIMAL", c)) } if err == types.ErrOverflow { - newErr := errTruncatedWrongValue.GenByArgs("DECIMAL", c) + newErr := errTruncatedWrongValue.GenWithStackByArgs("DECIMAL", c) err = sc.HandleOverflow(newErr, newErr) } if err != nil { @@ -766,7 +766,7 @@ func (s *builtinArithmeticIntDivideDecimalSig) evalInt(row chunk.Row) (ret int64 ret, err = c.ToInt() // err returned by ToInt may be ErrTruncated or ErrOverflow, only handle ErrOverflow, ignore ErrTruncated. if err == types.ErrOverflow { - return 0, true, types.ErrOverflow.GenByArgs("BIGINT", fmt.Sprintf("(%s DIV %s)", s.args[0].String(), s.args[1].String())) + return 0, true, types.ErrOverflow.GenWithStackByArgs("BIGINT", fmt.Sprintf("(%s DIV %s)", s.args[0].String(), s.args[1].String())) } return ret, false, nil } diff --git a/expression/builtin_cast.go b/expression/builtin_cast.go index 79dfb430b2ca3..2021a37650552 100644 --- a/expression/builtin_cast.go +++ b/expression/builtin_cast.go @@ -26,7 +26,6 @@ import ( "strconv" "strings" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/model" "github.com/pingcap/tidb/mysql" @@ -37,6 +36,7 @@ import ( "github.com/pingcap/tidb/util/charset" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tipb/go-tipb" + "github.com/pkg/errors" ) var ( @@ -902,7 +902,7 @@ func (b *builtinCastDecimalAsIntSig) evalInt(row chunk.Row) (res int64, isNull b } if types.ErrOverflow.Equal(err) { - warnErr := types.ErrTruncatedWrongVal.GenByArgs("DECIMAL", val) + warnErr := types.ErrTruncatedWrongVal.GenWithStackByArgs("DECIMAL", val) err = b.ctx.GetSessionVars().StmtCtx.HandleOverflow(err, warnErr) } @@ -1053,7 +1053,7 @@ func (b *builtinCastStringAsIntSig) handleOverflow(origRes int64, origStr string uval := uint64(math.MaxUint64) res = int64(uval) } - warnErr := types.ErrTruncatedWrongVal.GenByArgs("INTEGER", origStr) + warnErr := types.ErrTruncatedWrongVal.GenWithStackByArgs("INTEGER", origStr) err = sc.HandleOverflow(origErr, warnErr) } return diff --git a/expression/builtin_compare.go b/expression/builtin_compare.go index cbe93f9caf320..c83f861b546b7 100644 --- a/expression/builtin_compare.go +++ b/expression/builtin_compare.go @@ -16,7 +16,6 @@ package expression import ( "math" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/parser/opcode" @@ -26,6 +25,7 @@ import ( "github.com/pingcap/tidb/types/json" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tipb/go-tipb" + "github.com/pkg/errors" ) var ( diff --git a/expression/builtin_compare_test.go b/expression/builtin_compare_test.go index bbeda8c720173..4ce6c3386e750 100644 --- a/expression/builtin_compare_test.go +++ b/expression/builtin_compare_test.go @@ -16,7 +16,6 @@ package expression import ( "time" - "github.com/juju/errors" . "github.com/pingcap/check" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/mysql" @@ -24,6 +23,7 @@ import ( "github.com/pingcap/tidb/types/json" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/testleak" + "github.com/pkg/errors" ) func (s *testEvaluatorSuite) TestCompareFunctionWithRefine(c *C) { diff --git a/expression/builtin_control.go b/expression/builtin_control.go index 8725f56b5adec..8995e97b7813a 100644 --- a/expression/builtin_control.go +++ b/expression/builtin_control.go @@ -15,7 +15,6 @@ package expression import ( "github.com/cznic/mathutil" - "github.com/juju/errors" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/types" @@ -23,6 +22,7 @@ import ( "github.com/pingcap/tidb/util/charset" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tipb/go-tipb" + "github.com/pkg/errors" ) var ( diff --git a/expression/builtin_encryption.go b/expression/builtin_encryption.go index 9983aa9f48d1d..f12bd2832abf8 100644 --- a/expression/builtin_encryption.go +++ b/expression/builtin_encryption.go @@ -26,13 +26,13 @@ import ( "hash" "io" - "github.com/juju/errors" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/auth" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/encrypt" + "github.com/pkg/errors" ) var ( @@ -217,7 +217,7 @@ type desDecryptFunctionClass struct { } func (c *desDecryptFunctionClass) getFunction(ctx sessionctx.Context, args []Expression) (builtinFunc, error) { - return nil, errFunctionNotExists.GenByArgs("FUNCTION", "DES_DECRYPT") + return nil, errFunctionNotExists.GenWithStackByArgs("FUNCTION", "DES_DECRYPT") } type desEncryptFunctionClass struct { @@ -225,7 +225,7 @@ type desEncryptFunctionClass struct { } func (c *desEncryptFunctionClass) getFunction(ctx sessionctx.Context, args []Expression) (builtinFunc, error) { - return nil, errFunctionNotExists.GenByArgs("FUNCTION", "DES_ENCRYPT") + return nil, errFunctionNotExists.GenWithStackByArgs("FUNCTION", "DES_ENCRYPT") } type encodeFunctionClass struct { @@ -276,7 +276,7 @@ type encryptFunctionClass struct { } func (c *encryptFunctionClass) getFunction(ctx sessionctx.Context, args []Expression) (builtinFunc, error) { - return nil, errFunctionNotExists.GenByArgs("FUNCTION", "ENCRYPT") + return nil, errFunctionNotExists.GenWithStackByArgs("FUNCTION", "ENCRYPT") } type oldPasswordFunctionClass struct { @@ -284,7 +284,7 @@ type oldPasswordFunctionClass struct { } func (c *oldPasswordFunctionClass) getFunction(ctx sessionctx.Context, args []Expression) (builtinFunc, error) { - return nil, errFunctionNotExists.GenByArgs("FUNCTION", "OLD_PASSWORD") + return nil, errFunctionNotExists.GenWithStackByArgs("FUNCTION", "OLD_PASSWORD") } type passwordFunctionClass struct { @@ -325,7 +325,7 @@ func (b *builtinPasswordSig) evalString(row chunk.Row) (d string, isNull bool, e // We should append a warning here because function "PASSWORD" is deprecated since MySQL 5.7.6. // See https://dev.mysql.com/doc/refman/5.7/en/encryption-functions.html#function_password - b.ctx.GetSessionVars().StmtCtx.AppendWarning(errDeprecatedSyntaxNoReplacement.GenByArgs("PASSWORD")) + b.ctx.GetSessionVars().StmtCtx.AppendWarning(errDeprecatedSyntaxNoReplacement.GenWithStackByArgs("PASSWORD")) return auth.EncodePassword(pass), false, nil } @@ -363,7 +363,7 @@ func (b *builtinRandomBytesSig) evalString(row chunk.Row) (string, bool, error) return "", true, errors.Trace(err) } if len < 1 || len > 1024 { - return "", false, types.ErrOverflow.GenByArgs("length", "random_bytes") + return "", false, types.ErrOverflow.GenWithStackByArgs("length", "random_bytes") } buf := make([]byte, len) if n, err := rand.Read(buf); err != nil { @@ -709,5 +709,5 @@ type validatePasswordStrengthFunctionClass struct { } func (c *validatePasswordStrengthFunctionClass) getFunction(ctx sessionctx.Context, args []Expression) (builtinFunc, error) { - return nil, errFunctionNotExists.GenByArgs("FUNCTION", "VALIDATE_PASSWORD_STRENGTH") + return nil, errFunctionNotExists.GenWithStackByArgs("FUNCTION", "VALIDATE_PASSWORD_STRENGTH") } diff --git a/expression/builtin_info.go b/expression/builtin_info.go index 2b173e9296ce3..7a905745fa923 100644 --- a/expression/builtin_info.go +++ b/expression/builtin_info.go @@ -18,12 +18,12 @@ package expression import ( - "github.com/juju/errors" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/printer" + "github.com/pkg/errors" ) var ( @@ -386,7 +386,7 @@ type benchmarkFunctionClass struct { } func (c *benchmarkFunctionClass) getFunction(ctx sessionctx.Context, args []Expression) (builtinFunc, error) { - return nil, errFunctionNotExists.GenByArgs("FUNCTION", "BENCHMARK") + return nil, errFunctionNotExists.GenWithStackByArgs("FUNCTION", "BENCHMARK") } type charsetFunctionClass struct { @@ -394,7 +394,7 @@ type charsetFunctionClass struct { } func (c *charsetFunctionClass) getFunction(ctx sessionctx.Context, args []Expression) (builtinFunc, error) { - return nil, errFunctionNotExists.GenByArgs("FUNCTION", "CHARSET") + return nil, errFunctionNotExists.GenWithStackByArgs("FUNCTION", "CHARSET") } type coercibilityFunctionClass struct { @@ -402,7 +402,7 @@ type coercibilityFunctionClass struct { } func (c *coercibilityFunctionClass) getFunction(ctx sessionctx.Context, args []Expression) (builtinFunc, error) { - return nil, errFunctionNotExists.GenByArgs("FUNCTION", "COERCIBILITY") + return nil, errFunctionNotExists.GenWithStackByArgs("FUNCTION", "COERCIBILITY") } type collationFunctionClass struct { @@ -410,7 +410,7 @@ type collationFunctionClass struct { } func (c *collationFunctionClass) getFunction(ctx sessionctx.Context, args []Expression) (builtinFunc, error) { - return nil, errFunctionNotExists.GenByArgs("FUNCTION", "COLLATION") + return nil, errFunctionNotExists.GenWithStackByArgs("FUNCTION", "COLLATION") } type rowCountFunctionClass struct { diff --git a/expression/builtin_json.go b/expression/builtin_json.go index 4926fe5c2e731..b99906d4581e4 100644 --- a/expression/builtin_json.go +++ b/expression/builtin_json.go @@ -14,7 +14,6 @@ package expression import ( - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/sessionctx" @@ -22,6 +21,7 @@ import ( "github.com/pingcap/tidb/types/json" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tipb/go-tipb" + "github.com/pkg/errors" ) var ( @@ -216,7 +216,7 @@ func (c *jsonSetFunctionClass) getFunction(ctx sessionctx.Context, args []Expres return nil, errors.Trace(err) } if len(args)&1 != 1 { - return nil, ErrIncorrectParameterCount.GenByArgs(c.funcName) + return nil, ErrIncorrectParameterCount.GenWithStackByArgs(c.funcName) } argTps := make([]types.EvalType, 0, len(args)) argTps = append(argTps, types.ETJson) @@ -256,7 +256,7 @@ func (c *jsonInsertFunctionClass) getFunction(ctx sessionctx.Context, args []Exp return nil, errors.Trace(err) } if len(args)&1 != 1 { - return nil, ErrIncorrectParameterCount.GenByArgs(c.funcName) + return nil, ErrIncorrectParameterCount.GenWithStackByArgs(c.funcName) } argTps := make([]types.EvalType, 0, len(args)) argTps = append(argTps, types.ETJson) @@ -296,7 +296,7 @@ func (c *jsonReplaceFunctionClass) getFunction(ctx sessionctx.Context, args []Ex return nil, errors.Trace(err) } if len(args)&1 != 1 { - return nil, ErrIncorrectParameterCount.GenByArgs(c.funcName) + return nil, ErrIncorrectParameterCount.GenWithStackByArgs(c.funcName) } argTps := make([]types.EvalType, 0, len(args)) argTps = append(argTps, types.ETJson) @@ -433,7 +433,7 @@ func (c *jsonObjectFunctionClass) getFunction(ctx sessionctx.Context, args []Exp return nil, errors.Trace(err) } if len(args)&1 != 0 { - return nil, ErrIncorrectParameterCount.GenByArgs(c.funcName) + return nil, ErrIncorrectParameterCount.GenWithStackByArgs(c.funcName) } argTps := make([]types.EvalType, 0, len(args)) for i := 0; i < len(args)-1; i += 2 { @@ -450,7 +450,7 @@ func (c *jsonObjectFunctionClass) getFunction(ctx sessionctx.Context, args []Exp func (b *builtinJSONObjectSig) evalJSON(row chunk.Row) (res json.BinaryJSON, isNull bool, err error) { if len(b.args)&1 == 1 { - err = ErrIncorrectParameterCount.GenByArgs(ast.JSONObject) + err = ErrIncorrectParameterCount.GenWithStackByArgs(ast.JSONObject) return res, true, errors.Trace(err) } jsons := make(map[string]interface{}, len(b.args)>>1) @@ -696,7 +696,7 @@ type jsonValidFunctionClass struct { } func (c *jsonValidFunctionClass) getFunction(ctx sessionctx.Context, args []Expression) (builtinFunc, error) { - return nil, errFunctionNotExists.GenByArgs("FUNCTION", "JSON_VALID") + return nil, errFunctionNotExists.GenWithStackByArgs("FUNCTION", "JSON_VALID") } type jsonArrayAppendFunctionClass struct { @@ -704,7 +704,7 @@ type jsonArrayAppendFunctionClass struct { } func (c *jsonArrayAppendFunctionClass) getFunction(ctx sessionctx.Context, args []Expression) (builtinFunc, error) { - return nil, errFunctionNotExists.GenByArgs("FUNCTION", "JSON_ARRAY_APPEND") + return nil, errFunctionNotExists.GenWithStackByArgs("FUNCTION", "JSON_ARRAY_APPEND") } type jsonArrayInsertFunctionClass struct { @@ -712,7 +712,7 @@ type jsonArrayInsertFunctionClass struct { } func (c *jsonArrayInsertFunctionClass) getFunction(ctx sessionctx.Context, args []Expression) (builtinFunc, error) { - return nil, errFunctionNotExists.GenByArgs("FUNCTION", "JSON_ARRAY_INSERT") + return nil, errFunctionNotExists.GenWithStackByArgs("FUNCTION", "JSON_ARRAY_INSERT") } type jsonMergePatchFunctionClass struct { @@ -720,7 +720,7 @@ type jsonMergePatchFunctionClass struct { } func (c *jsonMergePatchFunctionClass) getFunction(ctx sessionctx.Context, args []Expression) (builtinFunc, error) { - return nil, errFunctionNotExists.GenByArgs("FUNCTION", "JSON_MERGE_PATCH") + return nil, errFunctionNotExists.GenWithStackByArgs("FUNCTION", "JSON_MERGE_PATCH") } type jsonMergePreserveFunctionClass struct { @@ -728,7 +728,7 @@ type jsonMergePreserveFunctionClass struct { } func (c *jsonMergePreserveFunctionClass) getFunction(ctx sessionctx.Context, args []Expression) (builtinFunc, error) { - return nil, errFunctionNotExists.GenByArgs("FUNCTION", "JSON_MERGE_PRESERVE") + return nil, errFunctionNotExists.GenWithStackByArgs("FUNCTION", "JSON_MERGE_PRESERVE") } type jsonPrettyFunctionClass struct { @@ -736,7 +736,7 @@ type jsonPrettyFunctionClass struct { } func (c *jsonPrettyFunctionClass) getFunction(ctx sessionctx.Context, args []Expression) (builtinFunc, error) { - return nil, errFunctionNotExists.GenByArgs("FUNCTION", "JSON_PRETTY") + return nil, errFunctionNotExists.GenWithStackByArgs("FUNCTION", "JSON_PRETTY") } type jsonQuoteFunctionClass struct { @@ -744,7 +744,7 @@ type jsonQuoteFunctionClass struct { } func (c *jsonQuoteFunctionClass) getFunction(ctx sessionctx.Context, args []Expression) (builtinFunc, error) { - return nil, errFunctionNotExists.GenByArgs("FUNCTION", "JSON_QUOTE") + return nil, errFunctionNotExists.GenWithStackByArgs("FUNCTION", "JSON_QUOTE") } type jsonSearchFunctionClass struct { @@ -752,7 +752,7 @@ type jsonSearchFunctionClass struct { } func (c *jsonSearchFunctionClass) getFunction(ctx sessionctx.Context, args []Expression) (builtinFunc, error) { - return nil, errFunctionNotExists.GenByArgs("FUNCTION", "JSON_SEARCH") + return nil, errFunctionNotExists.GenWithStackByArgs("FUNCTION", "JSON_SEARCH") } type jsonStorageSizeFunctionClass struct { @@ -760,7 +760,7 @@ type jsonStorageSizeFunctionClass struct { } func (c *jsonStorageSizeFunctionClass) getFunction(ctx sessionctx.Context, args []Expression) (builtinFunc, error) { - return nil, errFunctionNotExists.GenByArgs("FUNCTION", "JSON_STORAGE_SIZE") + return nil, errFunctionNotExists.GenWithStackByArgs("FUNCTION", "JSON_STORAGE_SIZE") } type jsonDepthFunctionClass struct { @@ -768,7 +768,7 @@ type jsonDepthFunctionClass struct { } func (c *jsonDepthFunctionClass) getFunction(ctx sessionctx.Context, args []Expression) (builtinFunc, error) { - return nil, errFunctionNotExists.GenByArgs("FUNCTION", "JSON_DEPTH") + return nil, errFunctionNotExists.GenWithStackByArgs("FUNCTION", "JSON_DEPTH") } type jsonKeysFunctionClass struct { @@ -776,7 +776,7 @@ type jsonKeysFunctionClass struct { } func (c *jsonKeysFunctionClass) getFunction(ctx sessionctx.Context, args []Expression) (builtinFunc, error) { - return nil, errFunctionNotExists.GenByArgs("FUNCTION", "JSON_KEYS") + return nil, errFunctionNotExists.GenWithStackByArgs("FUNCTION", "JSON_KEYS") } type jsonLengthFunctionClass struct { @@ -784,5 +784,5 @@ type jsonLengthFunctionClass struct { } func (c *jsonLengthFunctionClass) getFunction(ctx sessionctx.Context, args []Expression) (builtinFunc, error) { - return nil, errFunctionNotExists.GenByArgs("FUNCTION", "JSON_LENGTH") + return nil, errFunctionNotExists.GenWithStackByArgs("FUNCTION", "JSON_LENGTH") } diff --git a/expression/builtin_like.go b/expression/builtin_like.go index a9a961755a3b9..43312813cae94 100644 --- a/expression/builtin_like.go +++ b/expression/builtin_like.go @@ -16,12 +16,12 @@ package expression import ( "regexp" - "github.com/juju/errors" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/stringutil" "github.com/pingcap/tipb/go-tipb" + "github.com/pkg/errors" ) var ( @@ -128,7 +128,7 @@ func (b *builtinRegexpBinarySig) evalInt(row chunk.Row) (int64, bool, error) { // TODO: We don't need to compile pattern if it has been compiled or it is static. re, err := regexp.Compile(pat) if err != nil { - return 0, true, ErrRegexp.GenByArgs(err.Error()) + return 0, true, ErrRegexp.GenWithStackByArgs(err.Error()) } return boolToInt64(re.MatchString(expr)), false, nil } @@ -159,7 +159,7 @@ func (b *builtinRegexpSig) evalInt(row chunk.Row) (int64, bool, error) { // TODO: We don't need to compile pattern if it has been compiled or it is static. re, err := regexp.Compile("(?i)" + pat) if err != nil { - return 0, true, ErrRegexp.GenByArgs(err.Error()) + return 0, true, ErrRegexp.GenWithStackByArgs(err.Error()) } return boolToInt64(re.MatchString(expr)), false, nil } diff --git a/expression/builtin_math.go b/expression/builtin_math.go index cf0320f3e4fc7..07d5648fab575 100644 --- a/expression/builtin_math.go +++ b/expression/builtin_math.go @@ -27,12 +27,12 @@ import ( "time" "github.com/cznic/mathutil" - "github.com/juju/errors" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tipb/go-tipb" + "github.com/pkg/errors" ) var ( @@ -199,7 +199,7 @@ func (b *builtinAbsIntSig) evalInt(row chunk.Row) (int64, bool, error) { return val, false, nil } if val == math.MinInt64 { - return 0, false, types.ErrOverflow.GenByArgs("BIGINT", fmt.Sprintf("abs(%d)", val)) + return 0, false, types.ErrOverflow.GenWithStackByArgs("BIGINT", fmt.Sprintf("abs(%d)", val)) } return -val, false, nil } @@ -1057,7 +1057,7 @@ func (b *builtinPowSig) evalReal(row chunk.Row) (float64, bool, error) { } power := math.Pow(x, y) if math.IsInf(power, -1) || math.IsInf(power, 1) || math.IsNaN(power) { - return 0, false, types.ErrOverflow.GenByArgs("DOUBLE", fmt.Sprintf("pow(%s, %s)", strconv.FormatFloat(x, 'f', -1, 64), strconv.FormatFloat(y, 'f', -1, 64))) + return 0, false, types.ErrOverflow.GenWithStackByArgs("DOUBLE", fmt.Sprintf("pow(%s, %s)", strconv.FormatFloat(x, 'f', -1, 64), strconv.FormatFloat(y, 'f', -1, 64))) } return power, false, nil } @@ -1140,7 +1140,7 @@ func (b *builtinConvSig) evalString(row chunk.Row) (res string, isNull bool, err val, err := strconv.ParseUint(n, int(fromBase), 64) if err != nil { - return res, false, types.ErrOverflow.GenByArgs("BIGINT UNSINGED", n) + return res, false, types.ErrOverflow.GenWithStackByArgs("BIGINT UNSINGED", n) } if signed { if negative && val > -math.MinInt64 { @@ -1504,7 +1504,7 @@ func (b *builtinCotSig) evalReal(row chunk.Row) (float64, bool, error) { return cot, false, nil } } - return 0, false, types.ErrOverflow.GenByArgs("DOUBLE", fmt.Sprintf("cot(%s)", strconv.FormatFloat(val, 'f', -1, 64))) + return 0, false, types.ErrOverflow.GenWithStackByArgs("DOUBLE", fmt.Sprintf("cot(%s)", strconv.FormatFloat(val, 'f', -1, 64))) } type degreesFunctionClass struct { @@ -1574,7 +1574,7 @@ func (b *builtinExpSig) evalReal(row chunk.Row) (float64, bool, error) { exp := math.Exp(val) if math.IsInf(exp, 0) || math.IsNaN(exp) { s := fmt.Sprintf("exp(%s)", strconv.FormatFloat(val, 'f', -1, 64)) - return 0, false, types.ErrOverflow.GenByArgs("DOUBLE", s) + return 0, false, types.ErrOverflow.GenWithStackByArgs("DOUBLE", s) } return exp, false, nil } diff --git a/expression/builtin_miscellaneous.go b/expression/builtin_miscellaneous.go index 429ddf60da687..b249551247340 100644 --- a/expression/builtin_miscellaneous.go +++ b/expression/builtin_miscellaneous.go @@ -21,13 +21,13 @@ import ( "strings" "time" - "github.com/juju/errors" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/types/json" "github.com/pingcap/tidb/util/charset" "github.com/pingcap/tidb/util/chunk" + "github.com/pkg/errors" "github.com/twinj/uuid" ) @@ -110,20 +110,20 @@ func (b *builtinSleepSig) evalInt(row chunk.Row) (int64, bool, error) { sessVars := b.ctx.GetSessionVars() if isNull { if sessVars.StrictSQLMode { - return 0, true, errIncorrectArgs.GenByArgs("sleep") + return 0, true, errIncorrectArgs.GenWithStackByArgs("sleep") } return 0, true, nil } // processing argument is negative if val < 0 { if sessVars.StrictSQLMode { - return 0, false, errIncorrectArgs.GenByArgs("sleep") + return 0, false, errIncorrectArgs.GenWithStackByArgs("sleep") } return 0, false, nil } if val > math.MaxFloat64/float64(time.Second.Nanoseconds()) { - return 0, false, errIncorrectArgs.GenByArgs("sleep") + return 0, false, errIncorrectArgs.GenWithStackByArgs("sleep") } dur := time.Duration(val * float64(time.Second.Nanoseconds())) select { @@ -352,7 +352,7 @@ type defaultFunctionClass struct { } func (c *defaultFunctionClass) getFunction(ctx sessionctx.Context, args []Expression) (builtinFunc, error) { - return nil, errFunctionNotExists.GenByArgs("FUNCTION", "DEFAULT") + return nil, errFunctionNotExists.GenWithStackByArgs("FUNCTION", "DEFAULT") } type inetAtonFunctionClass struct { @@ -594,7 +594,7 @@ type isFreeLockFunctionClass struct { } func (c *isFreeLockFunctionClass) getFunction(ctx sessionctx.Context, args []Expression) (builtinFunc, error) { - return nil, errFunctionNotExists.GenByArgs("FUNCTION", "IS_FREE_LOCK") + return nil, errFunctionNotExists.GenWithStackByArgs("FUNCTION", "IS_FREE_LOCK") } type isIPv4FunctionClass struct { @@ -794,7 +794,7 @@ type isUsedLockFunctionClass struct { } func (c *isUsedLockFunctionClass) getFunction(ctx sessionctx.Context, args []Expression) (builtinFunc, error) { - return nil, errFunctionNotExists.GenByArgs("FUNCTION", "IS_USED_LOCK") + return nil, errFunctionNotExists.GenWithStackByArgs("FUNCTION", "IS_USED_LOCK") } type masterPosWaitFunctionClass struct { @@ -802,7 +802,7 @@ type masterPosWaitFunctionClass struct { } func (c *masterPosWaitFunctionClass) getFunction(ctx sessionctx.Context, args []Expression) (builtinFunc, error) { - return nil, errFunctionNotExists.GenByArgs("FUNCTION", "MASTER_POS_WAIT") + return nil, errFunctionNotExists.GenWithStackByArgs("FUNCTION", "MASTER_POS_WAIT") } type nameConstFunctionClass struct { @@ -810,7 +810,7 @@ type nameConstFunctionClass struct { } func (c *nameConstFunctionClass) getFunction(ctx sessionctx.Context, args []Expression) (builtinFunc, error) { - return nil, errFunctionNotExists.GenByArgs("FUNCTION", "NAME_CONST") + return nil, errFunctionNotExists.GenWithStackByArgs("FUNCTION", "NAME_CONST") } type releaseAllLocksFunctionClass struct { @@ -818,7 +818,7 @@ type releaseAllLocksFunctionClass struct { } func (c *releaseAllLocksFunctionClass) getFunction(ctx sessionctx.Context, args []Expression) (builtinFunc, error) { - return nil, errFunctionNotExists.GenByArgs("FUNCTION", "RELEASE_ALL_LOCKS") + return nil, errFunctionNotExists.GenWithStackByArgs("FUNCTION", "RELEASE_ALL_LOCKS") } type uuidFunctionClass struct { @@ -856,5 +856,5 @@ type uuidShortFunctionClass struct { } func (c *uuidShortFunctionClass) getFunction(ctx sessionctx.Context, args []Expression) (builtinFunc, error) { - return nil, errFunctionNotExists.GenByArgs("FUNCTION", "UUID_SHORT") + return nil, errFunctionNotExists.GenWithStackByArgs("FUNCTION", "UUID_SHORT") } diff --git a/expression/builtin_op.go b/expression/builtin_op.go index 342b12323740a..1c4109da9c1b1 100644 --- a/expression/builtin_op.go +++ b/expression/builtin_op.go @@ -17,13 +17,13 @@ import ( "fmt" "math" - "github.com/juju/errors" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/parser/opcode" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tipb/go-tipb" + "github.com/pkg/errors" ) var ( @@ -727,12 +727,12 @@ func (b *builtinUnaryMinusIntSig) evalInt(row chunk.Row) (res int64, isNull bool if mysql.HasUnsignedFlag(b.args[0].GetType().Flag) { uval := uint64(val) if uval > uint64(-math.MinInt64) { - return 0, false, types.ErrOverflow.GenByArgs("BIGINT", fmt.Sprintf("-%v", uval)) + return 0, false, types.ErrOverflow.GenWithStackByArgs("BIGINT", fmt.Sprintf("-%v", uval)) } else if uval == uint64(-math.MinInt64) { return math.MinInt64, false, nil } } else if val == math.MinInt64 { - return 0, false, types.ErrOverflow.GenByArgs("BIGINT", fmt.Sprintf("-%v", val)) + return 0, false, types.ErrOverflow.GenWithStackByArgs("BIGINT", fmt.Sprintf("-%v", val)) } return -val, false, nil } diff --git a/expression/builtin_op_test.go b/expression/builtin_op_test.go index 3099596a7feec..5e726be8745c7 100644 --- a/expression/builtin_op_test.go +++ b/expression/builtin_op_test.go @@ -16,13 +16,13 @@ package expression import ( "math" - "github.com/juju/errors" . "github.com/pingcap/check" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/testleak" "github.com/pingcap/tidb/util/testutil" + "github.com/pkg/errors" ) func (s *testEvaluatorSuite) TestUnary(c *C) { diff --git a/expression/builtin_other.go b/expression/builtin_other.go index 964f9ae82a11f..e7224f4031bd0 100644 --- a/expression/builtin_other.go +++ b/expression/builtin_other.go @@ -16,13 +16,13 @@ package expression import ( "strings" - "github.com/juju/errors" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/types/json" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tipb/go-tipb" + "github.com/pkg/errors" ) var ( diff --git a/expression/builtin_string.go b/expression/builtin_string.go index b2c28dee5a772..f20c7fe27a377 100644 --- a/expression/builtin_string.go +++ b/expression/builtin_string.go @@ -27,7 +27,6 @@ import ( "strings" "unicode/utf8" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/sessionctx" @@ -36,6 +35,7 @@ import ( "github.com/pingcap/tidb/util/charset" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/hack" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/text/transform" ) @@ -597,7 +597,7 @@ func (b *builtinRepeatSig) evalString(row chunk.Row) (d string, isNull bool, err } if uint64(byteLength)*uint64(num) > b.maxAllowedPacket { - b.ctx.GetSessionVars().StmtCtx.AppendWarning(errWarnAllowedPacketOverflowed.GenByArgs("repeat", b.maxAllowedPacket)) + b.ctx.GetSessionVars().StmtCtx.AppendWarning(errWarnAllowedPacketOverflowed.GenWithStackByArgs("repeat", b.maxAllowedPacket)) return "", true, nil } @@ -756,7 +756,7 @@ func (b *builtinSpaceSig) evalString(row chunk.Row) (d string, isNull bool, err x = 0 } if uint64(x) > b.maxAllowedPacket { - b.ctx.GetSessionVars().StmtCtx.AppendWarning(errWarnAllowedPacketOverflowed.GenByArgs("space", b.maxAllowedPacket)) + b.ctx.GetSessionVars().StmtCtx.AppendWarning(errWarnAllowedPacketOverflowed.GenWithStackByArgs("space", b.maxAllowedPacket)) return d, true, nil } if x > mysql.MaxBlobWidth { @@ -955,7 +955,7 @@ func (b *builtinConvertSig) evalString(row chunk.Row) (string, bool, error) { encoding, _ := charset.Lookup(charsetName) if encoding == nil { - return "", true, errUnknownCharacterSet.GenByArgs(charsetName) + return "", true, errUnknownCharacterSet.GenWithStackByArgs(charsetName) } target, _, err := transform.String(encoding.NewDecoder(), expr) @@ -1833,7 +1833,7 @@ func (b *builtinLpadBinarySig) evalString(row chunk.Row) (string, bool, error) { targetLength := int(length) if uint64(targetLength) > b.maxAllowedPacket { - b.ctx.GetSessionVars().StmtCtx.AppendWarning(errWarnAllowedPacketOverflowed.GenByArgs("lpad", b.maxAllowedPacket)) + b.ctx.GetSessionVars().StmtCtx.AppendWarning(errWarnAllowedPacketOverflowed.GenWithStackByArgs("lpad", b.maxAllowedPacket)) return "", true, nil } @@ -1882,7 +1882,7 @@ func (b *builtinLpadSig) evalString(row chunk.Row) (string, bool, error) { targetLength := int(length) if uint64(targetLength)*uint64(mysql.MaxBytesOfCharacter) > b.maxAllowedPacket { - b.ctx.GetSessionVars().StmtCtx.AppendWarning(errWarnAllowedPacketOverflowed.GenByArgs("lpad", b.maxAllowedPacket)) + b.ctx.GetSessionVars().StmtCtx.AppendWarning(errWarnAllowedPacketOverflowed.GenWithStackByArgs("lpad", b.maxAllowedPacket)) return "", true, nil } @@ -1960,7 +1960,7 @@ func (b *builtinRpadBinarySig) evalString(row chunk.Row) (string, bool, error) { } targetLength := int(length) if uint64(targetLength) > b.maxAllowedPacket { - b.ctx.GetSessionVars().StmtCtx.AppendWarning(errWarnAllowedPacketOverflowed.GenByArgs("rpad", b.maxAllowedPacket)) + b.ctx.GetSessionVars().StmtCtx.AppendWarning(errWarnAllowedPacketOverflowed.GenWithStackByArgs("rpad", b.maxAllowedPacket)) return "", true, nil } @@ -2009,7 +2009,7 @@ func (b *builtinRpadSig) evalString(row chunk.Row) (string, bool, error) { targetLength := int(length) if uint64(targetLength)*uint64(mysql.MaxBytesOfCharacter) > b.maxAllowedPacket { - b.ctx.GetSessionVars().StmtCtx.AppendWarning(errWarnAllowedPacketOverflowed.GenByArgs("rpad", b.maxAllowedPacket)) + b.ctx.GetSessionVars().StmtCtx.AppendWarning(errWarnAllowedPacketOverflowed.GenWithStackByArgs("rpad", b.maxAllowedPacket)) return "", true, nil } @@ -3045,7 +3045,7 @@ func (b *builtinFromBase64Sig) evalString(row chunk.Row) (string, bool, error) { return "", true, nil } if needDecodeLen > int(b.maxAllowedPacket) { - b.ctx.GetSessionVars().StmtCtx.AppendWarning(errWarnAllowedPacketOverflowed.GenByArgs("from_base64", b.maxAllowedPacket)) + b.ctx.GetSessionVars().StmtCtx.AppendWarning(errWarnAllowedPacketOverflowed.GenWithStackByArgs("from_base64", b.maxAllowedPacket)) return "", true, nil } @@ -3127,7 +3127,7 @@ func (b *builtinToBase64Sig) evalString(row chunk.Row) (d string, isNull bool, e return "", true, nil } if needEncodeLen > int(b.maxAllowedPacket) { - b.ctx.GetSessionVars().StmtCtx.AppendWarning(errWarnAllowedPacketOverflowed.GenByArgs("to_base64", b.maxAllowedPacket)) + b.ctx.GetSessionVars().StmtCtx.AppendWarning(errWarnAllowedPacketOverflowed.GenWithStackByArgs("to_base64", b.maxAllowedPacket)) return "", true, nil } if b.tp.Flen == -1 || b.tp.Flen > mysql.MaxBlobWidth { @@ -3229,7 +3229,7 @@ func (b *builtinInsertBinarySig) evalString(row chunk.Row) (string, bool, error) } if uint64(strLength-length+int64(len(newstr))) > b.maxAllowedPacket { - b.ctx.GetSessionVars().StmtCtx.AppendWarning(errWarnAllowedPacketOverflowed.GenByArgs("insert", b.maxAllowedPacket)) + b.ctx.GetSessionVars().StmtCtx.AppendWarning(errWarnAllowedPacketOverflowed.GenWithStackByArgs("insert", b.maxAllowedPacket)) return "", true, nil } @@ -3283,7 +3283,7 @@ func (b *builtinInsertSig) evalString(row chunk.Row) (string, bool, error) { strHead := string(runes[0 : pos-1]) strTail := string(runes[pos+length-1:]) if uint64(len(strHead)+len(newstr)+len(strTail)) > b.maxAllowedPacket { - b.ctx.GetSessionVars().StmtCtx.AppendWarning(errWarnAllowedPacketOverflowed.GenByArgs("insert", b.maxAllowedPacket)) + b.ctx.GetSessionVars().StmtCtx.AppendWarning(errWarnAllowedPacketOverflowed.GenWithStackByArgs("insert", b.maxAllowedPacket)) return "", true, nil } return strHead + newstr + strTail, false, nil @@ -3370,5 +3370,5 @@ type loadFileFunctionClass struct { } func (c *loadFileFunctionClass) getFunction(ctx sessionctx.Context, args []Expression) (builtinFunc, error) { - return nil, errFunctionNotExists.GenByArgs("FUNCTION", "load_file") + return nil, errFunctionNotExists.GenWithStackByArgs("FUNCTION", "load_file") } diff --git a/expression/builtin_string_test.go b/expression/builtin_string_test.go index dbadbca0ef833..c90068ae365fe 100644 --- a/expression/builtin_string_test.go +++ b/expression/builtin_string_test.go @@ -19,7 +19,6 @@ import ( "strings" "time" - "github.com/juju/errors" . "github.com/pingcap/check" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/mysql" @@ -31,6 +30,7 @@ import ( "github.com/pingcap/tidb/util/mock" "github.com/pingcap/tidb/util/testleak" "github.com/pingcap/tidb/util/testutil" + "github.com/pkg/errors" ) func (s *testEvaluatorSuite) TestLength(c *C) { diff --git a/expression/builtin_test.go b/expression/builtin_test.go index 6a325f7f43f29..b12f49ada982a 100644 --- a/expression/builtin_test.go +++ b/expression/builtin_test.go @@ -16,7 +16,6 @@ package expression import ( "reflect" - "github.com/juju/errors" . "github.com/pingcap/check" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/model" @@ -26,6 +25,7 @@ import ( "github.com/pingcap/tidb/util/charset" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/testleak" + "github.com/pkg/errors" ) func evalBuiltinFunc(f builtinFunc, row chunk.Row) (d types.Datum, err error) { @@ -139,7 +139,7 @@ func (s *testEvaluatorSuite) TestLock(c *C) { func newFunctionForTest(ctx sessionctx.Context, funcName string, args ...Expression) (Expression, error) { fc, ok := funcs[funcName] if !ok { - return nil, errFunctionNotExists.GenByArgs("FUNCTION", funcName) + return nil, errFunctionNotExists.GenWithStackByArgs("FUNCTION", funcName) } funcArgs := make([]Expression, len(args)) copy(funcArgs, args) diff --git a/expression/builtin_time.go b/expression/builtin_time.go index cdd6f54a2326e..c69b88d03672e 100644 --- a/expression/builtin_time.go +++ b/expression/builtin_time.go @@ -26,7 +26,6 @@ import ( "time" "github.com/cznic/mathutil" - "github.com/juju/errors" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/sessionctx/stmtctx" @@ -34,6 +33,7 @@ import ( "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tipb/go-tipb" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" ) @@ -273,7 +273,7 @@ func (b *builtinDateSig) evalTime(row chunk.Row) (types.Time, bool, error) { } if expr.IsZero() { - return types.Time{}, true, errors.Trace(handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenByArgs(expr.String()))) + return types.Time{}, true, errors.Trace(handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(expr.String()))) } expr.Time = types.FromDate(expr.Time.Year(), expr.Time.Month(), expr.Time.Day(), 0, 0, 0, 0) @@ -299,7 +299,7 @@ func (c *dateLiteralFunctionClass) getFunction(ctx sessionctx.Context, args []Ex } str := dt.GetString() if !datePattern.MatchString(str) { - return nil, types.ErrIncorrectDatetimeValue.GenByArgs(str) + return nil, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(str) } tm, err := types.ParseDate(ctx.GetSessionVars().StmtCtx, str) if err != nil { @@ -327,10 +327,10 @@ func (b *builtinDateLiteralSig) Clone() builtinFunc { func (b *builtinDateLiteralSig) evalTime(row chunk.Row) (types.Time, bool, error) { mode := b.ctx.GetSessionVars().SQLMode if mode.HasNoZeroDateMode() && b.literal.IsZero() { - return b.literal, true, types.ErrIncorrectDatetimeValue.GenByArgs(b.literal.String()) + return b.literal, true, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(b.literal.String()) } if mode.HasNoZeroInDateMode() && (b.literal.InvalidZero() && !b.literal.IsZero()) { - return b.literal, true, types.ErrIncorrectDatetimeValue.GenByArgs(b.literal.String()) + return b.literal, true, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(b.literal.String()) } return b.literal, false, nil } @@ -371,10 +371,10 @@ func (b *builtinDateDiffSig) evalInt(row chunk.Row) (int64, bool, error) { } if invalidLHS, invalidRHS := lhs.InvalidZero(), rhs.InvalidZero(); invalidLHS || invalidRHS { if invalidLHS { - err = handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenByArgs(lhs.String())) + err = handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(lhs.String())) } if invalidRHS { - err = handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenByArgs(rhs.String())) + err = handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(rhs.String())) } return 0, true, errors.Trace(err) } @@ -773,7 +773,7 @@ func (b *builtinDateFormatSig) evalString(row chunk.Row) (string, bool, error) { return "", isNull, errors.Trace(handleInvalidTimeError(b.ctx, err)) } if t.InvalidZero() { - return "", true, errors.Trace(handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenByArgs(t.String()))) + return "", true, errors.Trace(handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(t.String()))) } formatMask, isNull, err := b.args[1].EvalString(b.ctx, row) if isNull || err != nil { @@ -994,7 +994,7 @@ func (b *builtinMonthSig) evalInt(row chunk.Row) (int64, bool, error) { if date.IsZero() { if b.ctx.GetSessionVars().SQLMode.HasNoZeroDateMode() { - return 0, true, errors.Trace(handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenByArgs(date.String()))) + return 0, true, errors.Trace(handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(date.String()))) } return 0, false, nil } @@ -1034,7 +1034,7 @@ func (b *builtinMonthNameSig) evalString(row chunk.Row) (string, bool, error) { } mon := arg.Time.Month() if (arg.IsZero() && b.ctx.GetSessionVars().SQLMode.HasNoZeroDateMode()) || mon < 0 || mon > len(types.MonthNames) { - return "", true, errors.Trace(handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenByArgs(arg.String()))) + return "", true, errors.Trace(handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(arg.String()))) } else if mon == 0 || arg.IsZero() { return "", true, nil } @@ -1073,7 +1073,7 @@ func (b *builtinDayNameSig) evalString(row chunk.Row) (string, bool, error) { return "", isNull, errors.Trace(err) } if arg.InvalidZero() { - return "", true, errors.Trace(handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenByArgs(arg.String()))) + return "", true, errors.Trace(handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(arg.String()))) } // Monday is 0, ... Sunday = 6 in MySQL // but in go, Sunday is 0, ... Saturday is 6 @@ -1115,7 +1115,7 @@ func (b *builtinDayOfMonthSig) evalInt(row chunk.Row) (int64, bool, error) { } if arg.IsZero() { if b.ctx.GetSessionVars().SQLMode.HasNoZeroDateMode() { - return 0, true, errors.Trace(handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenByArgs(arg.String()))) + return 0, true, errors.Trace(handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(arg.String()))) } return 0, false, nil } @@ -1154,7 +1154,7 @@ func (b *builtinDayOfWeekSig) evalInt(row chunk.Row) (int64, bool, error) { return 0, true, errors.Trace(handleInvalidTimeError(b.ctx, err)) } if arg.InvalidZero() { - return 0, true, errors.Trace(handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenByArgs(arg.String()))) + return 0, true, errors.Trace(handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(arg.String()))) } // 1 is Sunday, 2 is Monday, .... 7 is Saturday return int64(arg.Time.Weekday() + 1), false, nil @@ -1192,7 +1192,7 @@ func (b *builtinDayOfYearSig) evalInt(row chunk.Row) (int64, bool, error) { return 0, isNull, errors.Trace(handleInvalidTimeError(b.ctx, err)) } if arg.InvalidZero() { - return 0, true, errors.Trace(handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenByArgs(arg.String()))) + return 0, true, errors.Trace(handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(arg.String()))) } return int64(arg.Time.YearDay()), false, nil @@ -1245,7 +1245,7 @@ func (b *builtinWeekWithModeSig) evalInt(row chunk.Row) (int64, bool, error) { } if date.IsZero() { - return 0, true, errors.Trace(handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenByArgs(date.String()))) + return 0, true, errors.Trace(handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(date.String()))) } mode, isNull, err := b.args[1].EvalInt(b.ctx, row) @@ -1277,7 +1277,7 @@ func (b *builtinWeekWithoutModeSig) evalInt(row chunk.Row) (int64, bool, error) } if date.IsZero() { - return 0, true, errors.Trace(handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenByArgs(date.String()))) + return 0, true, errors.Trace(handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(date.String()))) } week := date.Time.Week(0) @@ -1318,7 +1318,7 @@ func (b *builtinWeekDaySig) evalInt(row chunk.Row) (int64, bool, error) { } if date.IsZero() { - return 0, true, errors.Trace(handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenByArgs(date.String()))) + return 0, true, errors.Trace(handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(date.String()))) } return int64(date.Time.Weekday()+6) % 7, false, nil @@ -1358,7 +1358,7 @@ func (b *builtinWeekOfYearSig) evalInt(row chunk.Row) (int64, bool, error) { } if date.IsZero() { - return 0, true, errors.Trace(handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenByArgs(date.String()))) + return 0, true, errors.Trace(handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(date.String()))) } week := date.Time.Week(3) @@ -1400,7 +1400,7 @@ func (b *builtinYearSig) evalInt(row chunk.Row) (int64, bool, error) { if date.IsZero() { if b.ctx.GetSessionVars().SQLMode.HasNoZeroDateMode() { - return 0, true, errors.Trace(handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenByArgs(date.String()))) + return 0, true, errors.Trace(handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(date.String()))) } return 0, false, nil } @@ -1451,7 +1451,7 @@ func (b *builtinYearWeekWithModeSig) evalInt(row chunk.Row) (int64, bool, error) return 0, isNull, errors.Trace(handleInvalidTimeError(b.ctx, err)) } if date.IsZero() { - return 0, true, errors.Trace(handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenByArgs(date.String()))) + return 0, true, errors.Trace(handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(date.String()))) } mode, isNull, err := b.args[1].EvalInt(b.ctx, row) @@ -1489,7 +1489,7 @@ func (b *builtinYearWeekWithoutModeSig) evalInt(row chunk.Row) (int64, bool, err } if date.InvalidZero() { - return 0, true, errors.Trace(handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenByArgs(date.String()))) + return 0, true, errors.Trace(handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(date.String()))) } year, week := date.Time.YearWeek(0) @@ -1798,7 +1798,7 @@ func (b *builtinStrToDateDateSig) evalTime(row chunk.Row) (types.Time, bool, err sc := b.ctx.GetSessionVars().StmtCtx succ := t.StrToDate(sc, date, format) if !succ { - return types.Time{}, true, handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenByArgs(t.String())) + return types.Time{}, true, handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(t.String())) } t.Type, t.Fsp = mysql.TypeDate, types.MinFsp return t, false, nil @@ -1827,7 +1827,7 @@ func (b *builtinStrToDateDatetimeSig) evalTime(row chunk.Row) (types.Time, bool, sc := b.ctx.GetSessionVars().StmtCtx succ := t.StrToDate(sc, date, format) if !succ { - return types.Time{}, true, handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenByArgs(t.String())) + return types.Time{}, true, handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(t.String())) } t.Type, t.Fsp = mysql.TypeDatetime, b.tp.Decimal return t, false, nil @@ -1858,7 +1858,7 @@ func (b *builtinStrToDateDurationSig) evalDuration(row chunk.Row) (types.Duratio sc := b.ctx.GetSessionVars().StmtCtx succ := t.StrToDate(sc, date, format) if !succ { - return types.Duration{}, true, handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenByArgs(t.String())) + return types.Duration{}, true, handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(t.String())) } t.Fsp = b.tp.Decimal dur, err := t.ConvertToDuration() @@ -2124,7 +2124,7 @@ func (c *timeLiteralFunctionClass) getFunction(ctx sessionctx.Context, args []Ex } str := dt.GetString() if !isDuration(str) { - return nil, types.ErrIncorrectDatetimeValue.GenByArgs(str) + return nil, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(str) } duration, err := types.ParseDuration(str, types.GetFsp(str)) if err != nil { @@ -3283,10 +3283,10 @@ func (b *builtinTimestampDiffSig) evalInt(row chunk.Row) (int64, bool, error) { } if invalidLHS, invalidRHS := lhs.InvalidZero(), rhs.InvalidZero(); invalidLHS || invalidRHS { if invalidLHS { - err = handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenByArgs(lhs.String())) + err = handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(lhs.String())) } if invalidRHS { - err = handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenByArgs(rhs.String())) + err = handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(rhs.String())) } return 0, true, errors.Trace(err) } @@ -3415,7 +3415,7 @@ func (b *builtinUnixTimestampIntSig) Clone() builtinFunc { // See https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_unix-timestamp func (b *builtinUnixTimestampIntSig) evalInt(row chunk.Row) (int64, bool, error) { val, isNull, err := b.args[0].EvalTime(b.ctx, row) - if err != nil && terror.ErrorEqual(types.ErrInvalidTimeFormat.GenByArgs(val), err) { + if err != nil && terror.ErrorEqual(types.ErrInvalidTimeFormat.GenWithStackByArgs(val), err) { // Return 0 for invalid date time. return 0, false, nil } @@ -3615,7 +3615,7 @@ func (c *timestampLiteralFunctionClass) getFunction(ctx sessionctx.Context, args return nil, errors.Trace(err) } if !timestampPattern.MatchString(str) { - return nil, types.ErrIncorrectDatetimeValue.GenByArgs(str) + return nil, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(str) } tm, err := types.ParseTime(ctx.GetSessionVars().StmtCtx, str, mysql.TypeTimestamp, types.GetFsp(str)) if err != nil { @@ -4315,7 +4315,7 @@ func (b *builtinMakeDateSig) evalTime(row chunk.Row) (d types.Time, isNull bool, } retTimestamp := types.TimestampDiff("DAY", types.ZeroDate, startTime) if retTimestamp == 0 { - return d, true, errors.Trace(handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenByArgs(startTime.String()))) + return d, true, errors.Trace(handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(startTime.String()))) } ret := types.TimeFromDays(retTimestamp + dayOfYear - 1) if ret.IsZero() || ret.Time.Year() > 9999 { @@ -4566,7 +4566,7 @@ func (b *builtinQuarterSig) evalInt(row chunk.Row) (int64, bool, error) { } if date.IsZero() { - return 0, true, errors.Trace(handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenByArgs(date.String()))) + return 0, true, errors.Trace(handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(date.String()))) } return int64((date.Time.Month() + 2) / 3), false, nil @@ -5187,7 +5187,7 @@ func (b *builtinTimestampAddSig) evalString(row chunk.Row) (string, bool, error) case "YEAR": tb = tm1.AddDate(int(v), 0, 0) default: - return "", true, errors.Trace(types.ErrInvalidTimeFormat.GenByArgs(unit)) + return "", true, errors.Trace(types.ErrInvalidTimeFormat.GenWithStackByArgs(unit)) } r := types.Time{Time: types.FromGoTime(tb), Type: mysql.TypeDatetime, Fsp: fsp} if err = r.Check(b.ctx.GetSessionVars().StmtCtx); err != nil { @@ -5229,7 +5229,7 @@ func (b *builtinToDaysSig) evalInt(row chunk.Row) (int64, bool, error) { } ret := types.TimestampDiff("DAY", types.ZeroDate, arg) if ret == 0 { - return 0, true, errors.Trace(handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenByArgs(arg.String()))) + return 0, true, errors.Trace(handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(arg.String()))) } return ret, false, nil } @@ -5266,7 +5266,7 @@ func (b *builtinToSecondsSig) evalInt(row chunk.Row) (int64, bool, error) { } ret := types.TimestampDiff("SECOND", types.ZeroDate, arg) if ret == 0 { - return 0, true, errors.Trace(handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenByArgs(arg.String()))) + return 0, true, errors.Trace(handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(arg.String()))) } return ret, false, nil } @@ -5396,7 +5396,7 @@ func (b *builtinLastDaySig) evalTime(row chunk.Row) (types.Time, bool, error) { tm := arg.Time year, month, day := tm.Year(), tm.Month(), 30 if year == 0 && month == 0 && tm.Day() == 0 { - return types.Time{}, true, errors.Trace(handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenByArgs(arg.String()))) + return types.Time{}, true, errors.Trace(handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(arg.String()))) } if month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12 { diff --git a/expression/builtin_time_test.go b/expression/builtin_time_test.go index e516c6da08d25..437094bce1d44 100644 --- a/expression/builtin_time_test.go +++ b/expression/builtin_time_test.go @@ -19,7 +19,6 @@ import ( "strings" "time" - "github.com/juju/errors" . "github.com/pingcap/check" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/mysql" @@ -32,6 +31,7 @@ import ( "github.com/pingcap/tidb/util/mock" "github.com/pingcap/tidb/util/testleak" "github.com/pingcap/tidb/util/testutil" + "github.com/pkg/errors" ) func (s *testEvaluatorSuite) TestDate(c *C) { diff --git a/expression/chunk_executor.go b/expression/chunk_executor.go index 887eb2463c3a3..857211d65a3e1 100644 --- a/expression/chunk_executor.go +++ b/expression/chunk_executor.go @@ -16,12 +16,12 @@ package expression import ( "strconv" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" + "github.com/pkg/errors" ) // Vectorizable checks whether a list of expressions can employ vectorized execution. diff --git a/expression/column.go b/expression/column.go index a48485b77f511..e1cc400f61ecf 100644 --- a/expression/column.go +++ b/expression/column.go @@ -17,7 +17,6 @@ import ( "fmt" "strings" - "github.com/juju/errors" "github.com/pingcap/tidb/model" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/sessionctx" @@ -26,6 +25,7 @@ import ( "github.com/pingcap/tidb/types/json" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/codec" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" ) diff --git a/expression/constant.go b/expression/constant.go index 600a70aa48444..c1479355d5c13 100644 --- a/expression/constant.go +++ b/expression/constant.go @@ -16,7 +16,6 @@ package expression import ( "fmt" - "github.com/juju/errors" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/sessionctx/stmtctx" @@ -25,6 +24,7 @@ import ( "github.com/pingcap/tidb/types/json" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/codec" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" ) diff --git a/expression/constant_propagation.go b/expression/constant_propagation.go index c0573b6712b0c..c0d7a0fd10ddf 100644 --- a/expression/constant_propagation.go +++ b/expression/constant_propagation.go @@ -14,13 +14,13 @@ package expression import ( - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/terror" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" ) diff --git a/expression/distsql_builtin.go b/expression/distsql_builtin.go index 3c9720f13e2c0..af066f0ab33bb 100644 --- a/expression/distsql_builtin.go +++ b/expression/distsql_builtin.go @@ -17,7 +17,6 @@ import ( "fmt" "time" - "github.com/juju/errors" "github.com/pingcap/tidb/model" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/sessionctx" @@ -26,6 +25,7 @@ import ( "github.com/pingcap/tidb/util/codec" "github.com/pingcap/tidb/util/mock" "github.com/pingcap/tipb/go-tipb" + "github.com/pkg/errors" ) func pbTypeToFieldType(tp *tipb.FieldType) *types.FieldType { @@ -454,7 +454,7 @@ func getSignatureByPB(ctx sessionctx.Context, sigCode tipb.ScalarFuncSig, tp *ti f = &builtinDateFormatSig{base} default: - e = errFunctionNotExists.GenByArgs("FUNCTION", sigCode) + e = errFunctionNotExists.GenWithStackByArgs("FUNCTION", sigCode) return nil, errors.Trace(e) } return f, nil diff --git a/expression/evaluator.go b/expression/evaluator.go index ce46e4d8d0233..84f2cc81627c8 100644 --- a/expression/evaluator.go +++ b/expression/evaluator.go @@ -14,9 +14,9 @@ package expression import ( - "github.com/juju/errors" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/util/chunk" + "github.com/pkg/errors" ) type columnEvaluator struct { diff --git a/expression/expr_to_pb.go b/expression/expr_to_pb.go index f3e7b35aaf565..6dee4893ba66c 100644 --- a/expression/expr_to_pb.go +++ b/expression/expr_to_pb.go @@ -16,7 +16,6 @@ package expression import ( "time" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/mysql" @@ -27,6 +26,7 @@ import ( "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/codec" "github.com/pingcap/tipb/go-tipb" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" ) diff --git a/expression/expression.go b/expression/expression.go index e4be2df9d798c..072bc5a62f1bf 100644 --- a/expression/expression.go +++ b/expression/expression.go @@ -17,7 +17,6 @@ import ( goJSON "encoding/json" "fmt" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/model" "github.com/pingcap/tidb/mysql" @@ -27,6 +26,7 @@ import ( "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/types/json" "github.com/pingcap/tidb/util/chunk" + "github.com/pkg/errors" ) // These are byte flags used for `HashCode()`. diff --git a/expression/helper.go b/expression/helper.go index 24077e488b5ef..fe193651712a1 100644 --- a/expression/helper.go +++ b/expression/helper.go @@ -18,13 +18,13 @@ import ( "strings" "time" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/sessionctx/variable" "github.com/pingcap/tidb/terror" "github.com/pingcap/tidb/types" + "github.com/pkg/errors" ) func boolToInt64(v bool) int64 { diff --git a/expression/integration_test.go b/expression/integration_test.go index cf64bfdbc60e9..376a69f71f398 100644 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -20,7 +20,6 @@ import ( "strings" "time" - "github.com/juju/errors" . "github.com/pingcap/check" "github.com/pingcap/tidb/domain" "github.com/pingcap/tidb/expression" @@ -39,6 +38,7 @@ import ( "github.com/pingcap/tidb/util/testkit" "github.com/pingcap/tidb/util/testleak" "github.com/pingcap/tidb/util/testutil" + "github.com/pkg/errors" "golang.org/x/net/context" ) @@ -402,7 +402,7 @@ func (s *testIntegrationSuite) TestMathBuiltin(c *C) { c.Assert(err, IsNil) _, err = session.GetRows4Test(ctx, tk.Se, rs) c.Assert(err, NotNil) - terr := errors.Trace(err).(*errors.Err).Cause().(*terror.Error) + terr := errors.Cause(err).(*terror.Error) c.Assert(terr.Code(), Equals, terror.ErrCode(mysql.ErrDataOutOfRange)) c.Assert(rs.Close(), IsNil) @@ -415,7 +415,7 @@ func (s *testIntegrationSuite) TestMathBuiltin(c *C) { c.Assert(err, IsNil) _, err = session.GetRows4Test(ctx, tk.Se, rs) c.Assert(err, NotNil) - terr = errors.Trace(err).(*errors.Err).Cause().(*terror.Error) + terr = errors.Cause(err).(*terror.Error) c.Assert(terr.Code(), Equals, terror.ErrCode(mysql.ErrDataOutOfRange)) c.Assert(rs.Close(), IsNil) @@ -454,7 +454,7 @@ func (s *testIntegrationSuite) TestMathBuiltin(c *C) { c.Assert(err, IsNil) _, err = session.GetRows4Test(ctx, tk.Se, rs) c.Assert(err, NotNil) - terr = errors.Trace(err).(*errors.Err).Cause().(*terror.Error) + terr = errors.Cause(err).(*terror.Error) c.Assert(terr.Code(), Equals, terror.ErrCode(mysql.ErrDataOutOfRange)) c.Assert(rs.Close(), IsNil) @@ -513,7 +513,7 @@ func (s *testIntegrationSuite) TestMathBuiltin(c *C) { c.Assert(err, IsNil) _, err = session.GetRows4Test(ctx, tk.Se, rs) c.Assert(err, NotNil) - terr = errors.Trace(err).(*errors.Err).Cause().(*terror.Error) + terr = errors.Cause(err).(*terror.Error) c.Assert(terr.Code(), Equals, terror.ErrCode(mysql.ErrDataOutOfRange)) c.Assert(rs.Close(), IsNil) @@ -1044,7 +1044,7 @@ func (s *testIntegrationSuite) TestEncryptionBuiltin(c *C) { c.Assert(err, IsNil, Commentf("%v", len)) _, err = session.GetRows4Test(ctx, tk.Se, rs) c.Assert(err, NotNil, Commentf("%v", len)) - terr := errors.Trace(err).(*errors.Err).Cause().(*terror.Error) + terr := errors.Cause(err).(*terror.Error) c.Assert(terr.Code(), Equals, terror.ErrCode(mysql.ErrDataOutOfRange), Commentf("%v", len)) c.Assert(rs.Close(), IsNil) } @@ -3062,7 +3062,7 @@ func (s *testIntegrationSuite) TestDateBuiltin(c *C) { rs, err := tk.Exec("select date '0000-00-00';") _, err = session.GetRows4Test(ctx, tk.Se, rs) c.Assert(err, NotNil) - c.Assert(terror.ErrorEqual(err, types.ErrIncorrectDatetimeValue.GenByArgs("0000-00-00")), IsTrue) + c.Assert(terror.ErrorEqual(err, types.ErrIncorrectDatetimeValue.GenWithStackByArgs("0000-00-00")), IsTrue) c.Assert(rs.Close(), IsNil) tk.MustExec("set sql_mode = ''") @@ -3073,7 +3073,7 @@ func (s *testIntegrationSuite) TestDateBuiltin(c *C) { rs, _ = tk.Exec("select date '2007-10-00';") _, err = session.GetRows4Test(ctx, tk.Se, rs) c.Assert(err, NotNil) - c.Assert(terror.ErrorEqual(err, types.ErrIncorrectDatetimeValue.GenByArgs("2017-10-00")), IsTrue) + c.Assert(terror.ErrorEqual(err, types.ErrIncorrectDatetimeValue.GenWithStackByArgs("2017-10-00")), IsTrue) c.Assert(rs.Close(), IsNil) tk.MustExec("set sql_mode = 'NO_ZERO_DATE'") @@ -3085,13 +3085,13 @@ func (s *testIntegrationSuite) TestDateBuiltin(c *C) { rs, _ = tk.Exec("select date '2007-10-00';") _, err = session.GetRows4Test(ctx, tk.Se, rs) c.Assert(err, NotNil) - c.Assert(terror.ErrorEqual(err, types.ErrIncorrectDatetimeValue.GenByArgs("2017-10-00")), IsTrue) + c.Assert(terror.ErrorEqual(err, types.ErrIncorrectDatetimeValue.GenWithStackByArgs("2017-10-00")), IsTrue) c.Assert(rs.Close(), IsNil) rs, err = tk.Exec("select date '0000-00-00';") _, err = session.GetRows4Test(ctx, tk.Se, rs) c.Assert(err, NotNil) - c.Assert(terror.ErrorEqual(err, types.ErrIncorrectDatetimeValue.GenByArgs("0000-00-00")), IsTrue) + c.Assert(terror.ErrorEqual(err, types.ErrIncorrectDatetimeValue.GenWithStackByArgs("0000-00-00")), IsTrue) c.Assert(rs.Close(), IsNil) r = tk.MustQuery("select date'1998~01~02'") @@ -3102,7 +3102,7 @@ func (s *testIntegrationSuite) TestDateBuiltin(c *C) { _, err = tk.Exec("select date '0000-00-00 00:00:00';") c.Assert(err, NotNil) - c.Assert(terror.ErrorEqual(err, types.ErrIncorrectDatetimeValue.GenByArgs("0000-00-00 00:00:00")), IsTrue) + c.Assert(terror.ErrorEqual(err, types.ErrIncorrectDatetimeValue.GenWithStackByArgs("0000-00-00 00:00:00")), IsTrue) _, err = tk.Exec("select date '2017-99-99';") c.Assert(err, NotNil) @@ -3114,11 +3114,11 @@ func (s *testIntegrationSuite) TestDateBuiltin(c *C) { _, err = tk.Exec("select date '201712-31';") c.Assert(err, NotNil) - c.Assert(terror.ErrorEqual(err, types.ErrIncorrectDatetimeValue.GenByArgs("201712-31")), IsTrue) + c.Assert(terror.ErrorEqual(err, types.ErrIncorrectDatetimeValue.GenWithStackByArgs("201712-31")), IsTrue) _, err = tk.Exec("select date 'abcdefg';") c.Assert(err, NotNil) - c.Assert(terror.ErrorEqual(err, types.ErrIncorrectDatetimeValue.GenByArgs("abcdefg")), IsTrue) + c.Assert(terror.ErrorEqual(err, types.ErrIncorrectDatetimeValue.GenWithStackByArgs("abcdefg")), IsTrue) } func (s *testIntegrationSuite) TestJSONBuiltin(c *C) { @@ -3164,15 +3164,15 @@ func (s *testIntegrationSuite) TestTimeLiteral(c *C) { _, err := tk.Exec("select time '2017-01-01 00:00:00';") c.Assert(err, NotNil) - c.Assert(terror.ErrorEqual(err, types.ErrIncorrectDatetimeValue.GenByArgs("2017-01-01 00:00:00")), IsTrue) + c.Assert(terror.ErrorEqual(err, types.ErrIncorrectDatetimeValue.GenWithStackByArgs("2017-01-01 00:00:00")), IsTrue) _, err = tk.Exec("select time '071231235959.999999';") c.Assert(err, NotNil) - c.Assert(terror.ErrorEqual(err, types.ErrIncorrectDatetimeValue.GenByArgs("071231235959.999999")), IsTrue) + c.Assert(terror.ErrorEqual(err, types.ErrIncorrectDatetimeValue.GenWithStackByArgs("071231235959.999999")), IsTrue) _, err = tk.Exec("select time '20171231235959.999999';") c.Assert(err, NotNil) - c.Assert(terror.ErrorEqual(err, types.ErrIncorrectDatetimeValue.GenByArgs("20171231235959.999999")), IsTrue) + c.Assert(terror.ErrorEqual(err, types.ErrIncorrectDatetimeValue.GenWithStackByArgs("20171231235959.999999")), IsTrue) } func (s *testIntegrationSuite) TestTimestampLiteral(c *C) { @@ -3193,15 +3193,15 @@ func (s *testIntegrationSuite) TestTimestampLiteral(c *C) { _, err := tk.Exec("select timestamp '00:00:00';") c.Assert(err, NotNil) - c.Assert(terror.ErrorEqual(err, types.ErrIncorrectDatetimeValue.GenByArgs("00:00:00")), IsTrue) + c.Assert(terror.ErrorEqual(err, types.ErrIncorrectDatetimeValue.GenWithStackByArgs("00:00:00")), IsTrue) _, err = tk.Exec("select timestamp '1992-01-03';") c.Assert(err, NotNil) - c.Assert(terror.ErrorEqual(err, types.ErrIncorrectDatetimeValue.GenByArgs("1992-01-03")), IsTrue) + c.Assert(terror.ErrorEqual(err, types.ErrIncorrectDatetimeValue.GenWithStackByArgs("1992-01-03")), IsTrue) _, err = tk.Exec("select timestamp '20171231235959.999999';") c.Assert(err, NotNil) - c.Assert(terror.ErrorEqual(err, types.ErrIncorrectDatetimeValue.GenByArgs("20171231235959.999999")), IsTrue) + c.Assert(terror.ErrorEqual(err, types.ErrIncorrectDatetimeValue.GenWithStackByArgs("20171231235959.999999")), IsTrue) } func (s *testIntegrationSuite) TestLiterals(c *C) { diff --git a/expression/scalar_function.go b/expression/scalar_function.go index 70de593374b1d..34f0d7673e7ec 100644 --- a/expression/scalar_function.go +++ b/expression/scalar_function.go @@ -17,7 +17,6 @@ import ( "bytes" "fmt" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/model" "github.com/pingcap/tidb/mysql" @@ -29,6 +28,7 @@ import ( "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/codec" "github.com/pingcap/tidb/util/hack" + "github.com/pkg/errors" ) // ScalarFunction is the function that returns a value. @@ -80,7 +80,7 @@ func NewFunction(ctx sessionctx.Context, funcName string, retType *types.FieldTy } fc, ok := funcs[funcName] if !ok { - return nil, errFunctionNotExists.GenByArgs("FUNCTION", funcName) + return nil, errFunctionNotExists.GenWithStackByArgs("FUNCTION", funcName) } funcArgs := make([]Expression, len(args)) copy(funcArgs, args) diff --git a/expression/schema.go b/expression/schema.go index e6a5955d9f198..ffa41b72498d9 100644 --- a/expression/schema.go +++ b/expression/schema.go @@ -16,8 +16,8 @@ package expression import ( "strings" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" + "github.com/pkg/errors" ) // KeyInfo stores the columns of one unique key or primary key. diff --git a/expression/simple_rewriter.go b/expression/simple_rewriter.go index c1da52783e344..eecb2608242af 100644 --- a/expression/simple_rewriter.go +++ b/expression/simple_rewriter.go @@ -14,7 +14,6 @@ package expression import ( - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/model" "github.com/pingcap/tidb/mysql" @@ -22,6 +21,7 @@ import ( "github.com/pingcap/tidb/parser/opcode" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/types" + "github.com/pkg/errors" ) type simpleRewriter struct { @@ -91,7 +91,7 @@ func (sr *simpleRewriter) rewriteColumn(nodeColName *ast.ColumnNameExpr) (*Colum if col != nil { return col, nil } - return nil, errBadField.GenByArgs(nodeColName.Name.Name.O, "expression") + return nil, errBadField.GenWithStackByArgs(nodeColName.Name.Name.O, "expression") } func (sr *simpleRewriter) Enter(inNode ast.Node) (ast.Node, bool) { @@ -168,7 +168,7 @@ func (sr *simpleRewriter) binaryOpToExpression(v *ast.BinaryOperationExpr) { lLen := GetRowLen(left) rLen := GetRowLen(right) if lLen != 1 || rLen != 1 { - sr.err = ErrOperandColumns.GenByArgs(1) + sr.err = ErrOperandColumns.GenWithStackByArgs(1) return } function, sr.err = NewFunction(sr.ctx, v.Op.String(), types.NewFieldType(mysql.TypeUnspecified), left, right) @@ -198,7 +198,7 @@ func (sr *simpleRewriter) rewriteFuncCall(v *ast.FuncCallExpr) bool { switch v.FnName.L { case ast.Nullif: if len(v.Args) != 2 { - sr.err = ErrIncorrectParameterCount.GenByArgs(v.FnName.O) + sr.err = ErrIncorrectParameterCount.GenWithStackByArgs(v.FnName.O) return true } param2 := sr.pop() @@ -244,7 +244,7 @@ func (sr *simpleRewriter) constructBinaryOpFunction(l Expression, r Expression, if lLen == 1 && rLen == 1 { return NewFunction(sr.ctx, op, types.NewFieldType(mysql.TypeTiny), l, r) } else if rLen != lLen { - return nil, ErrOperandColumns.GenByArgs(lLen) + return nil, ErrOperandColumns.GenWithStackByArgs(lLen) } switch op { case ast.EQ, ast.NE, ast.NullEQ: @@ -303,7 +303,7 @@ func (sr *simpleRewriter) unaryOpToExpression(v *ast.UnaryOperationExpr) { } expr := sr.pop() if GetRowLen(expr) != 1 { - sr.err = ErrOperandColumns.GenByArgs(1) + sr.err = ErrOperandColumns.GenWithStackByArgs(1) return } newExpr, err := NewFunction(sr.ctx, op, &v.Type, expr) @@ -381,7 +381,7 @@ func (sr *simpleRewriter) betweenToExpression(v *ast.BetweenExpr) { func (sr *simpleRewriter) isNullToExpression(v *ast.IsNullExpr) { arg := sr.pop() if GetRowLen(arg) != 1 { - sr.err = ErrOperandColumns.GenByArgs(1) + sr.err = ErrOperandColumns.GenWithStackByArgs(1) return } function := sr.notToExpression(v.Not, ast.IsNull, &v.Type, arg) @@ -414,7 +414,7 @@ func (sr *simpleRewriter) isTrueToScalarFunc(v *ast.IsTruthExpr) { op = ast.IsFalsity } if GetRowLen(arg) != 1 { - sr.err = ErrOperandColumns.GenByArgs(1) + sr.err = ErrOperandColumns.GenWithStackByArgs(1) return } function := sr.notToExpression(v.Not, op, &v.Type, arg) @@ -431,7 +431,7 @@ func (sr *simpleRewriter) inToExpression(lLen int, not bool, tp *types.FieldType l, leftFt := GetRowLen(leftExpr), leftExpr.GetType() for i := 0; i < lLen; i++ { if l != GetRowLen(elems[i]) { - sr.err = ErrOperandColumns.GenByArgs(l) + sr.err = ErrOperandColumns.GenWithStackByArgs(l) return } } diff --git a/expression/util.go b/expression/util.go index 4bd4794873e69..2ec13fc76bb58 100644 --- a/expression/util.go +++ b/expression/util.go @@ -19,7 +19,6 @@ import ( "time" "unicode" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/parser/opcode" @@ -28,6 +27,7 @@ import ( "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/hack" + "github.com/pkg/errors" ) // Filter the input expressions, append the results to result. @@ -384,7 +384,7 @@ func GetRowLen(e Expression) int { func CheckArgsNotMultiColumnRow(args ...Expression) error { for _, arg := range args { if GetRowLen(arg) != 1 { - return ErrOperandColumns.GenByArgs(1) + return ErrOperandColumns.GenWithStackByArgs(1) } } return nil diff --git a/infoschema/builder.go b/infoschema/builder.go index ded204fc587cf..85caaee73e17f 100644 --- a/infoschema/builder.go +++ b/infoschema/builder.go @@ -17,13 +17,13 @@ import ( "fmt" "sort" - "github.com/juju/errors" "github.com/pingcap/tidb/meta" "github.com/pingcap/tidb/meta/autoid" "github.com/pingcap/tidb/model" "github.com/pingcap/tidb/perfschema" "github.com/pingcap/tidb/table" "github.com/pingcap/tidb/table/tables" + "github.com/pkg/errors" ) // Builder builds a new InfoSchema. @@ -45,7 +45,7 @@ func (b *Builder) ApplyDiff(m *meta.Meta, diff *model.SchemaDiff) ([]int64, erro roDBInfo, ok := b.is.SchemaByID(diff.SchemaID) if !ok { - return nil, ErrDatabaseNotExists.GenByArgs( + return nil, ErrDatabaseNotExists.GenWithStackByArgs( fmt.Sprintf("(Schema ID %d)", diff.SchemaID), ) } @@ -79,7 +79,7 @@ func (b *Builder) ApplyDiff(m *meta.Meta, diff *model.SchemaDiff) ([]int64, erro if diff.Type == model.ActionRenameTable && diff.OldSchemaID != diff.SchemaID { oldRoDBInfo, ok := b.is.SchemaByID(diff.OldSchemaID) if !ok { - return nil, ErrDatabaseNotExists.GenByArgs( + return nil, ErrDatabaseNotExists.GenWithStackByArgs( fmt.Sprintf("(Schema ID %d)", diff.OldSchemaID), ) } @@ -117,7 +117,7 @@ func (b *Builder) applyCreateSchema(m *meta.Meta, diff *model.SchemaDiff) error if di == nil { // When we apply an old schema diff, the database may has been dropped already, so we need to fall back to // full load. - return ErrDatabaseNotExists.GenByArgs( + return ErrDatabaseNotExists.GenWithStackByArgs( fmt.Sprintf("(Schema ID %d)", diff.SchemaID), ) } @@ -166,7 +166,7 @@ func (b *Builder) applyCreateTable(m *meta.Meta, dbInfo *model.DBInfo, tableID i if tblInfo == nil { // When we apply an old schema diff, the table may has been dropped already, so we need to fall back to // full load. - return ErrTableNotExists.GenByArgs( + return ErrTableNotExists.GenWithStackByArgs( fmt.Sprintf("(Schema ID %d)", dbInfo.ID), fmt.Sprintf("(Table ID %d)", tableID), ) diff --git a/infoschema/infoschema.go b/infoschema/infoschema.go index 92f1a7e7dbc55..94469ce7f5c45 100644 --- a/infoschema/infoschema.go +++ b/infoschema/infoschema.go @@ -173,7 +173,7 @@ func (is *infoSchema) TableByName(schema, table model.CIStr) (t table.Table, err return } } - return nil, ErrTableNotExists.GenByArgs(schema, table) + return nil, ErrTableNotExists.GenWithStackByArgs(schema, table) } func (is *infoSchema) TableExists(schema, table model.CIStr) bool { diff --git a/infoschema/infoschema_test.go b/infoschema/infoschema_test.go index 61e4ab240fbab..840730638092a 100644 --- a/infoschema/infoschema_test.go +++ b/infoschema/infoschema_test.go @@ -17,7 +17,6 @@ import ( "sync" "testing" - "github.com/juju/errors" . "github.com/pingcap/check" "github.com/pingcap/tidb/infoschema" "github.com/pingcap/tidb/kv" @@ -29,6 +28,7 @@ import ( "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/testleak" "github.com/pingcap/tidb/util/testutil" + "github.com/pkg/errors" ) func TestT(t *testing.T) { diff --git a/infoschema/tables.go b/infoschema/tables.go index b5d5a4ecb5027..8925393e7a8ae 100644 --- a/infoschema/tables.go +++ b/infoschema/tables.go @@ -18,7 +18,6 @@ import ( "sort" "time" - "github.com/juju/errors" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/meta/autoid" "github.com/pingcap/tidb/model" @@ -30,6 +29,7 @@ import ( "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/charset" "github.com/pingcap/tidb/util/sqlexec" + "github.com/pkg/errors" ) const ( diff --git a/kv/buffer_store.go b/kv/buffer_store.go index be2535e57c4ea..5e798db5c8875 100644 --- a/kv/buffer_store.go +++ b/kv/buffer_store.go @@ -14,7 +14,7 @@ package kv import ( - "github.com/juju/errors" + "github.com/pkg/errors" ) var ( diff --git a/kv/fault_injection_test.go b/kv/fault_injection_test.go index 2bae33a47eed7..2c38853c3cd20 100644 --- a/kv/fault_injection_test.go +++ b/kv/fault_injection_test.go @@ -14,9 +14,9 @@ package kv_test import ( - "github.com/juju/errors" . "github.com/pingcap/check" "github.com/pingcap/tidb/kv" + "github.com/pkg/errors" ) type testFaultInjectionSuite struct{} diff --git a/kv/iter.go b/kv/iter.go index 2c337be3ca771..1551391ea0627 100644 --- a/kv/iter.go +++ b/kv/iter.go @@ -13,7 +13,7 @@ package kv -import "github.com/juju/errors" +import "github.com/pkg/errors" // NextUntil applies FnKeyCmp to each entry of the iterator until meets some condition. // It will stop when fn returns true, or iterator is invalid or an error occurs. diff --git a/kv/memdb_buffer.go b/kv/memdb_buffer.go index 069e24343eb23..a4aaf7496ce0f 100644 --- a/kv/memdb_buffer.go +++ b/kv/memdb_buffer.go @@ -18,13 +18,13 @@ package kv import ( "sync/atomic" - "github.com/juju/errors" "github.com/pingcap/goleveldb/leveldb" "github.com/pingcap/goleveldb/leveldb/comparer" "github.com/pingcap/goleveldb/leveldb/iterator" "github.com/pingcap/goleveldb/leveldb/memdb" "github.com/pingcap/goleveldb/leveldb/util" "github.com/pingcap/tidb/terror" + "github.com/pkg/errors" ) // memDbBuffer implements the MemBuffer interface. @@ -95,15 +95,15 @@ func (m *memDbBuffer) Set(k Key, v []byte) error { return errors.Trace(ErrCannotSetNilValue) } if len(k)+len(v) > m.entrySizeLimit { - return ErrEntryTooLarge.Gen("entry too large, size: %d", len(k)+len(v)) + return ErrEntryTooLarge.GenWithStack("entry too large, size: %d", len(k)+len(v)) } err := m.db.Put(k, v) if m.Size() > m.bufferSizeLimit { - return ErrTxnTooLarge.Gen("transaction too large, size:%d", m.Size()) + return ErrTxnTooLarge.GenWithStack("transaction too large, size:%d", m.Size()) } if m.Len() > int(m.bufferLenLimit) { - return ErrTxnTooLarge.Gen("transaction too large, len:%d", m.Len()) + return ErrTxnTooLarge.GenWithStack("transaction too large, len:%d", m.Len()) } return errors.Trace(err) } diff --git a/kv/mock.go b/kv/mock.go index d3ca739f08c7c..9fb8a0559c33d 100644 --- a/kv/mock.go +++ b/kv/mock.go @@ -14,8 +14,8 @@ package kv import ( - "github.com/juju/errors" "github.com/pingcap/tidb/store/tikv/oracle" + "github.com/pkg/errors" "golang.org/x/net/context" ) diff --git a/kv/txn.go b/kv/txn.go index da753ca3c382e..56221f45d3cfe 100644 --- a/kv/txn.go +++ b/kv/txn.go @@ -18,8 +18,8 @@ import ( "math/rand" "time" - "github.com/juju/errors" "github.com/pingcap/tidb/terror" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" ) diff --git a/kv/union_iter.go b/kv/union_iter.go index 6ee5065ca03cd..c4ae42cfd5766 100644 --- a/kv/union_iter.go +++ b/kv/union_iter.go @@ -14,7 +14,7 @@ package kv import ( - "github.com/juju/errors" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" ) diff --git a/kv/union_store.go b/kv/union_store.go index 7823528ff4136..6e3111f3ca240 100644 --- a/kv/union_store.go +++ b/kv/union_store.go @@ -16,7 +16,7 @@ package kv import ( "bytes" - "github.com/juju/errors" + "github.com/pkg/errors" ) // UnionStore is a store that wraps a snapshot for read and a BufferStore for buffered write. diff --git a/kv/utils.go b/kv/utils.go index 8fb08d13faedb..214745bfadb41 100644 --- a/kv/utils.go +++ b/kv/utils.go @@ -16,7 +16,7 @@ package kv import ( "strconv" - "github.com/juju/errors" + "github.com/pkg/errors" ) // IncInt64 increases the value for key k in kv store by step. diff --git a/meta/autoid/autoid.go b/meta/autoid/autoid.go index 2568af1843ff5..095b7ba271db4 100644 --- a/meta/autoid/autoid.go +++ b/meta/autoid/autoid.go @@ -20,11 +20,11 @@ import ( "time" "github.com/cznic/mathutil" - "github.com/juju/errors" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/meta" "github.com/pingcap/tidb/metrics" "github.com/pingcap/tidb/terror" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" ) @@ -99,7 +99,7 @@ func (alloc *allocator) NextGlobalAutoID(tableID int64) (int64, error) { // The real base may be greater than the required base. func (alloc *allocator) Rebase(tableID, requiredBase int64, allocIDs bool) error { if tableID == 0 { - return errInvalidTableID.Gen("Invalid tableID") + return errInvalidTableID.GenWithStack("Invalid tableID") } alloc.mu.Lock() @@ -151,7 +151,7 @@ func (alloc *allocator) Rebase(tableID, requiredBase int64, allocIDs bool) error // Alloc implements autoid.Allocator Alloc interface. func (alloc *allocator) Alloc(tableID int64) (int64, error) { if tableID == 0 { - return 0, errInvalidTableID.Gen("Invalid tableID") + return 0, errInvalidTableID.GenWithStack("Invalid tableID") } alloc.mu.Lock() defer alloc.mu.Unlock() @@ -221,7 +221,7 @@ func (alloc *memoryAllocator) Rebase(tableID, newBase int64, allocIDs bool) erro // Alloc implements autoid.Allocator Alloc interface. func (alloc *memoryAllocator) Alloc(tableID int64) (int64, error) { if tableID == 0 { - return 0, errInvalidTableID.Gen("Invalid tableID") + return 0, errInvalidTableID.GenWithStack("Invalid tableID") } alloc.mu.Lock() defer alloc.mu.Unlock() diff --git a/meta/autoid/autoid_test.go b/meta/autoid/autoid_test.go index 7d0d5d537092e..15caebe1cd36d 100644 --- a/meta/autoid/autoid_test.go +++ b/meta/autoid/autoid_test.go @@ -19,13 +19,13 @@ import ( "testing" "time" - "github.com/juju/errors" . "github.com/pingcap/check" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/meta" "github.com/pingcap/tidb/meta/autoid" "github.com/pingcap/tidb/model" "github.com/pingcap/tidb/store/mockstore" + "github.com/pkg/errors" ) func TestT(t *testing.T) { diff --git a/meta/meta.go b/meta/meta.go index 443adda7a9161..877453d67c012 100644 --- a/meta/meta.go +++ b/meta/meta.go @@ -24,13 +24,13 @@ import ( "sync" "time" - "github.com/juju/errors" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/metrics" "github.com/pingcap/tidb/model" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/structure" "github.com/pingcap/tidb/terror" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" ) diff --git a/metrics/server.go b/metrics/server.go index a0d09a627ac45..caa99a632f33e 100644 --- a/metrics/server.go +++ b/metrics/server.go @@ -16,8 +16,8 @@ package metrics import ( "strconv" - "github.com/juju/errors" "github.com/pingcap/tidb/terror" + "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" ) diff --git a/model/ddl.go b/model/ddl.go index 1492a77001930..23db9df3e2d90 100644 --- a/model/ddl.go +++ b/model/ddl.go @@ -20,8 +20,8 @@ import ( "sync" "time" - "github.com/juju/errors" "github.com/pingcap/tidb/terror" + "github.com/pkg/errors" ) // ActionType is the type for DDL action. diff --git a/model/model.go b/model/model.go index 74545f8d4f47b..17dc813c7c78d 100644 --- a/model/model.go +++ b/model/model.go @@ -19,11 +19,11 @@ import ( "strings" "time" - "github.com/juju/errors" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/hack" "github.com/pingcap/tipb/go-tipb" + "github.com/pkg/errors" ) // SchemaState is the state for schema elements. @@ -104,7 +104,7 @@ func (c *ColumnInfo) SetDefaultValue(value interface{}) error { c.DefaultValueBit = []byte(v) return nil } - return types.ErrInvalidDefault.GenByArgs(c.Name) + return types.ErrInvalidDefault.GenWithStackByArgs(c.Name) } return nil } diff --git a/mysql/locale_format.go b/mysql/locale_format.go index f09e9c52ceea8..62037e854e268 100644 --- a/mysql/locale_format.go +++ b/mysql/locale_format.go @@ -6,7 +6,7 @@ import ( "strings" "unicode" - "github.com/juju/errors" + "github.com/pkg/errors" ) func formatENUS(number string, precision string) (string, error) { diff --git a/owner/manager.go b/owner/manager.go index 66b9e58664d9f..6ac8d8eac285f 100644 --- a/owner/manager.go +++ b/owner/manager.go @@ -26,10 +26,10 @@ import ( "github.com/coreos/etcd/clientv3/concurrency" "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" "github.com/coreos/etcd/mvcc/mvccpb" - "github.com/juju/errors" "github.com/pingcap/tidb/metrics" "github.com/pingcap/tidb/terror" "github.com/pingcap/tidb/util" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" "google.golang.org/grpc" diff --git a/owner/mock.go b/owner/mock.go index 5516b0e5e2b46..5266ba9b2553d 100644 --- a/owner/mock.go +++ b/owner/mock.go @@ -16,7 +16,7 @@ package owner import ( "sync/atomic" - "github.com/juju/errors" + "github.com/pkg/errors" "golang.org/x/net/context" ) diff --git a/parser/parser_test.go b/parser/parser_test.go index 771b96f4ed063..c649c6615deb7 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -19,13 +19,13 @@ import ( "strings" "testing" - "github.com/juju/errors" . "github.com/pingcap/check" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/terror" "github.com/pingcap/tidb/util/charset" "github.com/pingcap/tidb/util/testleak" + "github.com/pkg/errors" ) func TestT(t *testing.T) { diff --git a/parser/yy_parser.go b/parser/yy_parser.go index 487580c2ccf07..48098ef3e9158 100644 --- a/parser/yy_parser.go +++ b/parser/yy_parser.go @@ -19,12 +19,12 @@ import ( "strconv" "unicode" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/terror" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/hack" + "github.com/pkg/errors" ) const ( @@ -131,11 +131,11 @@ func (parser *Parser) SetSQLMode(mode mysql.SQLMode) { } // ParseErrorWith returns "You have a syntax error near..." error message compatible with mysql. -func ParseErrorWith(errstr string, lineno int) *terror.Error { +func ParseErrorWith(errstr string, lineno int) error { if len(errstr) > mysql.ErrTextLength { errstr = errstr[:mysql.ErrTextLength] } - return ErrParse.GenByArgs(mysql.MySQLErrName[mysql.ErrSyntax], errstr, lineno) + return ErrParse.GenWithStackByArgs(mysql.MySQLErrName[mysql.ErrSyntax], errstr, lineno) } // The select statement is not at the end of the whole statement, if the last diff --git a/plan/cbo_test.go b/plan/cbo_test.go index c9aa1ef65baff..9c2f4cf609aec 100644 --- a/plan/cbo_test.go +++ b/plan/cbo_test.go @@ -17,7 +17,6 @@ import ( "fmt" "testing" - "github.com/juju/errors" . "github.com/pingcap/check" "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/domain" @@ -29,6 +28,7 @@ import ( "github.com/pingcap/tidb/store/mockstore" "github.com/pingcap/tidb/util/testkit" "github.com/pingcap/tidb/util/testleak" + "github.com/pkg/errors" ) var _ = Suite(&testAnalyzeSuite{}) diff --git a/plan/common_plans.go b/plan/common_plans.go index 5af8667d01cd1..8b41cae415bd4 100644 --- a/plan/common_plans.go +++ b/plan/common_plans.go @@ -18,7 +18,6 @@ import ( "fmt" "strconv" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/infoschema" @@ -30,6 +29,7 @@ import ( "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/kvcache" "github.com/pingcap/tidb/util/ranger" + "github.com/pkg/errors" ) // ShowDDL is for showing DDL information. @@ -167,7 +167,7 @@ func (e *Execute) optimizePreparedPlan(ctx sessionctx.Context, is infoschema.Inf // if this time it failed, the real reason for the error is schema changed. err := Preprocess(ctx, prepared.Stmt, is, true) if err != nil { - return ErrSchemaChanged.Gen("Schema change caused error: %s", err.Error()) + return ErrSchemaChanged.GenWithStack("Schema change caused error: %s", err.Error()) } prepared.SchemaVersion = is.SchemaMetaVersion() } diff --git a/plan/exhaust_physical_plans.go b/plan/exhaust_physical_plans.go index ad8ed66d37587..b89a29ac243bb 100644 --- a/plan/exhaust_physical_plans.go +++ b/plan/exhaust_physical_plans.go @@ -16,7 +16,6 @@ package plan import ( "math" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/expression/aggregation" @@ -26,6 +25,7 @@ import ( "github.com/pingcap/tidb/terror" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/ranger" + "github.com/pkg/errors" ) func (p *LogicalUnionScan) exhaustPhysicalPlans(prop *property.PhysicalProperty) []PhysicalPlan { diff --git a/plan/expression_rewriter.go b/plan/expression_rewriter.go index b2811f8925d5c..9f46fb21809e4 100644 --- a/plan/expression_rewriter.go +++ b/plan/expression_rewriter.go @@ -17,7 +17,6 @@ import ( "strconv" "strings" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/expression/aggregation" @@ -29,6 +28,7 @@ import ( "github.com/pingcap/tidb/sessionctx/variable" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" + "github.com/pkg/errors" ) // EvalSubquery evaluates incorrelated subqueries once. @@ -183,7 +183,7 @@ func (er *expressionRewriter) constructBinaryOpFunction(l expression.Expression, if lLen == 1 && rLen == 1 { return expression.NewFunction(er.ctx, op, types.NewFieldType(mysql.TypeTiny), l, r) } else if rLen != lLen { - return nil, expression.ErrOperandColumns.GenByArgs(lLen) + return nil, expression.ErrOperandColumns.GenWithStackByArgs(lLen) } switch op { case ast.EQ, ast.NE, ast.NullEQ: @@ -299,7 +299,7 @@ func (er *expressionRewriter) Enter(inNode ast.Node) (ast.Node, bool) { return inNode, false } if col == nil { - er.err = ErrUnknownColumn.GenByArgs(v.Column.Name.OrigColName(), "field list") + er.err = ErrUnknownColumn.GenWithStackByArgs(v.Column.Name.OrigColName(), "field list") return inNode, false } er.ctxStack = append(er.ctxStack, expression.NewValuesFunc(er.ctx, col.Index, col.RetType)) @@ -329,12 +329,12 @@ func (er *expressionRewriter) handleCompareSubquery(v *ast.CompareSubqueryExpr) // Only (a,b,c) = any (...) and (a,b,c) != all (...) can use row expression. canMultiCol := (!v.All && v.Op == opcode.EQ) || (v.All && v.Op == opcode.NE) if !canMultiCol && (expression.GetRowLen(lexpr) != 1 || np.Schema().Len() != 1) { - er.err = expression.ErrOperandColumns.GenByArgs(1) + er.err = expression.ErrOperandColumns.GenWithStackByArgs(1) return v, true } lLen := expression.GetRowLen(lexpr) if lLen != np.Schema().Len() { - er.err = expression.ErrOperandColumns.GenByArgs(lLen) + er.err = expression.ErrOperandColumns.GenWithStackByArgs(lLen) return v, true } var condition expression.Expression @@ -614,7 +614,7 @@ func (er *expressionRewriter) handleInSubquery(v *ast.PatternInExpr) (ast.Node, } lLen := expression.GetRowLen(lexpr) if lLen != np.Schema().Len() { - er.err = expression.ErrOperandColumns.GenByArgs(lLen) + er.err = expression.ErrOperandColumns.GenWithStackByArgs(lLen) return v, true } // Sometimes we can unfold the in subquery. For example, a in (select * from t) can rewrite to `a in (1,2,3,4)`. @@ -900,7 +900,7 @@ func (er *expressionRewriter) unaryOpToExpression(v *ast.UnaryOperationExpr) { return } if expression.GetRowLen(er.ctxStack[stkLen-1]) != 1 { - er.err = expression.ErrOperandColumns.GenByArgs(1) + er.err = expression.ErrOperandColumns.GenWithStackByArgs(1) return } er.ctxStack[stkLen-1], er.err = expression.NewFunction(er.ctx, op, &v.Type, er.ctxStack[stkLen-1]) @@ -917,7 +917,7 @@ func (er *expressionRewriter) binaryOpToExpression(v *ast.BinaryOperationExpr) { lLen := expression.GetRowLen(er.ctxStack[stkLen-2]) rLen := expression.GetRowLen(er.ctxStack[stkLen-1]) if lLen != 1 || rLen != 1 { - er.err = expression.ErrOperandColumns.GenByArgs(1) + er.err = expression.ErrOperandColumns.GenWithStackByArgs(1) return } function, er.err = expression.NewFunction(er.ctx, v.Op.String(), types.NewFieldType(mysql.TypeUnspecified), er.ctxStack[stkLen-2:]...) @@ -952,7 +952,7 @@ func (er *expressionRewriter) notToExpression(hasNot bool, op string, tp *types. func (er *expressionRewriter) isNullToExpression(v *ast.IsNullExpr) { stkLen := len(er.ctxStack) if expression.GetRowLen(er.ctxStack[stkLen-1]) != 1 { - er.err = expression.ErrOperandColumns.GenByArgs(1) + er.err = expression.ErrOperandColumns.GenWithStackByArgs(1) return } function := er.notToExpression(v.Not, ast.IsNull, &v.Type, er.ctxStack[stkLen-1]) @@ -964,7 +964,7 @@ func (er *expressionRewriter) positionToScalarFunc(v *ast.PositionExpr) { if v.N > 0 && v.N <= er.schema.Len() { er.ctxStack = append(er.ctxStack, er.schema.Columns[v.N-1]) } else { - er.err = ErrUnknownColumn.GenByArgs(strconv.Itoa(v.N), clauseMsg[er.b.curClause]) + er.err = ErrUnknownColumn.GenWithStackByArgs(strconv.Itoa(v.N), clauseMsg[er.b.curClause]) } } @@ -975,7 +975,7 @@ func (er *expressionRewriter) isTrueToScalarFunc(v *ast.IsTruthExpr) { op = ast.IsFalsity } if expression.GetRowLen(er.ctxStack[stkLen-1]) != 1 { - er.err = expression.ErrOperandColumns.GenByArgs(1) + er.err = expression.ErrOperandColumns.GenWithStackByArgs(1) return } function := er.notToExpression(v.Not, op, &v.Type, er.ctxStack[stkLen-1]) @@ -991,7 +991,7 @@ func (er *expressionRewriter) inToExpression(lLen int, not bool, tp *types.Field l := expression.GetRowLen(er.ctxStack[stkLen-lLen-1]) for i := 0; i < lLen; i++ { if l != expression.GetRowLen(er.ctxStack[stkLen-lLen+i]) { - er.err = expression.ErrOperandColumns.GenByArgs(l) + er.err = expression.ErrOperandColumns.GenWithStackByArgs(l) return } } @@ -1176,7 +1176,7 @@ func (er *expressionRewriter) rewriteFuncCall(v *ast.FuncCallExpr) bool { switch v.FnName.L { case ast.Nullif: if len(v.Args) != 2 { - er.err = expression.ErrIncorrectParameterCount.GenByArgs(v.FnName.O) + er.err = expression.ErrIncorrectParameterCount.GenWithStackByArgs(v.FnName.O) return true } stackLen := len(er.ctxStack) @@ -1228,7 +1228,7 @@ func (er *expressionRewriter) funcCallToExpression(v *ast.FuncCallExpr) { func (er *expressionRewriter) toColumn(v *ast.ColumnName) { column, err := er.schema.FindColumn(v) if err != nil { - er.err = ErrAmbiguous.GenByArgs(v.Name, clauseMsg[fieldList]) + er.err = ErrAmbiguous.GenWithStackByArgs(v.Name, clauseMsg[fieldList]) return } if column != nil { @@ -1243,7 +1243,7 @@ func (er *expressionRewriter) toColumn(v *ast.ColumnName) { return } if err != nil { - er.err = ErrAmbiguous.GenByArgs(v.Name, clauseMsg[fieldList]) + er.err = ErrAmbiguous.GenWithStackByArgs(v.Name, clauseMsg[fieldList]) return } } @@ -1258,5 +1258,5 @@ func (er *expressionRewriter) toColumn(v *ast.ColumnName) { return } } - er.err = ErrUnknownColumn.GenByArgs(v.String(), clauseMsg[er.b.curClause]) + er.err = ErrUnknownColumn.GenWithStackByArgs(v.String(), clauseMsg[er.b.curClause]) } diff --git a/plan/find_best_task.go b/plan/find_best_task.go index 4339100d51945..38ca150f9127a 100644 --- a/plan/find_best_task.go +++ b/plan/find_best_task.go @@ -16,7 +16,6 @@ package plan import ( "math" - "github.com/juju/errors" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/infoschema" "github.com/pingcap/tidb/model" @@ -24,6 +23,7 @@ import ( "github.com/pingcap/tidb/plan/property" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" + "github.com/pkg/errors" ) const ( diff --git a/plan/logical_plan_builder.go b/plan/logical_plan_builder.go index 99bf2804404f6..1d1711fd331ed 100644 --- a/plan/logical_plan_builder.go +++ b/plan/logical_plan_builder.go @@ -22,7 +22,6 @@ import ( "unicode" "github.com/cznic/mathutil" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/domain" "github.com/pingcap/tidb/expression" @@ -39,6 +38,7 @@ import ( "github.com/pingcap/tidb/table" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" + "github.com/pkg/errors" ) const ( @@ -137,7 +137,7 @@ func (b *planBuilder) buildResultSetNode(node ast.ResultSetNode) (p LogicalPlan, case *ast.TableName: p, err = b.buildDataSource(v) default: - err = ErrUnsupportedType.GenByArgs(v) + err = ErrUnsupportedType.GenWithStackByArgs(v) } if err != nil { return nil, errors.Trace(err) @@ -159,7 +159,7 @@ func (b *planBuilder) buildResultSetNode(node ast.ResultSetNode) (p LogicalPlan, for _, col := range p.Schema().Columns { name := col.ColName.O if _, ok := dupNames[name]; ok { - return nil, ErrDupFieldName.GenByArgs(name) + return nil, ErrDupFieldName.GenWithStackByArgs(name) } dupNames[name] = struct{}{} } @@ -169,7 +169,7 @@ func (b *planBuilder) buildResultSetNode(node ast.ResultSetNode) (p LogicalPlan, case *ast.UnionStmt: return b.buildUnion(x) default: - return nil, ErrUnsupportedType.Gen("Unsupported ast.ResultSetNode(%T) for buildResultSetNode()", x) + return nil, ErrUnsupportedType.GenWithStack("Unsupported ast.ResultSetNode(%T) for buildResultSetNode()", x) } } @@ -405,7 +405,7 @@ func (b *planBuilder) coalesceCommonColumns(p *LogicalJoin, leftPlan, rightPlan if len(filter) > 0 && len(filter) != commonLen { for col, notExist := range filter { if notExist { - return ErrUnknownColumn.GenByArgs(col, "from clause") + return ErrUnknownColumn.GenWithStackByArgs(col, "from clause") } } } @@ -731,7 +731,7 @@ func (b *planBuilder) divideUnionSelectPlans(selects []*ast.SelectStmt) (distinc columnNums = selectPlan.Schema().Len() } if selectPlan.Schema().Len() != columnNums { - return nil, nil, ErrWrongNumberOfColumnsInSelect.GenByArgs() + return nil, nil, ErrWrongNumberOfColumnsInSelect.GenWithStackByArgs() } children[i] = selectPlan } @@ -813,14 +813,14 @@ func (b *planBuilder) buildLimit(src LogicalPlan, limit *ast.Limit) (LogicalPlan if limit.Offset != nil { offset, err = getUintForLimitOffset(sc, limit.Offset.GetValue()) if err != nil { - return nil, ErrWrongArguments.GenByArgs("LIMIT") + return nil, ErrWrongArguments.GenWithStackByArgs("LIMIT") } } if limit.Count != nil { count, err = getUintForLimitOffset(sc, limit.Count.GetValue()) if err != nil { - return nil, ErrWrongArguments.GenByArgs("LIMIT") + return nil, ErrWrongArguments.GenWithStackByArgs("LIMIT") } } @@ -890,7 +890,7 @@ func resolveFromSelectFields(v *ast.ColumnNameExpr, fields []*ast.SelectField, i index = i } else if !colMatch(matchedExpr.(*ast.ColumnNameExpr).Name, curCol.Name) && !colMatch(curCol.Name, matchedExpr.(*ast.ColumnNameExpr).Name) { - return -1, ErrAmbiguous.GenByArgs(curCol.Name.Name.L, clauseMsg[fieldList]) + return -1, ErrAmbiguous.GenWithStackByArgs(curCol.Name.Name.L, clauseMsg[fieldList]) } } } @@ -1019,7 +1019,7 @@ func (a *havingAndOrderbyExprResolver) Leave(n ast.Node) (node ast.Node, ok bool return n, true } } - a.err = ErrUnknownColumn.GenByArgs(v.Name.OrigColName(), clauseMsg[a.curClause]) + a.err = ErrUnknownColumn.GenWithStackByArgs(v.Name.OrigColName(), clauseMsg[a.curClause]) return node, false } if a.inAggFunc { @@ -1125,7 +1125,7 @@ func (g *gbyResolver) Leave(inNode ast.Node) (ast.Node, bool) { ret := g.fields[index].Expr ret.Accept(extractor) if len(extractor.AggFuncs) != 0 { - err = ErrIllegalReference.GenByArgs(v.Name.OrigColName(), "reference to group function") + err = ErrIllegalReference.GenWithStackByArgs(v.Name.OrigColName(), "reference to group function") } else { return ret, true } @@ -1141,7 +1141,7 @@ func (g *gbyResolver) Leave(inNode ast.Node) (ast.Node, bool) { ret := g.fields[v.N-1].Expr ret.Accept(extractor) if len(extractor.AggFuncs) != 0 { - g.err = ErrWrongGroupField.GenByArgs(g.fields[v.N-1].Text()) + g.err = ErrWrongGroupField.GenWithStackByArgs(g.fields[v.N-1].Text()) return inNode, false } return ret, true @@ -1402,9 +1402,9 @@ func (b *planBuilder) checkOnlyFullGroupByWithGroupClause(p LogicalPlan, sel *as } switch errExprLoc.Loc { case ErrExprInSelect: - return ErrFieldNotInGroupBy.GenByArgs(errExprLoc.Offset+1, errExprLoc.Loc, sel.Fields.Fields[errExprLoc.Offset].Text()) + return ErrFieldNotInGroupBy.GenWithStackByArgs(errExprLoc.Offset+1, errExprLoc.Loc, sel.Fields.Fields[errExprLoc.Offset].Text()) case ErrExprInOrderBy: - return ErrFieldNotInGroupBy.GenByArgs(errExprLoc.Offset+1, errExprLoc.Loc, sel.OrderBy.Items[errExprLoc.Offset].Expr.Text()) + return ErrFieldNotInGroupBy.GenWithStackByArgs(errExprLoc.Offset+1, errExprLoc.Loc, sel.OrderBy.Items[errExprLoc.Offset].Expr.Text()) } return nil } @@ -1453,7 +1453,7 @@ func (c *colResolverForOnlyFullGroupBy) Leave(node ast.Node) (ast.Node, bool) { func (c *colResolverForOnlyFullGroupBy) Check() error { if c.hasAggFunc && c.firstNonAggCol != nil { - return ErrMixOfGroupFuncAndFields.GenByArgs(c.firstNonAggColIdx+1, c.firstNonAggCol.Name.O) + return ErrMixOfGroupFuncAndFields.GenWithStackByArgs(c.firstNonAggColIdx+1, c.firstNonAggCol.Name.O) } return nil } @@ -1547,7 +1547,7 @@ func (b *planBuilder) unfoldWildStar(p LogicalPlan, selectFields []*ast.SelectFi } } if !findTblNameInSchema { - return nil, ErrBadTable.GenByArgs(tblName) + return nil, ErrBadTable.GenWithStackByArgs(tblName) } } return resultList, nil @@ -2085,7 +2085,7 @@ func (b *planBuilder) buildUpdateLists(tableList []*ast.TableName, list []*ast.A tableInfo := tn.TableInfo tableVal, found := b.is.TableByID(tableInfo.ID) if !found { - return nil, nil, infoschema.ErrTableNotExists.GenByArgs(tn.DBInfo.Name.O, tableInfo.Name.O) + return nil, nil, infoschema.ErrTableNotExists.GenWithStackByArgs(tn.DBInfo.Name.O, tableInfo.Name.O) } for i, colInfo := range tableInfo.Columns { if !colInfo.IsGenerated() { @@ -2093,7 +2093,7 @@ func (b *planBuilder) buildUpdateLists(tableList []*ast.TableName, list []*ast.A } columnFullName := fmt.Sprintf("%s.%s.%s", tn.Schema.L, tn.Name.L, colInfo.Name.L) if _, ok := modifyColumns[columnFullName]; ok { - return nil, nil, ErrBadGeneratedColumn.GenByArgs(colInfo.Name.O, tableInfo.Name.O) + return nil, nil, ErrBadGeneratedColumn.GenWithStackByArgs(colInfo.Name.O, tableInfo.Name.O) } for _, asName := range tableAsName[tableInfo] { virtualAssignments = append(virtualAssignments, &ast.Assignment{ @@ -2257,11 +2257,11 @@ func (b *planBuilder) buildDelete(delete *ast.DeleteStmt) (Plan, error) { } if asName == tblName { // check sql like: `delete a from (select * from t) as a, t` - return nil, ErrNonUpdatableTable.GenByArgs(tn.Name.O, "DELETE") + return nil, ErrNonUpdatableTable.GenWithStackByArgs(tn.Name.O, "DELETE") } } // check sql like: `delete b from (select * from t) as a, t` - return nil, ErrUnknownTable.GenByArgs(tn.Name.O, "MULTI DELETE") + return nil, ErrUnknownTable.GenWithStackByArgs(tn.Name.O, "MULTI DELETE") } b.visitInfo = appendVisitInfo(b.visitInfo, mysql.DeletePriv, tn.Schema.L, tn.TableInfo.Name.L, "") } diff --git a/plan/logical_plans.go b/plan/logical_plans.go index d742f86e9ba6a..e5bddebfc429c 100644 --- a/plan/logical_plans.go +++ b/plan/logical_plans.go @@ -16,7 +16,6 @@ package plan import ( "math" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/expression/aggregation" @@ -26,6 +25,7 @@ import ( "github.com/pingcap/tidb/table" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/ranger" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" ) diff --git a/plan/logical_plans_test.go b/plan/logical_plans_test.go index 9531e8c32a2eb..4a82b8050ac8e 100644 --- a/plan/logical_plans_test.go +++ b/plan/logical_plans_test.go @@ -16,7 +16,6 @@ package plan import ( "fmt" - "github.com/juju/errors" . "github.com/pingcap/check" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/expression" @@ -25,6 +24,7 @@ import ( "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/testleak" + "github.com/pkg/errors" "github.com/sirupsen/logrus" ) diff --git a/plan/optimizer.go b/plan/optimizer.go index 456d5c6dcf843..4a1c2b5b7b5b3 100644 --- a/plan/optimizer.go +++ b/plan/optimizer.go @@ -16,13 +16,13 @@ package plan import ( "math" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/infoschema" "github.com/pingcap/tidb/plan/property" "github.com/pingcap/tidb/privilege" "github.com/pingcap/tidb/sessionctx" + "github.com/pkg/errors" ) // AllowCartesianProduct means whether tidb allows cartesian join without equal conditions. @@ -169,7 +169,7 @@ func physicalOptimize(logic LogicalPlan) (PhysicalPlan, error) { return nil, errors.Trace(err) } if t.invalid() { - return nil, ErrInternal.GenByArgs("Can't find a proper physical plan for this query") + return nil, ErrInternal.GenWithStackByArgs("Can't find a proper physical plan for this query") } t.plan().ResolveIndices() diff --git a/plan/plan.go b/plan/plan.go index 0bb72c244cec7..028f78c622b1e 100644 --- a/plan/plan.go +++ b/plan/plan.go @@ -17,12 +17,12 @@ import ( "fmt" "math" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/plan/property" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tipb/go-tipb" + "github.com/pkg/errors" ) // Plan is the description of an execution flow. diff --git a/plan/plan_to_pb.go b/plan/plan_to_pb.go index 3b921c903c31a..ba0fa272dff9a 100644 --- a/plan/plan_to_pb.go +++ b/plan/plan_to_pb.go @@ -14,7 +14,6 @@ package plan import ( - "github.com/juju/errors" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/expression/aggregation" "github.com/pingcap/tidb/model" @@ -23,6 +22,7 @@ import ( "github.com/pingcap/tidb/tablecodec" "github.com/pingcap/tidb/util/ranger" "github.com/pingcap/tipb/go-tipb" + "github.com/pkg/errors" ) // ToPB implements PhysicalPlan ToPB interface. diff --git a/plan/planbuilder.go b/plan/planbuilder.go index 7f1f4ae3d42d6..4fdd79f61d8be 100644 --- a/plan/planbuilder.go +++ b/plan/planbuilder.go @@ -18,7 +18,6 @@ import ( "strings" "github.com/cznic/mathutil" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/infoschema" @@ -30,6 +29,7 @@ import ( "github.com/pingcap/tidb/table" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/ranger" + "github.com/pkg/errors" ) type visitInfo struct { @@ -174,7 +174,7 @@ func (b *planBuilder) build(node ast.Node) (Plan, error) { case ast.DDLNode: return b.buildDDL(x), nil } - return nil, ErrUnsupportedType.Gen("Unsupported type %T", node) + return nil, ErrUnsupportedType.GenWithStack("Unsupported type %T", node) } func (b *planBuilder) buildExecute(v *ast.ExecuteStmt) (Plan, error) { @@ -313,7 +313,7 @@ func getPossibleAccessPaths(indexHints []*ast.IndexHint, tblInfo *model.TableInf for _, idxName := range hint.IndexNames { path := getPathByIndexName(publicPaths, idxName, tblInfo) if path == nil { - return nil, ErrKeyDoesNotExist.GenByArgs(idxName, tblInfo.Name) + return nil, ErrKeyDoesNotExist.GenWithStackByArgs(idxName, tblInfo.Name) } if hint.HintType == ast.HintIgnore { // Collect all the ignored index hints. @@ -502,7 +502,7 @@ func (b *planBuilder) buildAdmin(as *ast.AdminStmt) (Plan, error) { p.SetSchema(buildShowDDLJobQueriesFields()) ret = p default: - return nil, ErrUnsupportedType.Gen("Unsupported ast.AdminStmt(%T) for buildAdmin", as) + return nil, ErrUnsupportedType.GenWithStack("Unsupported ast.AdminStmt(%T) for buildAdmin", as) } // Admin command can only be executed by administrator. @@ -520,7 +520,7 @@ func (b *planBuilder) buildAdminCheckTable(as *ast.AdminStmt) (*CheckTable, erro schema := expression.TableInfo2SchemaWithDBName(b.ctx, tbl.Schema, tableInfo) table, ok := b.is.TableByID(tableInfo.ID) if !ok { - return nil, infoschema.ErrTableNotExists.GenByArgs(tbl.DBInfo.Name.O, tableInfo.Name.O) + return nil, infoschema.ErrTableNotExists.GenWithStackByArgs(tbl.DBInfo.Name.O, tableInfo.Name.O) } mockTablePlan.SetSchema(schema) @@ -659,7 +659,7 @@ func (b *planBuilder) buildAnalyzeIndex(as *ast.AnalyzeTableStmt) (Plan, error) for _, idxName := range as.IndexNames { idx := findIndexByName(tblInfo.Indices, idxName) if idx == nil || idx.State != model.StatePublic { - return nil, ErrAnalyzeMissIndex.GenByArgs(idxName.O, tblInfo.Name.O) + return nil, ErrAnalyzeMissIndex.GenWithStackByArgs(idxName.O, tblInfo.Name.O) } for _, id := range physicalIDs { p.IdxTasks = append(p.IdxTasks, AnalyzeIndexTask{PhysicalTableID: id, IndexInfo: idx}) @@ -929,7 +929,7 @@ func (b *planBuilder) findDefaultValue(cols []*table.Column, name *ast.ColumnNam return b.getDefaultValue(col) } } - return nil, ErrUnknownColumn.GenByArgs(name.Name.O, "field_list") + return nil, ErrUnknownColumn.GenWithStackByArgs(name.Name.O, "field_list") } // resolveGeneratedColumns resolves generated columns with their generation @@ -972,11 +972,11 @@ func (b *planBuilder) resolveGeneratedColumns(columns []*table.Column, onDups ma func (b *planBuilder) buildInsert(insert *ast.InsertStmt) (Plan, error) { ts, ok := insert.Table.TableRefs.Left.(*ast.TableSource) if !ok { - return nil, infoschema.ErrTableNotExists.GenByArgs() + return nil, infoschema.ErrTableNotExists.GenWithStackByArgs() } tn, ok := ts.Source.(*ast.TableName) if !ok { - return nil, infoschema.ErrTableNotExists.GenByArgs() + return nil, infoschema.ErrTableNotExists.GenWithStackByArgs() } tableInfo := tn.TableInfo // Build Schema with DBName otherwise ColumnRef with DBName cannot match any Column in Schema. @@ -1075,13 +1075,13 @@ func (p *Insert) validateOnDup(onDup []*ast.Assignment, colMap map[string]*table if err != nil { return nil, nil, errors.Trace(err) } else if col == nil { - return nil, nil, ErrUnknownColumn.GenByArgs(assign.Column.OrigColName(), "field list") + return nil, nil, ErrUnknownColumn.GenWithStackByArgs(assign.Column.OrigColName(), "field list") } // Check whether the column to be updated is the generated column. column := colMap[assign.Column.Name.L] if column.IsGenerated() { - return nil, nil, ErrBadGeneratedColumn.GenByArgs(assign.Column.Name.O, tblInfo.Name.O) + return nil, nil, ErrBadGeneratedColumn.GenWithStackByArgs(assign.Column.Name.O, tblInfo.Name.O) } onDupColSet[column.Name.L] = struct{}{} dupCols = append(dupCols, col) @@ -1135,7 +1135,7 @@ func (b *planBuilder) buildSetValuesOfInsert(insert *ast.InsertStmt, insertPlan } for _, tCol := range tCols { if tCol.IsGenerated() { - return ErrBadGeneratedColumn.GenByArgs(tCol.Name.O, tableInfo.Name.O) + return ErrBadGeneratedColumn.GenWithStackByArgs(tCol.Name.O, tableInfo.Name.O) } } @@ -1164,12 +1164,12 @@ func (b *planBuilder) buildValuesListOfInsert(insert *ast.InsertStmt, insertPlan if len(insert.Columns) > 0 || len(insert.Lists[0]) > 0 { // If value_list or col_list is not empty, the length of value_list should be the same with that of col_list. if len(insert.Lists[0]) != len(affectedValuesCols) { - return ErrWrongValueCountOnRow.GenByArgs(1) + return ErrWrongValueCountOnRow.GenWithStackByArgs(1) } // No generated column is allowed. for _, col := range affectedValuesCols { if col.IsGenerated() { - return ErrBadGeneratedColumn.GenByArgs(col.Name.O, insertPlan.Table.Meta().Name.O) + return ErrBadGeneratedColumn.GenWithStackByArgs(col.Name.O, insertPlan.Table.Meta().Name.O) } } } @@ -1182,7 +1182,7 @@ func (b *planBuilder) buildValuesListOfInsert(insert *ast.InsertStmt, insertPlan // "insert into t values (1), ()" is not valid. // "insert into t values (1,2), (1)" is not valid. if i > 0 && len(insert.Lists[i-1]) != len(insert.Lists[i]) { - return ErrWrongValueCountOnRow.GenByArgs(i + 1) + return ErrWrongValueCountOnRow.GenWithStackByArgs(i + 1) } exprList := make([]expression.Expression, 0, len(valuesItem)) for j, valueItem := range valuesItem { @@ -1226,7 +1226,7 @@ func (b *planBuilder) buildSelectPlanOfInsert(insert *ast.InsertStmt, insertPlan // Check to guarantee that the length of the row returned by select is equal to that of affectedValuesCols. if selectPlan.Schema().Len() != len(affectedValuesCols) { - return ErrWrongValueCountOnRow.GenByArgs(1) + return ErrWrongValueCountOnRow.GenWithStackByArgs(1) } // Check to guarantee that there's no generated column. @@ -1238,7 +1238,7 @@ func (b *planBuilder) buildSelectPlanOfInsert(insert *ast.InsertStmt, insertPlan // that there's a generated column in the column list. for _, col := range affectedValuesCols { if col.IsGenerated() { - return ErrBadGeneratedColumn.GenByArgs(col.Name.O, insertPlan.Table.Meta().Name.O) + return ErrBadGeneratedColumn.GenWithStackByArgs(col.Name.O, insertPlan.Table.Meta().Name.O) } } @@ -1281,7 +1281,7 @@ func (b *planBuilder) buildLoadData(ld *ast.LoadDataStmt) (Plan, error) { tableInPlan, ok := b.is.TableByID(tableInfo.ID) if !ok { db := b.ctx.GetSessionVars().CurrentDB - return nil, infoschema.ErrTableNotExists.GenByArgs(db, tableInfo.Name.O) + return nil, infoschema.ErrTableNotExists.GenWithStackByArgs(db, tableInfo.Name.O) } schema := expression.TableInfo2Schema(b.ctx, tableInfo) mockTablePlan := LogicalTableDual{}.init(b.ctx) @@ -1416,7 +1416,7 @@ func (b *planBuilder) buildExplain(explain *ast.ExplainStmt) (Plan, error) { } } if pp == nil { - return nil, ErrUnsupportedType.GenByArgs(targetPlan) + return nil, ErrUnsupportedType.GenWithStackByArgs(targetPlan) } } p := &Explain{StmtPlan: pp} diff --git a/plan/point_get_plan.go b/plan/point_get_plan.go index ab31980c9b5af..21734c2e75584 100644 --- a/plan/point_get_plan.go +++ b/plan/point_get_plan.go @@ -17,7 +17,6 @@ import ( "bytes" "fmt" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/model" @@ -28,6 +27,7 @@ import ( "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/types" "github.com/pingcap/tipb/go-tipb" + "github.com/pkg/errors" ) // PointGetPlan is a fast plan for simple point get. diff --git a/plan/preprocess.go b/plan/preprocess.go index c31e38ee72e89..8c6baa6727df3 100644 --- a/plan/preprocess.go +++ b/plan/preprocess.go @@ -17,7 +17,6 @@ import ( "math" "strings" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/ddl" "github.com/pingcap/tidb/infoschema" @@ -27,6 +26,7 @@ import ( "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/charset" + "github.com/pkg/errors" ) // Preprocess resolves table names of the node, and checks some statements validation. @@ -97,7 +97,7 @@ func (p *preprocessor) Leave(in ast.Node) (out ast.Node, ok bool) { p.inCreateOrDropTable = false case *ast.ParamMarkerExpr: if !p.inPrepare { - p.err = parser.ErrSyntax.Gen("syntax error, unexpected '?'") + p.err = parser.ErrSyntax.GenWithStack("syntax error, unexpected '?'") return } case *ast.ExplainStmt: @@ -112,7 +112,7 @@ func (p *preprocessor) Leave(in ast.Node) (out ast.Node, ok bool) { } } if !valid { - p.err = ErrUnknownExplainFormat.GenByArgs(x.Format) + p.err = ErrUnknownExplainFormat.GenWithStackByArgs(x.Format) } case *ast.TableName: p.handleTableName(x) @@ -232,11 +232,11 @@ func (p *preprocessor) checkUnionSelectList(stmt *ast.UnionSelectList) { continue } if sel.Limit != nil { - p.err = ErrWrongUsage.GenByArgs("UNION", "LIMIT") + p.err = ErrWrongUsage.GenWithStackByArgs("UNION", "LIMIT") return } if sel.OrderBy != nil { - p.err = ErrWrongUsage.GenByArgs("UNION", "ORDER BY") + p.err = ErrWrongUsage.GenWithStackByArgs("UNION", "ORDER BY") return } } @@ -244,20 +244,20 @@ func (p *preprocessor) checkUnionSelectList(stmt *ast.UnionSelectList) { func (p *preprocessor) checkCreateDatabaseGrammar(stmt *ast.CreateDatabaseStmt) { if isIncorrectName(stmt.Name) { - p.err = ddl.ErrWrongDBName.GenByArgs(stmt.Name) + p.err = ddl.ErrWrongDBName.GenWithStackByArgs(stmt.Name) } } func (p *preprocessor) checkDropDatabaseGrammar(stmt *ast.DropDatabaseStmt) { if isIncorrectName(stmt.Name) { - p.err = ddl.ErrWrongDBName.GenByArgs(stmt.Name) + p.err = ddl.ErrWrongDBName.GenWithStackByArgs(stmt.Name) } } func (p *preprocessor) checkCreateTableGrammar(stmt *ast.CreateTableStmt) { tName := stmt.Table.Name.String() if isIncorrectName(tName) { - p.err = ddl.ErrWrongTableName.GenByArgs(tName) + p.err = ddl.ErrWrongTableName.GenWithStackByArgs(tName) return } countPrimaryKey := 0 @@ -306,7 +306,7 @@ func (p *preprocessor) checkCreateTableGrammar(stmt *ast.CreateTableStmt) { func (p *preprocessor) checkDropTableGrammar(stmt *ast.DropTableStmt) { for _, t := range stmt.Tables { if isIncorrectName(t.Name.String()) { - p.err = ddl.ErrWrongTableName.GenByArgs(t.Name.String()) + p.err = ddl.ErrWrongTableName.GenWithStackByArgs(t.Name.String()) return } } @@ -332,7 +332,7 @@ func isTableAliasDuplicate(node ast.ResultSetNode, tableAliases map[string]inter if ts, ok := node.(*ast.TableSource); ok { _, exists := tableAliases[ts.AsName.L] if len(ts.AsName.L) != 0 && exists { - return ErrNonUniqTable.GenByArgs(ts.AsName) + return ErrNonUniqTable.GenWithStackByArgs(ts.AsName) } tableAliases[ts.AsName.L] = nil } @@ -351,7 +351,7 @@ func isPrimary(ops []*ast.ColumnOption) int { func (p *preprocessor) checkCreateIndexGrammar(stmt *ast.CreateIndexStmt) { tName := stmt.Table.Name.String() if isIncorrectName(tName) { - p.err = ddl.ErrWrongTableName.GenByArgs(tName) + p.err = ddl.ErrWrongTableName.GenWithStackByArgs(tName) return } p.err = checkIndexInfo(stmt.IndexName, stmt.IndexColNames) @@ -362,12 +362,12 @@ func (p *preprocessor) checkRenameTableGrammar(stmt *ast.RenameTableStmt) { newTable := stmt.NewTable.Name.String() if isIncorrectName(oldTable) { - p.err = ddl.ErrWrongTableName.GenByArgs(oldTable) + p.err = ddl.ErrWrongTableName.GenWithStackByArgs(oldTable) return } if isIncorrectName(newTable) { - p.err = ddl.ErrWrongTableName.GenByArgs(newTable) + p.err = ddl.ErrWrongTableName.GenWithStackByArgs(newTable) return } } @@ -375,7 +375,7 @@ func (p *preprocessor) checkRenameTableGrammar(stmt *ast.RenameTableStmt) { func (p *preprocessor) checkAlterTableGrammar(stmt *ast.AlterTableStmt) { tName := stmt.Table.Name.String() if isIncorrectName(tName) { - p.err = ddl.ErrWrongTableName.GenByArgs(tName) + p.err = ddl.ErrWrongTableName.GenWithStackByArgs(tName) return } specs := stmt.Specs @@ -383,7 +383,7 @@ func (p *preprocessor) checkAlterTableGrammar(stmt *ast.AlterTableStmt) { if spec.NewTable != nil { ntName := spec.NewTable.Name.String() if isIncorrectName(ntName) { - p.err = ddl.ErrWrongTableName.GenByArgs(ntName) + p.err = ddl.ErrWrongTableName.GenWithStackByArgs(ntName) return } } @@ -416,7 +416,7 @@ func checkDuplicateColumnName(indexColNames []*ast.IndexColName) error { for _, indexColName := range indexColNames { name := indexColName.Column.Name if _, ok := colNames[name.L]; ok { - return infoschema.ErrColumnExists.GenByArgs(name) + return infoschema.ErrColumnExists.GenWithStackByArgs(name) } colNames[name.L] = struct{}{} } @@ -426,10 +426,10 @@ func checkDuplicateColumnName(indexColNames []*ast.IndexColName) error { // checkIndexInfo checks index name and index column names. func checkIndexInfo(indexName string, indexColNames []*ast.IndexColName) error { if strings.EqualFold(indexName, mysql.PrimaryKeyName) { - return ddl.ErrWrongNameForIndex.GenByArgs(indexName) + return ddl.ErrWrongNameForIndex.GenWithStackByArgs(indexName) } if len(indexColNames) > mysql.MaxKeyParts { - return infoschema.ErrTooManyKeyParts.GenByArgs(mysql.MaxKeyParts) + return infoschema.ErrTooManyKeyParts.GenWithStackByArgs(mysql.MaxKeyParts) } return checkDuplicateColumnName(indexColNames) } @@ -440,11 +440,11 @@ func checkColumn(colDef *ast.ColumnDef) error { // Check column name. cName := colDef.Name.Name.String() if isIncorrectName(cName) { - return ddl.ErrWrongColumnName.GenByArgs(cName) + return ddl.ErrWrongColumnName.GenWithStackByArgs(cName) } if isInvalidDefaultValue(colDef) { - return types.ErrInvalidDefault.GenByArgs(colDef.Name.Name.O) + return types.ErrInvalidDefault.GenWithStackByArgs(colDef.Name.Name.O) } // Check column type. @@ -453,13 +453,13 @@ func checkColumn(colDef *ast.ColumnDef) error { return nil } if tp.Flen > math.MaxUint32 { - return types.ErrTooBigDisplayWidth.Gen("Display width out of range for column '%s' (max = %d)", colDef.Name.Name.O, math.MaxUint32) + return types.ErrTooBigDisplayWidth.GenWithStack("Display width out of range for column '%s' (max = %d)", colDef.Name.Name.O, math.MaxUint32) } switch tp.Tp { case mysql.TypeString: if tp.Flen != types.UnspecifiedLength && tp.Flen > mysql.MaxFieldCharLength { - return types.ErrTooBigFieldLength.Gen("Column length too big for column '%s' (max = %d); use BLOB or TEXT instead", colDef.Name.Name.O, mysql.MaxFieldCharLength) + return types.ErrTooBigFieldLength.GenWithStack("Column length too big for column '%s' (max = %d); use BLOB or TEXT instead", colDef.Name.Name.O, mysql.MaxFieldCharLength) } case mysql.TypeVarchar: maxFlen := mysql.MaxFieldVarCharLength @@ -476,32 +476,32 @@ func checkColumn(colDef *ast.ColumnDef) error { } maxFlen /= desc.Maxlen if tp.Flen != types.UnspecifiedLength && tp.Flen > maxFlen { - return types.ErrTooBigFieldLength.Gen("Column length too big for column '%s' (max = %d); use BLOB or TEXT instead", colDef.Name.Name.O, maxFlen) + return types.ErrTooBigFieldLength.GenWithStack("Column length too big for column '%s' (max = %d); use BLOB or TEXT instead", colDef.Name.Name.O, maxFlen) } case mysql.TypeFloat, mysql.TypeDouble: if tp.Decimal > mysql.MaxFloatingTypeScale { - return types.ErrTooBigScale.GenByArgs(tp.Decimal, colDef.Name.Name.O, mysql.MaxFloatingTypeScale) + return types.ErrTooBigScale.GenWithStackByArgs(tp.Decimal, colDef.Name.Name.O, mysql.MaxFloatingTypeScale) } if tp.Flen > mysql.MaxFloatingTypeWidth { - return types.ErrTooBigPrecision.GenByArgs(tp.Flen, colDef.Name.Name.O, mysql.MaxFloatingTypeWidth) + return types.ErrTooBigPrecision.GenWithStackByArgs(tp.Flen, colDef.Name.Name.O, mysql.MaxFloatingTypeWidth) } case mysql.TypeSet: if len(tp.Elems) > mysql.MaxTypeSetMembers { - return types.ErrTooBigSet.Gen("Too many strings for column %s and SET", colDef.Name.Name.O) + return types.ErrTooBigSet.GenWithStack("Too many strings for column %s and SET", colDef.Name.Name.O) } // Check set elements. See https://dev.mysql.com/doc/refman/5.7/en/set.html . for _, str := range colDef.Tp.Elems { if strings.Contains(str, ",") { - return types.ErrIllegalValueForType.GenByArgs(types.TypeStr(tp.Tp), str) + return types.ErrIllegalValueForType.GenWithStackByArgs(types.TypeStr(tp.Tp), str) } } case mysql.TypeNewDecimal: if tp.Decimal > mysql.MaxDecimalScale { - return types.ErrTooBigScale.GenByArgs(tp.Decimal, colDef.Name.Name.O, mysql.MaxDecimalScale) + return types.ErrTooBigScale.GenWithStackByArgs(tp.Decimal, colDef.Name.Name.O, mysql.MaxDecimalScale) } if tp.Flen > mysql.MaxDecimalWidth { - return types.ErrTooBigPrecision.GenByArgs(tp.Flen, colDef.Name.Name.O, mysql.MaxDecimalWidth) + return types.ErrTooBigPrecision.GenWithStackByArgs(tp.Flen, colDef.Name.Name.O, mysql.MaxDecimalWidth) } default: // TODO: Add more types. @@ -557,11 +557,11 @@ func (p *preprocessor) checkContainDotColumn(stmt *ast.CreateTableStmt) { for _, colDef := range stmt.Cols { // check schema and table names. if colDef.Name.Schema.O != sName && len(colDef.Name.Schema.O) != 0 { - p.err = ddl.ErrWrongDBName.GenByArgs(colDef.Name.Schema.O) + p.err = ddl.ErrWrongDBName.GenWithStackByArgs(colDef.Name.Schema.O) return } if colDef.Name.Table.O != tName && len(colDef.Name.Table.O) != 0 { - p.err = ddl.ErrWrongTableName.GenByArgs(colDef.Name.Table.O) + p.err = ddl.ErrWrongTableName.GenWithStackByArgs(colDef.Name.Table.O) return } } diff --git a/plan/preprocess_test.go b/plan/preprocess_test.go index 2efa73eff3564..2dfb2c1eb3f66 100644 --- a/plan/preprocess_test.go +++ b/plan/preprocess_test.go @@ -14,7 +14,6 @@ package plan_test import ( - "github.com/juju/errors" . "github.com/pingcap/check" "github.com/pingcap/tidb/ddl" "github.com/pingcap/tidb/infoschema" @@ -26,6 +25,7 @@ import ( "github.com/pingcap/tidb/terror" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/testleak" + "github.com/pkg/errors" "golang.org/x/net/context" ) @@ -159,7 +159,7 @@ func (s *testValidatorSuite) TestValidator(c *C) { {"CREATE TABLE `t` (`a` varchar(10) DEFAULT now());", false, types.ErrInvalidDefault}, {"CREATE TABLE `t` (`a` double DEFAULT 1.0 DEFAULT now() DEFAULT 2.0 );", false, nil}, - {`explain format = "xx" select 100;`, false, plan.ErrUnknownExplainFormat.GenByArgs("xx")}, + {`explain format = "xx" select 100;`, false, plan.ErrUnknownExplainFormat.GenWithStackByArgs("xx")}, // issue 4472 {`select sum(distinct(if('a', (select adddate(elt(999, count(*)), interval 1 day)), .1))) as foo;`, true, nil}, diff --git a/plan/rule_decorrelate.go b/plan/rule_decorrelate.go index a56e30899a37b..9ea443146a67f 100644 --- a/plan/rule_decorrelate.go +++ b/plan/rule_decorrelate.go @@ -16,12 +16,12 @@ package plan import ( "math" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/expression/aggregation" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/types" + "github.com/pkg/errors" ) // extractCorColumnsBySchema only extracts the correlated columns that match the outer plan's schema. diff --git a/plan/rule_partition_processor.go b/plan/rule_partition_processor.go index ab37b28cc0e5e..48432e767d42d 100644 --- a/plan/rule_partition_processor.go +++ b/plan/rule_partition_processor.go @@ -13,11 +13,11 @@ package plan import ( - "github.com/juju/errors" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/table/tables" "github.com/pingcap/tidb/util/ranger" + "github.com/pkg/errors" ) // partitionProcessor rewrites the ast for table partition. diff --git a/plan/stats.go b/plan/stats.go index 53f2cf8c40f88..3e270e02047d5 100644 --- a/plan/stats.go +++ b/plan/stats.go @@ -16,9 +16,9 @@ package plan import ( "math" - "github.com/juju/errors" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/plan/property" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" ) diff --git a/privilege/privileges/cache.go b/privilege/privileges/cache.go index d00dc99bb076c..100e86efba061 100644 --- a/privilege/privileges/cache.go +++ b/privilege/privileges/cache.go @@ -20,7 +20,6 @@ import ( "sync/atomic" "time" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/sessionctx" @@ -29,6 +28,7 @@ import ( "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/sqlexec" "github.com/pingcap/tidb/util/stringutil" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" ) @@ -316,7 +316,7 @@ func (p *MySQLPrivilege) decodeUserTableRow(row chunk.Row, fs []*ast.ResultField } priv, ok := mysql.Col2PrivType[f.ColumnAsName.O] if !ok { - return errInvalidPrivilegeType.Gen("Unknown Privilege Type!") + return errInvalidPrivilegeType.GenWithStack("Unknown Privilege Type!") } value.Privileges |= priv } @@ -343,7 +343,7 @@ func (p *MySQLPrivilege) decodeDBTableRow(row chunk.Row, fs []*ast.ResultField) } priv, ok := mysql.Col2PrivType[f.ColumnAsName.O] if !ok { - return errInvalidPrivilegeType.Gen("Unknown Privilege Type!") + return errInvalidPrivilegeType.GenWithStack("Unknown Privilege Type!") } value.Privileges |= priv } diff --git a/server/conn.go b/server/conn.go index 21c74d0587886..2275f7170897f 100644 --- a/server/conn.go +++ b/server/conn.go @@ -48,7 +48,6 @@ import ( "sync/atomic" "time" - "github.com/juju/errors" "github.com/opentracing/opentracing-go" "github.com/pingcap/tidb/executor" "github.com/pingcap/tidb/kv" @@ -61,6 +60,7 @@ import ( "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/hack" "github.com/pingcap/tidb/util/memory" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" ) @@ -396,10 +396,10 @@ func (cc *clientConn) openSessionAndDoAuth(authData []byte) error { addr := cc.bufReadConn.RemoteAddr().String() host, _, err1 := net.SplitHostPort(addr) if err1 != nil { - return errors.Trace(errAccessDenied.GenByArgs(cc.user, addr, "YES")) + return errors.Trace(errAccessDenied.GenWithStackByArgs(cc.user, addr, "YES")) } if !cc.ctx.Auth(&auth.UserIdentity{Username: cc.user, Hostname: host}, authData, cc.salt) { - return errors.Trace(errAccessDenied.GenByArgs(cc.user, host, "YES")) + return errors.Trace(errAccessDenied.GenWithStackByArgs(cc.user, host, "YES")) } } if cc.dbname != "" { diff --git a/server/conn_stmt.go b/server/conn_stmt.go index 71e97ba0e0d15..4bb163d5e5076 100644 --- a/server/conn_stmt.go +++ b/server/conn_stmt.go @@ -40,10 +40,10 @@ import ( "math" "strconv" - "github.com/juju/errors" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/hack" + "github.com/pkg/errors" "golang.org/x/net/context" ) @@ -432,7 +432,7 @@ func parseStmtArgs(args []interface{}, boundParams [][]byte, nullBitmap, paramTy } continue default: - err = errUnknownFieldType.Gen("stmt unknown field type %d", tp) + err = errUnknownFieldType.GenWithStack("stmt unknown field type %d", tp) return } } diff --git a/server/driver_tidb.go b/server/driver_tidb.go index 9405f8eadae2a..6a583bd357c6f 100644 --- a/server/driver_tidb.go +++ b/server/driver_tidb.go @@ -17,7 +17,6 @@ import ( "crypto/tls" "fmt" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/mysql" @@ -27,6 +26,7 @@ import ( "github.com/pingcap/tidb/util" "github.com/pingcap/tidb/util/auth" "github.com/pingcap/tidb/util/chunk" + "github.com/pkg/errors" "golang.org/x/net/context" ) diff --git a/server/http_handler.go b/server/http_handler.go index 2636666da5caa..5fdebb28d1062 100644 --- a/server/http_handler.go +++ b/server/http_handler.go @@ -28,7 +28,6 @@ import ( "time" "github.com/gorilla/mux" - "github.com/juju/errors" "github.com/pingcap/kvproto/pkg/kvrpcpb" "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/tidb/config" @@ -49,6 +48,7 @@ import ( "github.com/pingcap/tidb/terror" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/codec" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" ) @@ -619,7 +619,7 @@ func (h schemaHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { writeData(w, tbsInfo) return } - writeError(w, infoschema.ErrDatabaseNotExists.GenByArgs(dbName)) + writeError(w, infoschema.ErrDatabaseNotExists.GenWithStackByArgs(dbName)) return } @@ -631,14 +631,14 @@ func (h schemaHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } if tid < 0 { - writeError(w, infoschema.ErrTableNotExists.Gen("Table which ID = %s does not exist.", tableID)) + writeError(w, infoschema.ErrTableNotExists.GenWithStack("Table which ID = %s does not exist.", tableID)) return } if data, ok := schema.TableByID(int64(tid)); ok { writeData(w, data.Meta()) return } - writeError(w, infoschema.ErrTableNotExists.Gen("Table which ID = %s does not exist.", tableID)) + writeError(w, infoschema.ErrTableNotExists.GenWithStack("Table which ID = %s does not exist.", tableID)) return } diff --git a/server/http_status.go b/server/http_status.go index 0b6a35d609efb..1d9789b6dc423 100644 --- a/server/http_status.go +++ b/server/http_status.go @@ -20,11 +20,11 @@ import ( "net/http/pprof" "github.com/gorilla/mux" - "github.com/juju/errors" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/terror" "github.com/pingcap/tidb/util/printer" + "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" log "github.com/sirupsen/logrus" ) diff --git a/server/packetio.go b/server/packetio.go index a88ebcc7e3d9a..ae16f5d143063 100644 --- a/server/packetio.go +++ b/server/packetio.go @@ -38,9 +38,9 @@ import ( "bufio" "io" - "github.com/juju/errors" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/terror" + "github.com/pkg/errors" ) const defaultWriterSize = 16 * 1024 @@ -72,7 +72,7 @@ func (p *packetIO) readOnePacket() ([]byte, error) { sequence := header[3] if sequence != p.sequence { - return nil, errInvalidSequence.Gen("invalid sequence %d != %d", sequence, p.sequence) + return nil, errInvalidSequence.GenWithStack("invalid sequence %d != %d", sequence, p.sequence) } p.sequence++ diff --git a/server/server.go b/server/server.go index 4512a60bc20be..9b8e0ecd10d48 100644 --- a/server/server.go +++ b/server/server.go @@ -43,13 +43,13 @@ import ( "time" "github.com/blacktear23/go-proxyprotocol" - "github.com/juju/errors" "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/metrics" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/sessionctx/variable" "github.com/pingcap/tidb/terror" "github.com/pingcap/tidb/util" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" ) diff --git a/server/tidb_test.go b/server/tidb_test.go index 8775073904463..db9c56cd77541 100644 --- a/server/tidb_test.go +++ b/server/tidb_test.go @@ -27,7 +27,6 @@ import ( "time" "github.com/go-sql-driver/mysql" - "github.com/juju/errors" . "github.com/pingcap/check" "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/domain" @@ -36,6 +35,7 @@ import ( tmysql "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/session" "github.com/pingcap/tidb/store/mockstore" + "github.com/pkg/errors" "golang.org/x/net/context" ) diff --git a/server/util.go b/server/util.go index 6a38f10281b82..352fc9e75c12e 100644 --- a/server/util.go +++ b/server/util.go @@ -42,11 +42,11 @@ import ( "strconv" "time" - "github.com/juju/errors" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/hack" + "github.com/pkg/errors" ) func parseNullTermString(b []byte) (str []byte, remain []byte) { @@ -271,7 +271,7 @@ func dumpBinaryRow(buffer []byte, columns []*ColumnInfo, row chunk.Row) ([]byte, case mysql.TypeJSON: buffer = dumpLengthEncodedString(buffer, hack.Slice(row.GetJSON(i).String())) default: - return nil, errInvalidType.Gen("invalid type %v", columns[i].Type) + return nil, errInvalidType.GenWithStack("invalid type %v", columns[i].Type) } } return buffer, nil @@ -326,7 +326,7 @@ func dumpTextRow(buffer []byte, columns []*ColumnInfo, row chunk.Row) ([]byte, e case mysql.TypeJSON: buffer = dumpLengthEncodedString(buffer, hack.Slice(row.GetJSON(i).String())) default: - return nil, errInvalidType.Gen("invalid type %v", columns[i].Type) + return nil, errInvalidType.GenWithStack("invalid type %v", columns[i].Type) } } return buffer, nil diff --git a/server/util_test.go b/server/util_test.go index 3f0505045f29d..2ddd55fe70e66 100644 --- a/server/util_test.go +++ b/server/util_test.go @@ -14,7 +14,6 @@ package server import ( - "github.com/juju/errors" . "github.com/pingcap/check" "github.com/pingcap/tidb/domain" "github.com/pingcap/tidb/kv" @@ -24,6 +23,7 @@ import ( "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/testleak" + "github.com/pkg/errors" ) var _ = Suite(&testUtilSuite{}) diff --git a/session/bootstrap.go b/session/bootstrap.go index c4298907d66b3..dfa65909e98ae 100644 --- a/session/bootstrap.go +++ b/session/bootstrap.go @@ -25,7 +25,6 @@ import ( "strings" "time" - "github.com/juju/errors" "github.com/pingcap/tidb/ddl" "github.com/pingcap/tidb/infoschema" "github.com/pingcap/tidb/mysql" @@ -33,6 +32,7 @@ import ( "github.com/pingcap/tidb/terror" "github.com/pingcap/tidb/util/auth" "github.com/pingcap/tidb/util/chunk" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" ) diff --git a/session/session.go b/session/session.go index 9f5e662edcfdf..4c47455187439 100644 --- a/session/session.go +++ b/session/session.go @@ -27,7 +27,6 @@ import ( "sync/atomic" "time" - "github.com/juju/errors" "github.com/ngaut/pools" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/domain" @@ -55,6 +54,7 @@ import ( "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/kvcache" binlog "github.com/pingcap/tipb/go-binlog" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" ) @@ -442,7 +442,7 @@ func (s *session) isRetryableError(err error) bool { func (s *session) retry(ctx context.Context, maxCnt uint) error { connID := s.sessionVars.ConnectionID if s.sessionVars.TxnCtx.ForUpdate { - return errForUpdateCantRetry.GenByArgs(connID) + return errForUpdateCantRetry.GenWithStackByArgs(connID) } s.sessionVars.RetryInfo.Retrying = true var retryCnt uint @@ -669,7 +669,7 @@ func (s *session) GetGlobalSysVar(name string) (string, error) { if sv, ok := variable.SysVars[name]; ok { return sv.Value, nil } - return "", variable.UnknownSystemVar.GenByArgs(name) + return "", variable.UnknownSystemVar.GenWithStackByArgs(name) } return "", errors.Trace(err) } diff --git a/session/tidb.go b/session/tidb.go index 0a50470813ab3..26ed871736e73 100644 --- a/session/tidb.go +++ b/session/tidb.go @@ -23,7 +23,6 @@ import ( "sync" "time" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/domain" @@ -35,6 +34,7 @@ import ( "github.com/pingcap/tidb/terror" "github.com/pingcap/tidb/util" "github.com/pingcap/tidb/util/chunk" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" "google.golang.org/grpc" diff --git a/session/tidb_test.go b/session/tidb_test.go index 776a4884daeba..1821351008d94 100644 --- a/session/tidb_test.go +++ b/session/tidb_test.go @@ -21,7 +21,6 @@ import ( "testing" "time" - "github.com/juju/errors" . "github.com/pingcap/check" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/domain" @@ -32,6 +31,7 @@ import ( "github.com/pingcap/tidb/util/auth" "github.com/pingcap/tidb/util/logutil" "github.com/pingcap/tidb/util/testleak" + "github.com/pkg/errors" "golang.org/x/net/context" "google.golang.org/grpc" ) diff --git a/session/txn.go b/session/txn.go index 575596b09eb89..5b37b63ad29f3 100644 --- a/session/txn.go +++ b/session/txn.go @@ -14,7 +14,6 @@ package session import ( - "github.com/juju/errors" "github.com/pingcap/tidb/executor" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/sessionctx" @@ -23,6 +22,7 @@ import ( "github.com/pingcap/tidb/table" "github.com/pingcap/tidb/types" binlog "github.com/pingcap/tipb/go-binlog" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" ) diff --git a/sessionctx/binloginfo/binloginfo.go b/sessionctx/binloginfo/binloginfo.go index e83b0f5ed0ae5..acd9ae82dc8d4 100644 --- a/sessionctx/binloginfo/binloginfo.go +++ b/sessionctx/binloginfo/binloginfo.go @@ -20,12 +20,12 @@ import ( "sync/atomic" "time" - "github.com/juju/errors" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/metrics" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/terror" binlog "github.com/pingcap/tipb/go-binlog" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" "google.golang.org/grpc" @@ -147,7 +147,7 @@ func (info *BinlogInfo) WriteBinlog(clusterID uint64) error { } } - return terror.ErrCritical.GenByArgs(err) + return terror.ErrCritical.GenWithStackByArgs(err) } // SetDDLBinlog sets DDL binlog in the kv.Transaction. diff --git a/sessionctx/binloginfo/binloginfo_test.go b/sessionctx/binloginfo/binloginfo_test.go index dee95184983e5..8650a9afb1ede 100644 --- a/sessionctx/binloginfo/binloginfo_test.go +++ b/sessionctx/binloginfo/binloginfo_test.go @@ -21,7 +21,6 @@ import ( "testing" "time" - "github.com/juju/errors" . "github.com/pingcap/check" "github.com/pingcap/tidb/ddl" "github.com/pingcap/tidb/domain" @@ -36,6 +35,7 @@ import ( "github.com/pingcap/tidb/util/logutil" "github.com/pingcap/tidb/util/testkit" binlog "github.com/pingcap/tipb/go-binlog" + "github.com/pkg/errors" "golang.org/x/net/context" "google.golang.org/grpc" ) diff --git a/sessionctx/variable/session.go b/sessionctx/variable/session.go index f8c6e1183c43b..b0454332fe625 100644 --- a/sessionctx/variable/session.go +++ b/sessionctx/variable/session.go @@ -20,7 +20,6 @@ import ( "sync/atomic" "time" - "github.com/juju/errors" "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/meta/autoid" @@ -30,6 +29,7 @@ import ( "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/auth" "github.com/pingcap/tidb/util/chunk" + "github.com/pkg/errors" ) const ( diff --git a/sessionctx/variable/statusvar.go b/sessionctx/variable/statusvar.go index 9052dfe3d2a4c..f7d6f1a65c21f 100644 --- a/sessionctx/variable/statusvar.go +++ b/sessionctx/variable/statusvar.go @@ -17,7 +17,7 @@ import ( "bytes" "crypto/tls" - "github.com/juju/errors" + "github.com/pkg/errors" ) var statisticsList []Statistics diff --git a/sessionctx/variable/varsutil.go b/sessionctx/variable/varsutil.go index 3722e9a5ad523..176e99ebacaa2 100644 --- a/sessionctx/variable/varsutil.go +++ b/sessionctx/variable/varsutil.go @@ -22,10 +22,10 @@ import ( "sync/atomic" "time" - "github.com/juju/errors" "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/types" + "github.com/pkg/errors" ) // secondsPerYear represents seconds in a normal year. Leap year is not considered here. @@ -67,7 +67,7 @@ func GetSessionSystemVar(s *SessionVars, key string) (string, error) { func GetSessionOnlySysVars(s *SessionVars, key string) (string, bool, error) { sysVar := SysVars[key] if sysVar == nil { - return "", false, UnknownSystemVar.GenByArgs(key) + return "", false, UnknownSystemVar.GenWithStackByArgs(key) } // For virtual system variables: switch sysVar.Name { @@ -113,7 +113,7 @@ func GetGlobalSystemVar(s *SessionVars, key string) (string, error) { func GetScopeNoneSystemVar(key string) (string, bool, error) { sysVar := SysVars[key] if sysVar == nil { - return "", false, UnknownSystemVar.GenByArgs(key) + return "", false, UnknownSystemVar.GenWithStackByArgs(key) } if sysVar.Scope == ScopeNone { return sysVar.Value, true, nil @@ -150,16 +150,16 @@ func SetSessionSystemVar(vars *SessionVars, name string, value types.Datum) erro func ValidateGetSystemVar(name string, isGlobal bool) error { sysVar, exists := SysVars[name] if !exists { - return UnknownSystemVar.GenByArgs(name) + return UnknownSystemVar.GenWithStackByArgs(name) } switch sysVar.Scope { case ScopeGlobal, ScopeNone: if !isGlobal { - return ErrIncorrectScope.GenByArgs(name, "GLOBAL") + return ErrIncorrectScope.GenWithStackByArgs(name, "GLOBAL") } case ScopeSession: if isGlobal { - return ErrIncorrectScope.GenByArgs(name, "SESSION") + return ErrIncorrectScope.GenWithStackByArgs(name, "SESSION") } } return nil @@ -169,21 +169,21 @@ func checkUInt64SystemVar(name, value string, min, max uint64, vars *SessionVars if value[0] == '-' { _, err := strconv.ParseInt(value, 10, 64) if err != nil { - return value, ErrWrongTypeForVar.GenByArgs(name) + return value, ErrWrongTypeForVar.GenWithStackByArgs(name) } - vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.GenByArgs(name, value)) + vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.GenWithStackByArgs(name, value)) return fmt.Sprintf("%d", min), nil } val, err := strconv.ParseUint(value, 10, 64) if err != nil { - return value, ErrWrongTypeForVar.GenByArgs(name) + return value, ErrWrongTypeForVar.GenWithStackByArgs(name) } if val < min { - vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.GenByArgs(name, value)) + vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.GenWithStackByArgs(name, value)) return fmt.Sprintf("%d", min), nil } if val > max { - vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.GenByArgs(name, value)) + vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.GenWithStackByArgs(name, value)) return fmt.Sprintf("%d", max), nil } return value, nil @@ -192,14 +192,14 @@ func checkUInt64SystemVar(name, value string, min, max uint64, vars *SessionVars func checkInt64SystemVar(name, value string, min, max int64, vars *SessionVars) (string, error) { val, err := strconv.ParseInt(value, 10, 64) if err != nil { - return value, ErrWrongTypeForVar.GenByArgs(name) + return value, ErrWrongTypeForVar.GenWithStackByArgs(name) } if val < min { - vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.GenByArgs(name, value)) + vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.GenWithStackByArgs(name, value)) return fmt.Sprintf("%d", min), nil } if val > max { - vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.GenByArgs(name, value)) + vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.GenWithStackByArgs(name, value)) return fmt.Sprintf("%d", max), nil } return value, nil @@ -211,7 +211,7 @@ func ValidateSetSystemVar(vars *SessionVars, name string, value string) (string, if val := GetSysVar(name); val != nil { return val.Value, nil } - return value, UnknownSystemVar.GenByArgs(name) + return value, UnknownSystemVar.GenWithStackByArgs(name) } switch name { case ConnectTimeout: @@ -226,7 +226,7 @@ func ValidateSetSystemVar(vars *SessionVars, name string, value string) (string, } else if strings.EqualFold(value, "ALL") || value == "2" { return "ALL", nil } - return value, ErrWrongValueForVar.GenByArgs(name, value) + return value, ErrWrongValueForVar.GenWithStackByArgs(name, value) case FlushTime: return checkUInt64SystemVar(name, value, 0, secondsPerYear, vars) case GroupConcatMaxLen: @@ -255,7 +255,7 @@ func ValidateSetSystemVar(vars *SessionVars, name string, value string) (string, } else if strings.EqualFold(value, "ALL_GTIDS") || value == "2" { return "ALL_GTIDS", nil } - return value, ErrWrongValueForVar.GenByArgs(name, value) + return value, ErrWrongValueForVar.GenWithStackByArgs(name, value) case SQLSelectLimit: return checkUInt64SystemVar(name, value, 0, math.MaxUint64, vars) case TableDefinitionCache: @@ -268,7 +268,7 @@ func ValidateSetSystemVar(vars *SessionVars, name string, value string) (string, } return value, nil case WarningCount, ErrorCount: - return value, ErrReadOnly.GenByArgs(name) + return value, ErrReadOnly.GenWithStackByArgs(name) case GeneralLog, TiDBGeneralLog, AvoidTemporalUpgrade, BigTables, CheckProxyUsers, CoreFile, EndMakersInJSON, SQLLogBin, OfflineMode, PseudoSlaveMode, LowPriorityUpdates, SkipNameResolve, ForeignKeyChecks, SQLSafeUpdates: if strings.EqualFold(value, "ON") || value == "1" { @@ -276,7 +276,7 @@ func ValidateSetSystemVar(vars *SessionVars, name string, value string) (string, } else if strings.EqualFold(value, "OFF") || value == "0" { return "0", nil } - return value, ErrWrongValueForVar.GenByArgs(name, value) + return value, ErrWrongValueForVar.GenWithStackByArgs(name, value) case AutocommitVar, TiDBSkipUTF8Check, TiDBOptAggPushDown, TiDBOptInSubqUnFolding, TiDBEnableTablePartition, TiDBBatchInsert, TiDBDisableTxnAutoRetry, TiDBEnableStreaming, @@ -284,7 +284,7 @@ func ValidateSetSystemVar(vars *SessionVars, name string, value string) (string, if strings.EqualFold(value, "ON") || value == "1" || strings.EqualFold(value, "OFF") || value == "0" { return value, nil } - return value, ErrWrongValueForVar.GenByArgs(name, value) + return value, ErrWrongValueForVar.GenWithStackByArgs(name, value) case TiDBIndexLookupConcurrency, TiDBIndexLookupJoinConcurrency, TiDBIndexJoinBatchSize, TiDBIndexLookupSize, TiDBHashJoinConcurrency, @@ -296,10 +296,10 @@ func ValidateSetSystemVar(vars *SessionVars, name string, value string) (string, TiDBDMLBatchSize, TiDBOptimizerSelectivityLevel: v, err := strconv.Atoi(value) if err != nil { - return value, ErrWrongTypeForVar.GenByArgs(name) + return value, ErrWrongTypeForVar.GenWithStackByArgs(name) } if v <= 0 { - return value, ErrWrongValueForVar.GenByArgs(name, value) + return value, ErrWrongValueForVar.GenWithStackByArgs(name, value) } return value, nil case TiDBProjectionConcurrency, @@ -314,7 +314,7 @@ func ValidateSetSystemVar(vars *SessionVars, name string, value string) (string, TiDBRetryLimit: _, err := strconv.ParseInt(value, 10, 64) if err != nil { - return value, ErrWrongValueForVar.GenByArgs(name) + return value, ErrWrongValueForVar.GenWithStackByArgs(name) } return value, nil case TiDBAutoAnalyzeStartTime, TiDBAutoAnalyzeEndTime: @@ -371,7 +371,7 @@ func parseTimeZone(s string) (*time.Location, error) { } } - return nil, ErrUnknownTimeZone.GenByArgs(s) + return nil, ErrUnknownTimeZone.GenWithStackByArgs(s) } func setSnapshotTS(s *SessionVars, sVal string) error { diff --git a/statistics/bootstrap.go b/statistics/bootstrap.go index 726c44bf2fe4d..850ad1a043a71 100644 --- a/statistics/bootstrap.go +++ b/statistics/bootstrap.go @@ -16,7 +16,6 @@ package statistics import ( "fmt" - "github.com/juju/errors" "github.com/pingcap/tidb/infoschema" "github.com/pingcap/tidb/model" "github.com/pingcap/tidb/mysql" @@ -25,6 +24,7 @@ import ( "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/sqlexec" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" ) diff --git a/statistics/builder.go b/statistics/builder.go index 952a47628692f..616716693e59a 100644 --- a/statistics/builder.go +++ b/statistics/builder.go @@ -14,10 +14,10 @@ package statistics import ( - "github.com/juju/errors" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/sessionctx/stmtctx" "github.com/pingcap/tidb/types" + "github.com/pkg/errors" ) // SortedBuilder is used to build histograms for PK and index. diff --git a/statistics/cmsketch.go b/statistics/cmsketch.go index 790eae2323693..6d16ad1546f89 100644 --- a/statistics/cmsketch.go +++ b/statistics/cmsketch.go @@ -18,11 +18,11 @@ import ( "sort" "github.com/cznic/sortutil" - "github.com/juju/errors" "github.com/pingcap/tidb/sessionctx/stmtctx" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/codec" "github.com/pingcap/tipb/go-tipb" + "github.com/pkg/errors" "github.com/spaolacci/murmur3" ) diff --git a/statistics/cmsketch_test.go b/statistics/cmsketch_test.go index 7a644e74c00e1..2ad7a9868d86a 100644 --- a/statistics/cmsketch_test.go +++ b/statistics/cmsketch_test.go @@ -18,11 +18,11 @@ import ( "math/rand" "time" - "github.com/juju/errors" . "github.com/pingcap/check" "github.com/pingcap/tidb/sessionctx/stmtctx" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/codec" + "github.com/pkg/errors" ) func (c *CMSketch) insert(val *types.Datum) error { diff --git a/statistics/ddl.go b/statistics/ddl.go index 9c6341fe223b9..acabf0fd71907 100644 --- a/statistics/ddl.go +++ b/statistics/ddl.go @@ -16,7 +16,6 @@ package statistics import ( "fmt" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/ddl/util" "github.com/pingcap/tidb/model" @@ -24,6 +23,7 @@ import ( "github.com/pingcap/tidb/terror" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/sqlexec" + "github.com/pkg/errors" "golang.org/x/net/context" ) diff --git a/statistics/dump.go b/statistics/dump.go index 7beff42041579..597473caf8d2f 100644 --- a/statistics/dump.go +++ b/statistics/dump.go @@ -16,13 +16,13 @@ package statistics import ( "time" - "github.com/juju/errors" "github.com/pingcap/tidb/infoschema" "github.com/pingcap/tidb/model" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/sessionctx/stmtctx" "github.com/pingcap/tidb/types" "github.com/pingcap/tipb/go-tipb" + "github.com/pkg/errors" ) // JSONTable is used for dumping statistics. diff --git a/statistics/feedback.go b/statistics/feedback.go index fce82dbb151d9..6d97ec54bd22b 100644 --- a/statistics/feedback.go +++ b/statistics/feedback.go @@ -23,7 +23,6 @@ import ( "time" "github.com/cznic/mathutil" - "github.com/juju/errors" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/metrics" "github.com/pingcap/tidb/mysql" @@ -33,6 +32,7 @@ import ( "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/codec" "github.com/pingcap/tidb/util/ranger" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "github.com/spaolacci/murmur3" ) diff --git a/statistics/fmsketch.go b/statistics/fmsketch.go index 72f1fbdbe3070..8878a21f8e863 100644 --- a/statistics/fmsketch.go +++ b/statistics/fmsketch.go @@ -16,11 +16,11 @@ package statistics import ( "hash" - "github.com/juju/errors" "github.com/pingcap/tidb/sessionctx/stmtctx" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/codec" "github.com/pingcap/tipb/go-tipb" + "github.com/pkg/errors" "github.com/spaolacci/murmur3" ) diff --git a/statistics/gc.go b/statistics/gc.go index 867bc0ceb3acf..75efc03c1558a 100644 --- a/statistics/gc.go +++ b/statistics/gc.go @@ -18,10 +18,10 @@ import ( "time" "github.com/cznic/mathutil" - "github.com/juju/errors" "github.com/pingcap/tidb/infoschema" "github.com/pingcap/tidb/store/tikv/oracle" "github.com/pingcap/tidb/util/sqlexec" + "github.com/pkg/errors" "golang.org/x/net/context" ) diff --git a/statistics/handle.go b/statistics/handle.go index c0ddaec4e0ea6..b014d863c97e5 100644 --- a/statistics/handle.go +++ b/statistics/handle.go @@ -19,7 +19,6 @@ import ( "sync/atomic" "time" - "github.com/juju/errors" "github.com/pingcap/tidb/ddl/util" "github.com/pingcap/tidb/infoschema" "github.com/pingcap/tidb/model" @@ -27,6 +26,7 @@ import ( "github.com/pingcap/tidb/store/tikv/oracle" "github.com/pingcap/tidb/table" "github.com/pingcap/tidb/util/sqlexec" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" ) diff --git a/statistics/handle_test.go b/statistics/handle_test.go index 3929ce7acffc8..07ab5f4decaba 100644 --- a/statistics/handle_test.go +++ b/statistics/handle_test.go @@ -17,7 +17,6 @@ import ( "fmt" "time" - "github.com/juju/errors" . "github.com/pingcap/check" "github.com/pingcap/tidb/domain" "github.com/pingcap/tidb/kv" @@ -30,6 +29,7 @@ import ( "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/testkit" "github.com/pingcap/tidb/util/testleak" + "github.com/pkg/errors" ) var _ = Suite(&testStatsCacheSuite{}) diff --git a/statistics/histogram.go b/statistics/histogram.go index 372a2ff8f96f7..a7730d07d975d 100644 --- a/statistics/histogram.go +++ b/statistics/histogram.go @@ -20,7 +20,6 @@ import ( "strings" "time" - "github.com/juju/errors" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/model" "github.com/pingcap/tidb/mysql" @@ -33,6 +32,7 @@ import ( "github.com/pingcap/tidb/util/ranger" "github.com/pingcap/tidb/util/sqlexec" "github.com/pingcap/tipb/go-tipb" + "github.com/pkg/errors" "golang.org/x/net/context" ) diff --git a/statistics/sample.go b/statistics/sample.go index bdbcdb75db4e9..6b841fab0bd30 100644 --- a/statistics/sample.go +++ b/statistics/sample.go @@ -17,13 +17,13 @@ import ( "fmt" "math/rand" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/sessionctx/stmtctx" "github.com/pingcap/tidb/terror" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tipb/go-tipb" + "github.com/pkg/errors" "golang.org/x/net/context" ) diff --git a/statistics/selectivity.go b/statistics/selectivity.go index a854a881b1fc4..ef474455d98ea 100644 --- a/statistics/selectivity.go +++ b/statistics/selectivity.go @@ -16,12 +16,12 @@ package statistics import ( "math" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/util/ranger" + "github.com/pkg/errors" ) // If one condition can't be calculated, we will assume that the selectivity of this condition is 0.8. diff --git a/statistics/statistics_test.go b/statistics/statistics_test.go index 5f8f805dce99c..d719edad22df9 100644 --- a/statistics/statistics_test.go +++ b/statistics/statistics_test.go @@ -18,7 +18,6 @@ import ( "testing" "time" - "github.com/juju/errors" . "github.com/pingcap/check" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/model" @@ -31,6 +30,7 @@ import ( "github.com/pingcap/tidb/util/codec" "github.com/pingcap/tidb/util/mock" "github.com/pingcap/tidb/util/ranger" + "github.com/pkg/errors" "golang.org/x/net/context" ) diff --git a/statistics/table.go b/statistics/table.go index 650893ec8266d..8e64a2ee87c94 100644 --- a/statistics/table.go +++ b/statistics/table.go @@ -19,7 +19,6 @@ import ( "strings" "sync" - "github.com/juju/errors" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/model" "github.com/pingcap/tidb/mysql" @@ -28,6 +27,7 @@ import ( "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/codec" "github.com/pingcap/tidb/util/ranger" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" ) diff --git a/statistics/update.go b/statistics/update.go index 81f5b5cd8e503..326be9bbc8508 100644 --- a/statistics/update.go +++ b/statistics/update.go @@ -21,7 +21,6 @@ import ( "sync" "time" - "github.com/juju/errors" "github.com/pingcap/tidb/infoschema" "github.com/pingcap/tidb/metrics" "github.com/pingcap/tidb/model" @@ -29,6 +28,7 @@ import ( "github.com/pingcap/tidb/store/tikv/oracle" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/sqlexec" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" ) diff --git a/store/mockoracle/oracle.go b/store/mockoracle/oracle.go index 84fddab6ae8d9..54933f0c10ef7 100644 --- a/store/mockoracle/oracle.go +++ b/store/mockoracle/oracle.go @@ -17,8 +17,8 @@ import ( "sync" "time" - "github.com/juju/errors" "github.com/pingcap/tidb/store/tikv/oracle" + "github.com/pkg/errors" "golang.org/x/net/context" ) diff --git a/store/mockstore/mocktikv/aggregate.go b/store/mockstore/mocktikv/aggregate.go index 75ade34b2930b..08dab065c6fb9 100644 --- a/store/mockstore/mocktikv/aggregate.go +++ b/store/mockstore/mocktikv/aggregate.go @@ -14,12 +14,12 @@ package mocktikv import ( - "github.com/juju/errors" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/expression/aggregation" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/codec" + "github.com/pkg/errors" "golang.org/x/net/context" ) diff --git a/store/mockstore/mocktikv/analyze.go b/store/mockstore/mocktikv/analyze.go index 4227a16081184..bbda6c3020b00 100644 --- a/store/mockstore/mocktikv/analyze.go +++ b/store/mockstore/mocktikv/analyze.go @@ -15,7 +15,6 @@ package mocktikv import ( "github.com/golang/protobuf/proto" - "github.com/juju/errors" "github.com/pingcap/kvproto/pkg/coprocessor" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/kv" @@ -27,6 +26,7 @@ import ( "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/codec" "github.com/pingcap/tipb/go-tipb" + "github.com/pkg/errors" "golang.org/x/net/context" ) diff --git a/store/mockstore/mocktikv/cop_handler_dag.go b/store/mockstore/mocktikv/cop_handler_dag.go index 456e1feb057b2..2f2af9687e03a 100644 --- a/store/mockstore/mocktikv/cop_handler_dag.go +++ b/store/mockstore/mocktikv/cop_handler_dag.go @@ -21,7 +21,6 @@ import ( "time" "github.com/golang/protobuf/proto" - "github.com/juju/errors" "github.com/pingcap/kvproto/pkg/coprocessor" "github.com/pingcap/kvproto/pkg/errorpb" "github.com/pingcap/kvproto/pkg/kvrpcpb" @@ -38,6 +37,7 @@ import ( "github.com/pingcap/tidb/util/codec" mockpkg "github.com/pingcap/tidb/util/mock" "github.com/pingcap/tipb/go-tipb" + "github.com/pkg/errors" "golang.org/x/net/context" "google.golang.org/grpc" "google.golang.org/grpc/metadata" diff --git a/store/mockstore/mocktikv/executor.go b/store/mockstore/mocktikv/executor.go index 75562e89c85f1..b3d78396fdf3e 100644 --- a/store/mockstore/mocktikv/executor.go +++ b/store/mockstore/mocktikv/executor.go @@ -18,7 +18,6 @@ import ( "encoding/binary" "sort" - "github.com/juju/errors" "github.com/pingcap/kvproto/pkg/kvrpcpb" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/kv" @@ -30,6 +29,7 @@ import ( "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/codec" "github.com/pingcap/tipb/go-tipb" + "github.com/pkg/errors" "golang.org/x/net/context" ) diff --git a/store/mockstore/mocktikv/mock.go b/store/mockstore/mocktikv/mock.go index e867368b19d45..0d43376a6883d 100644 --- a/store/mockstore/mocktikv/mock.go +++ b/store/mockstore/mocktikv/mock.go @@ -14,8 +14,8 @@ package mocktikv import ( - "github.com/juju/errors" "github.com/pingcap/pd/pd-client" + "github.com/pkg/errors" ) // NewTiKVAndPDClient creates a TiKV client and PD client from options. diff --git a/store/mockstore/mocktikv/mvcc.go b/store/mockstore/mocktikv/mvcc.go index a08045faaf796..28983d9656eee 100644 --- a/store/mockstore/mocktikv/mvcc.go +++ b/store/mockstore/mocktikv/mvcc.go @@ -21,9 +21,9 @@ import ( "sort" "github.com/google/btree" - "github.com/juju/errors" "github.com/pingcap/kvproto/pkg/kvrpcpb" "github.com/pingcap/tidb/util/codec" + "github.com/pkg/errors" ) type mvccValueType int diff --git a/store/mockstore/mocktikv/mvcc_leveldb.go b/store/mockstore/mocktikv/mvcc_leveldb.go index 2f43dcddecf7a..34abd116a3449 100644 --- a/store/mockstore/mocktikv/mvcc_leveldb.go +++ b/store/mockstore/mocktikv/mvcc_leveldb.go @@ -18,7 +18,6 @@ import ( "math" "sync" - "github.com/juju/errors" "github.com/pingcap/goleveldb/leveldb" "github.com/pingcap/goleveldb/leveldb/iterator" "github.com/pingcap/goleveldb/leveldb/opt" @@ -27,6 +26,7 @@ import ( "github.com/pingcap/kvproto/pkg/kvrpcpb" "github.com/pingcap/tidb/terror" "github.com/pingcap/tidb/util/codec" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" ) diff --git a/store/mockstore/mocktikv/rpc.go b/store/mockstore/mocktikv/rpc.go index 0877ca0cddd63..da6c638866fe8 100644 --- a/store/mockstore/mocktikv/rpc.go +++ b/store/mockstore/mocktikv/rpc.go @@ -20,7 +20,6 @@ import ( "time" "github.com/golang/protobuf/proto" - "github.com/juju/errors" "github.com/pingcap/kvproto/pkg/coprocessor" "github.com/pingcap/kvproto/pkg/errorpb" "github.com/pingcap/kvproto/pkg/kvrpcpb" @@ -28,6 +27,7 @@ import ( "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/store/tikv/tikvrpc" "github.com/pingcap/tidb/terror" + "github.com/pkg/errors" "golang.org/x/net/context" ) diff --git a/store/mockstore/mocktikv/topn.go b/store/mockstore/mocktikv/topn.go index 0cef7b9492158..b7a49110e429b 100644 --- a/store/mockstore/mocktikv/topn.go +++ b/store/mockstore/mocktikv/topn.go @@ -16,10 +16,10 @@ package mocktikv import ( "container/heap" - "github.com/juju/errors" "github.com/pingcap/tidb/sessionctx/stmtctx" "github.com/pingcap/tidb/types" "github.com/pingcap/tipb/go-tipb" + "github.com/pkg/errors" ) type sortRow struct { diff --git a/store/mockstore/tikv.go b/store/mockstore/tikv.go index 2ee11192becc6..796aa74e2ba58 100644 --- a/store/mockstore/tikv.go +++ b/store/mockstore/tikv.go @@ -17,12 +17,12 @@ import ( "net/url" "strings" - "github.com/juju/errors" "github.com/pingcap/pd/pd-client" "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/store/mockstore/mocktikv" "github.com/pingcap/tidb/store/tikv" + "github.com/pkg/errors" ) // MockDriver is in memory mock TiKV driver. diff --git a/store/tikv/2pc.go b/store/tikv/2pc.go index 086acb577b0fa..347490b64ebf1 100644 --- a/store/tikv/2pc.go +++ b/store/tikv/2pc.go @@ -20,7 +20,6 @@ import ( "sync/atomic" "time" - "github.com/juju/errors" pb "github.com/pingcap/kvproto/pkg/kvrpcpb" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/metrics" @@ -29,6 +28,7 @@ import ( "github.com/pingcap/tidb/tablecodec" "github.com/pingcap/tidb/terror" binlog "github.com/pingcap/tipb/go-binlog" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" ) @@ -621,7 +621,8 @@ func (c *twoPhaseCommitter) execute(ctx context.Context) error { if err != nil { if undeterminedErr := c.getUndeterminedErr(); undeterminedErr != nil { log.Warnf("con:%d 2PC commit result undetermined, err: %v, rpcErr: %v, tid: %v", c.connID, err, undeterminedErr, c.startTS) - err = errors.Wrap(err, terror.ErrResultUndetermined) + log.Error(err) + err = errors.Trace(terror.ErrResultUndetermined) } if !c.mu.committed { log.Debugf("con:%d 2PC failed on commit: %v, tid: %d", c.connID, err, c.startTS) diff --git a/store/tikv/2pc_fail_test.go b/store/tikv/2pc_fail_test.go index 63701dd1b5f9c..e840c94bed02b 100644 --- a/store/tikv/2pc_fail_test.go +++ b/store/tikv/2pc_fail_test.go @@ -15,9 +15,9 @@ package tikv import ( gofail "github.com/etcd-io/gofail/runtime" - "github.com/juju/errors" . "github.com/pingcap/check" "github.com/pingcap/tidb/terror" + "github.com/pkg/errors" "golang.org/x/net/context" ) diff --git a/store/tikv/2pc_test.go b/store/tikv/2pc_test.go index 7aa9bf5d6d9f7..724590523e0c8 100644 --- a/store/tikv/2pc_test.go +++ b/store/tikv/2pc_test.go @@ -19,11 +19,11 @@ import ( "strings" "time" - "github.com/juju/errors" . "github.com/pingcap/check" "github.com/pingcap/kvproto/pkg/kvrpcpb" "github.com/pingcap/tidb/store/mockstore/mocktikv" "github.com/pingcap/tidb/store/tikv/tikvrpc" + "github.com/pkg/errors" "golang.org/x/net/context" ) diff --git a/store/tikv/backoff.go b/store/tikv/backoff.go index 25847993b81c4..76b5e32ec6c22 100644 --- a/store/tikv/backoff.go +++ b/store/tikv/backoff.go @@ -20,11 +20,11 @@ import ( "strings" "time" - "github.com/juju/errors" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/metrics" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/terror" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" ) @@ -136,14 +136,14 @@ func (t backoffType) String() string { return "" } -func (t backoffType) TError() *terror.Error { +func (t backoffType) TError() error { switch t { case boTiKVRPC: return ErrTiKVServerTimeout case BoTxnLock, boTxnLockFast: return ErrResolveLockTimeout case boPDRPC: - return ErrPDServerTimeout.GenByArgs(txnRetryableMark) + return ErrPDServerTimeout.GenWithStackByArgs(txnRetryableMark) case BoRegionMiss, BoUpdateLeader: return ErrRegionUnavailable case boServerBusy: diff --git a/store/tikv/client.go b/store/tikv/client.go index 25818b60b8133..aa1a4fb5fece9 100644 --- a/store/tikv/client.go +++ b/store/tikv/client.go @@ -24,13 +24,13 @@ import ( "github.com/grpc-ecosystem/go-grpc-middleware" "github.com/grpc-ecosystem/go-grpc-middleware/tracing/opentracing" "github.com/grpc-ecosystem/go-grpc-prometheus" - "github.com/juju/errors" "github.com/pingcap/kvproto/pkg/coprocessor" "github.com/pingcap/kvproto/pkg/tikvpb" "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/metrics" "github.com/pingcap/tidb/store/tikv/tikvrpc" "github.com/pingcap/tidb/terror" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" "google.golang.org/grpc" diff --git a/store/tikv/coprocessor.go b/store/tikv/coprocessor.go index 1e9a6b8acf666..8db253229aa69 100644 --- a/store/tikv/coprocessor.go +++ b/store/tikv/coprocessor.go @@ -24,7 +24,6 @@ import ( "time" "github.com/cznic/mathutil" - "github.com/juju/errors" "github.com/pingcap/kvproto/pkg/coprocessor" "github.com/pingcap/kvproto/pkg/kvrpcpb" "github.com/pingcap/tidb/kv" @@ -32,6 +31,7 @@ import ( "github.com/pingcap/tidb/store/tikv/tikvrpc" "github.com/pingcap/tidb/util/execdetails" "github.com/pingcap/tipb/go-tipb" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" ) diff --git a/store/tikv/delete_range.go b/store/tikv/delete_range.go index 8db1dd3625cd0..521a6a8139f59 100644 --- a/store/tikv/delete_range.go +++ b/store/tikv/delete_range.go @@ -17,9 +17,9 @@ import ( "bytes" "context" - "github.com/juju/errors" "github.com/pingcap/kvproto/pkg/kvrpcpb" "github.com/pingcap/tidb/store/tikv/tikvrpc" + "github.com/pkg/errors" ) // DeleteRangeTask is used to delete all keys in a range. After diff --git a/store/tikv/error.go b/store/tikv/error.go index 467d346d146fc..9c78022c5fcae 100644 --- a/store/tikv/error.go +++ b/store/tikv/error.go @@ -14,9 +14,9 @@ package tikv import ( - "github.com/juju/errors" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/terror" + "github.com/pkg/errors" ) var ( diff --git a/store/tikv/gcworker/gc_worker.go b/store/tikv/gcworker/gc_worker.go index e35337b1b48f4..2739c00ed1c88 100644 --- a/store/tikv/gcworker/gc_worker.go +++ b/store/tikv/gcworker/gc_worker.go @@ -22,7 +22,6 @@ import ( "sync/atomic" "time" - "github.com/juju/errors" "github.com/pingcap/kvproto/pkg/errorpb" "github.com/pingcap/kvproto/pkg/kvrpcpb" "github.com/pingcap/tidb/ddl/util" @@ -36,6 +35,7 @@ import ( "github.com/pingcap/tidb/store/tikv/tikvrpc" "github.com/pingcap/tidb/terror" tidbutil "github.com/pingcap/tidb/util" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" ) diff --git a/store/tikv/kv.go b/store/tikv/kv.go index 8cc503da150cd..7f270cf62730a 100644 --- a/store/tikv/kv.go +++ b/store/tikv/kv.go @@ -24,7 +24,6 @@ import ( "github.com/coreos/etcd/clientv3" "github.com/grpc-ecosystem/go-grpc-prometheus" - "github.com/juju/errors" "github.com/pingcap/pd/pd-client" "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/kv" @@ -33,6 +32,7 @@ import ( "github.com/pingcap/tidb/store/tikv/oracle" "github.com/pingcap/tidb/store/tikv/oracle/oracles" "github.com/pingcap/tidb/store/tikv/tikvrpc" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" "google.golang.org/grpc" @@ -161,13 +161,13 @@ func (s *tikvStore) CheckVisibility(startTime uint64) error { diff := time.Since(cachedTime) if diff > (GcSafePointCacheInterval - gcCPUTimeInaccuracyBound) { - return ErrPDServerTimeout.GenByArgs("start timestamp may fall behind safe point") + return ErrPDServerTimeout.GenWithStackByArgs("start timestamp may fall behind safe point") } if startTime < cachedSafePoint { t1 := oracle.GetTimeFromTS(startTime) t2 := oracle.GetTimeFromTS(cachedSafePoint) - return ErrGCTooEarly.GenByArgs(t1, t2) + return ErrGCTooEarly.GenWithStackByArgs(t1, t2) } return nil diff --git a/store/tikv/lock_resolver.go b/store/tikv/lock_resolver.go index 68daded4baca2..ba8ab179b85c8 100644 --- a/store/tikv/lock_resolver.go +++ b/store/tikv/lock_resolver.go @@ -19,12 +19,12 @@ import ( "sync" "time" - "github.com/juju/errors" "github.com/pingcap/kvproto/pkg/kvrpcpb" "github.com/pingcap/pd/pd-client" "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/metrics" "github.com/pingcap/tidb/store/tikv/tikvrpc" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" ) diff --git a/store/tikv/oracle/oracles/pd.go b/store/tikv/oracle/oracles/pd.go index 8c78eaf930e69..d02748c3528ef 100644 --- a/store/tikv/oracle/oracles/pd.go +++ b/store/tikv/oracle/oracles/pd.go @@ -17,10 +17,10 @@ import ( "sync/atomic" "time" - "github.com/juju/errors" "github.com/pingcap/pd/pd-client" "github.com/pingcap/tidb/metrics" "github.com/pingcap/tidb/store/tikv/oracle" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" ) diff --git a/store/tikv/pd_codec.go b/store/tikv/pd_codec.go index 173678d2224af..e009a6c17e8d7 100644 --- a/store/tikv/pd_codec.go +++ b/store/tikv/pd_codec.go @@ -14,10 +14,10 @@ package tikv import ( - "github.com/juju/errors" "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/pd/pd-client" "github.com/pingcap/tidb/util/codec" + "github.com/pkg/errors" "golang.org/x/net/context" ) diff --git a/store/tikv/rawkv.go b/store/tikv/rawkv.go index cdaf29cc35a15..44eeef9cb95f1 100644 --- a/store/tikv/rawkv.go +++ b/store/tikv/rawkv.go @@ -17,12 +17,12 @@ import ( "bytes" "time" - "github.com/juju/errors" "github.com/pingcap/kvproto/pkg/kvrpcpb" "github.com/pingcap/pd/pd-client" "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/metrics" "github.com/pingcap/tidb/store/tikv/tikvrpc" + "github.com/pkg/errors" "golang.org/x/net/context" ) diff --git a/store/tikv/region_cache.go b/store/tikv/region_cache.go index 259a9aa3725fe..9bf21762a0622 100644 --- a/store/tikv/region_cache.go +++ b/store/tikv/region_cache.go @@ -20,11 +20,11 @@ import ( "time" "github.com/google/btree" - "github.com/juju/errors" "github.com/pingcap/kvproto/pkg/kvrpcpb" "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/pd/pd-client" "github.com/pingcap/tidb/metrics" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" ) diff --git a/store/tikv/region_request.go b/store/tikv/region_request.go index e9747bd5b3a9b..a599b56a9a831 100644 --- a/store/tikv/region_request.go +++ b/store/tikv/region_request.go @@ -16,12 +16,12 @@ package tikv import ( "time" - "github.com/juju/errors" "github.com/pingcap/kvproto/pkg/errorpb" "github.com/pingcap/kvproto/pkg/kvrpcpb" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/metrics" "github.com/pingcap/tidb/store/tikv/tikvrpc" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" "google.golang.org/grpc" diff --git a/store/tikv/region_request_test.go b/store/tikv/region_request_test.go index 710e33270eda3..fed561fd92288 100644 --- a/store/tikv/region_request_test.go +++ b/store/tikv/region_request_test.go @@ -19,7 +19,6 @@ import ( "sync" "time" - "github.com/juju/errors" . "github.com/pingcap/check" "github.com/pingcap/kvproto/pkg/coprocessor" "github.com/pingcap/kvproto/pkg/kvrpcpb" @@ -27,6 +26,7 @@ import ( "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/store/mockstore/mocktikv" "github.com/pingcap/tidb/store/tikv/tikvrpc" + "github.com/pkg/errors" "golang.org/x/net/context" "google.golang.org/grpc" ) diff --git a/store/tikv/safepoint.go b/store/tikv/safepoint.go index 5bca2389f0ab8..ea456c0c23162 100644 --- a/store/tikv/safepoint.go +++ b/store/tikv/safepoint.go @@ -20,7 +20,7 @@ import ( "time" "github.com/coreos/etcd/clientv3" - "github.com/juju/errors" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" ) diff --git a/store/tikv/safepoint_test.go b/store/tikv/safepoint_test.go index 4458851d1eb0c..29b640a1d48fd 100644 --- a/store/tikv/safepoint_test.go +++ b/store/tikv/safepoint_test.go @@ -17,10 +17,10 @@ import ( "fmt" "time" - "github.com/juju/errors" . "github.com/pingcap/check" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/terror" + "github.com/pkg/errors" "golang.org/x/net/context" ) @@ -91,7 +91,7 @@ func (s *testSafePointSuite) TestSafePoint(c *C) { _, geterr2 := txn2.Get(encodeKey(s.prefix, s08d("key", 0))) c.Assert(geterr2, NotNil) isFallBehind := terror.ErrorEqual(errors.Cause(geterr2), ErrGCTooEarly) - isMayFallBehind := terror.ErrorEqual(errors.Cause(geterr2), ErrPDServerTimeout.GenByArgs("start timestamp may fall behind safe point")) + isMayFallBehind := terror.ErrorEqual(errors.Cause(geterr2), ErrPDServerTimeout.GenWithStackByArgs("start timestamp may fall behind safe point")) isBehind := isFallBehind || isMayFallBehind c.Assert(isBehind, IsTrue) @@ -103,7 +103,7 @@ func (s *testSafePointSuite) TestSafePoint(c *C) { _, seekerr := txn3.Seek(encodeKey(s.prefix, "")) c.Assert(seekerr, NotNil) isFallBehind = terror.ErrorEqual(errors.Cause(geterr2), ErrGCTooEarly) - isMayFallBehind = terror.ErrorEqual(errors.Cause(geterr2), ErrPDServerTimeout.GenByArgs("start timestamp may fall behind safe point")) + isMayFallBehind = terror.ErrorEqual(errors.Cause(geterr2), ErrPDServerTimeout.GenWithStackByArgs("start timestamp may fall behind safe point")) isBehind = isFallBehind || isMayFallBehind c.Assert(isBehind, IsTrue) @@ -117,7 +117,7 @@ func (s *testSafePointSuite) TestSafePoint(c *C) { _, batchgeterr := snapshot.BatchGet(keys) c.Assert(batchgeterr, NotNil) isFallBehind = terror.ErrorEqual(errors.Cause(geterr2), ErrGCTooEarly) - isMayFallBehind = terror.ErrorEqual(errors.Cause(geterr2), ErrPDServerTimeout.GenByArgs("start timestamp may fall behind safe point")) + isMayFallBehind = terror.ErrorEqual(errors.Cause(geterr2), ErrPDServerTimeout.GenWithStackByArgs("start timestamp may fall behind safe point")) isBehind = isFallBehind || isMayFallBehind c.Assert(isBehind, IsTrue) } diff --git a/store/tikv/scan.go b/store/tikv/scan.go index b37de8c9db394..ab0ba76bc0e60 100644 --- a/store/tikv/scan.go +++ b/store/tikv/scan.go @@ -14,10 +14,10 @@ package tikv import ( - "github.com/juju/errors" pb "github.com/pingcap/kvproto/pkg/kvrpcpb" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/store/tikv/tikvrpc" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" ) diff --git a/store/tikv/snapshot.go b/store/tikv/snapshot.go index e4f55d1600a15..730db0273c193 100644 --- a/store/tikv/snapshot.go +++ b/store/tikv/snapshot.go @@ -20,12 +20,12 @@ import ( "time" "unsafe" - "github.com/juju/errors" pb "github.com/pingcap/kvproto/pkg/kvrpcpb" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/metrics" "github.com/pingcap/tidb/store/tikv/tikvrpc" "github.com/pingcap/tidb/tablecodec" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" ) diff --git a/store/tikv/split_region.go b/store/tikv/split_region.go index 9c24c80f5876b..8be3e81c52dd3 100644 --- a/store/tikv/split_region.go +++ b/store/tikv/split_region.go @@ -16,10 +16,10 @@ package tikv import ( "bytes" - "github.com/juju/errors" "github.com/pingcap/kvproto/pkg/kvrpcpb" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/store/tikv/tikvrpc" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" ) diff --git a/store/tikv/store_test.go b/store/tikv/store_test.go index d06008e79ffee..2fe3af12b194d 100644 --- a/store/tikv/store_test.go +++ b/store/tikv/store_test.go @@ -17,7 +17,6 @@ import ( "sync" "time" - "github.com/juju/errors" . "github.com/pingcap/check" pb "github.com/pingcap/kvproto/pkg/kvrpcpb" "github.com/pingcap/kvproto/pkg/metapb" @@ -25,6 +24,7 @@ import ( "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/store/mockoracle" "github.com/pingcap/tidb/store/tikv/tikvrpc" + "github.com/pkg/errors" "golang.org/x/net/context" ) diff --git a/store/tikv/test_util.go b/store/tikv/test_util.go index 01b4eb7574f93..060ea68a626c0 100644 --- a/store/tikv/test_util.go +++ b/store/tikv/test_util.go @@ -14,9 +14,9 @@ package tikv import ( - "github.com/juju/errors" "github.com/pingcap/pd/pd-client" "github.com/pingcap/tidb/kv" + "github.com/pkg/errors" "github.com/twinj/uuid" ) diff --git a/store/tikv/ticlient_test.go b/store/tikv/ticlient_test.go index c0f167fab6560..1b4ea24ad5c82 100644 --- a/store/tikv/ticlient_test.go +++ b/store/tikv/ticlient_test.go @@ -19,11 +19,11 @@ import ( "sync" "time" - "github.com/juju/errors" . "github.com/pingcap/check" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/store/mockstore/mocktikv" "github.com/pingcap/tidb/util/codec" + "github.com/pkg/errors" "golang.org/x/net/context" ) diff --git a/store/tikv/tikvrpc/tikvrpc.go b/store/tikv/tikvrpc/tikvrpc.go index e9c7eb2189d0c..d6f562ba2f671 100644 --- a/store/tikv/tikvrpc/tikvrpc.go +++ b/store/tikv/tikvrpc/tikvrpc.go @@ -18,12 +18,12 @@ import ( "sync/atomic" "time" - "github.com/juju/errors" "github.com/pingcap/kvproto/pkg/coprocessor" "github.com/pingcap/kvproto/pkg/errorpb" "github.com/pingcap/kvproto/pkg/kvrpcpb" "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/tikvpb" + "github.com/pkg/errors" "golang.org/x/net/context" ) diff --git a/store/tikv/txn.go b/store/tikv/txn.go index 5fa3cf28d0f96..b1edef7da5b97 100644 --- a/store/tikv/txn.go +++ b/store/tikv/txn.go @@ -18,10 +18,10 @@ import ( "sync" "time" - "github.com/juju/errors" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/metrics" "github.com/pingcap/tidb/sessionctx" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" ) diff --git a/structure/hash.go b/structure/hash.go index ff9c3e4cd8ad8..8b04016c37bc1 100644 --- a/structure/hash.go +++ b/structure/hash.go @@ -18,8 +18,8 @@ import ( "encoding/binary" "strconv" - "github.com/juju/errors" "github.com/pingcap/tidb/kv" + "github.com/pkg/errors" ) // HashPair is the pair for (field, value) in a hash. diff --git a/structure/list.go b/structure/list.go index e46567539f107..ae98232dc670e 100644 --- a/structure/list.go +++ b/structure/list.go @@ -16,8 +16,8 @@ package structure import ( "encoding/binary" - "github.com/juju/errors" "github.com/pingcap/tidb/kv" + "github.com/pkg/errors" ) type listMeta struct { @@ -188,7 +188,7 @@ func (t *TxStructure) LSet(key []byte, index int64, value []byte) error { if index >= meta.LIndex && index < meta.RIndex { return t.readWriter.Set(t.encodeListDataKey(key, index), value) } - return errInvalidListIndex.Gen("invalid list index %d", index) + return errInvalidListIndex.GenWithStack("invalid list index %d", index) } // LClear removes the list of the key. diff --git a/structure/string.go b/structure/string.go index 5e0e4b5d6fed1..ccf5b67c25cf5 100644 --- a/structure/string.go +++ b/structure/string.go @@ -16,8 +16,8 @@ package structure import ( "strconv" - "github.com/juju/errors" "github.com/pingcap/tidb/kv" + "github.com/pkg/errors" ) // Set sets the string value of the key. diff --git a/structure/type.go b/structure/type.go index 526c1822486a0..79c58beddba7c 100644 --- a/structure/type.go +++ b/structure/type.go @@ -16,9 +16,9 @@ package structure import ( "bytes" - "github.com/juju/errors" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/util/codec" + "github.com/pkg/errors" ) // TypeFlag is for data structure meta/data flag. @@ -86,7 +86,7 @@ func (t *TxStructure) decodeHashDataKey(ek kv.Key) ([]byte, []byte, error) { if err != nil { return nil, nil, errors.Trace(err) } else if TypeFlag(tp) != HashData { - return nil, nil, errInvalidHashKeyFlag.Gen("invalid encoded hash data key flag %c", byte(tp)) + return nil, nil, errInvalidHashKeyFlag.GenWithStack("invalid encoded hash data key flag %c", byte(tp)) } _, field, err = codec.DecodeBytes(ek, nil) diff --git a/table/column.go b/table/column.go index 86276ea6330ac..c2b408943f5c5 100644 --- a/table/column.go +++ b/table/column.go @@ -21,7 +21,6 @@ import ( "strings" "unicode/utf8" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/model" @@ -31,6 +30,7 @@ import ( "github.com/pingcap/tidb/types/json" "github.com/pingcap/tidb/util/charset" "github.com/pingcap/tidb/util/hack" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" ) @@ -91,7 +91,7 @@ func FindCols(cols []*Column, names []string, pkIsHandle bool) ([]*Column, error col.ColumnInfo.Offset = len(cols) rcols = append(rcols, col) } else { - return nil, errUnknownColumn.Gen("unknown column %s", name) + return nil, errUnknownColumn.GenWithStack("unknown column %s", name) } } @@ -274,7 +274,7 @@ func CheckOnce(cols []*Column) error { name := col.Name _, ok := m[name.L] if ok { - return errDuplicateColumn.Gen("column specified twice - %s", name) + return errDuplicateColumn.GenWithStack("column specified twice - %s", name) } m[name.L] = struct{}{} @@ -286,7 +286,7 @@ func CheckOnce(cols []*Column) error { // CheckNotNull checks if nil value set to a column with NotNull flag is set. func (c *Column) CheckNotNull(data types.Datum) error { if mysql.HasNotNullFlag(c.Flag) && data.IsNull() { - return ErrColumnCantNull.GenByArgs(c.Name) + return ErrColumnCantNull.GenWithStackByArgs(c.Name) } return nil } @@ -325,7 +325,7 @@ func getColDefaultValue(ctx sessionctx.Context, col *model.ColumnInfo, defaultVa if col.Tp == mysql.TypeTimestamp || col.Tp == mysql.TypeDatetime { value, err := expression.GetTimeValue(ctx, defaultVal, col.Tp, col.Decimal) if err != nil { - return types.Datum{}, errGetDefaultFailed.Gen("Field '%s' get default value fail - %s", + return types.Datum{}, errGetDefaultFailed.GenWithStack("Field '%s' get default value fail - %s", col.Name, errors.Trace(err)) } return value, nil @@ -352,10 +352,10 @@ func getColDefaultValueFromNil(ctx sessionctx.Context, col *model.ColumnInfo) (t } sc := ctx.GetSessionVars().StmtCtx if sc.BadNullAsWarning { - sc.AppendWarning(ErrColumnCantNull.GenByArgs(col.Name)) + sc.AppendWarning(ErrColumnCantNull.GenWithStackByArgs(col.Name)) return GetZeroValue(col), nil } - return types.Datum{}, ErrNoDefaultValue.Gen("Field '%s' doesn't have a default value", col.Name) + return types.Datum{}, ErrNoDefaultValue.GenWithStack("Field '%s' doesn't have a default value", col.Name) } // GetZeroValue gets zero value for given column type. diff --git a/table/tables/gen_expr.go b/table/tables/gen_expr.go index e8b238b6731a1..fa94ca009c74d 100644 --- a/table/tables/gen_expr.go +++ b/table/tables/gen_expr.go @@ -16,10 +16,10 @@ package tables import ( "fmt" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/model" "github.com/pingcap/tidb/parser" + "github.com/pkg/errors" ) // getDefaultCharsetAndCollate is copyed from ddl/ddl_api.go. diff --git a/table/tables/index.go b/table/tables/index.go index 1781a2c16e843..e11993001bfac 100644 --- a/table/tables/index.go +++ b/table/tables/index.go @@ -19,7 +19,6 @@ import ( "io" "unicode/utf8" - "github.com/juju/errors" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/model" "github.com/pingcap/tidb/sessionctx" @@ -29,6 +28,7 @@ import ( "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/charset" "github.com/pingcap/tidb/util/codec" + "github.com/pkg/errors" ) // EncodeHandle encodes handle in data. @@ -330,7 +330,7 @@ func (c *index) FetchValues(r []types.Datum, vals []types.Datum) ([]types.Datum, vals = vals[:needLength] for i, ic := range c.idxInfo.Columns { if ic.Offset < 0 || ic.Offset >= len(r) { - return nil, table.ErrIndexOutBound.Gen("Index column %s offset out of bound, offset: %d, row: %v", + return nil, table.ErrIndexOutBound.GenWithStack("Index column %s offset out of bound, offset: %d, row: %v", ic.Name, ic.Offset, r) } vals[i] = r[ic.Offset] diff --git a/table/tables/partition.go b/table/tables/partition.go index 5f72a99e40a33..762c4e7976e7f 100644 --- a/table/tables/partition.go +++ b/table/tables/partition.go @@ -19,7 +19,6 @@ import ( "sort" "strings" - "github.com/juju/errors" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/model" @@ -29,6 +28,7 @@ import ( "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/mock" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" ) diff --git a/table/tables/tables.go b/table/tables/tables.go index 23a58cae54c86..8660f8625e27e 100644 --- a/table/tables/tables.go +++ b/table/tables/tables.go @@ -24,7 +24,6 @@ import ( "strings" "time" - "github.com/juju/errors" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/meta/autoid" "github.com/pingcap/tidb/model" @@ -40,6 +39,7 @@ import ( "github.com/pingcap/tidb/util/codec" "github.com/pingcap/tidb/util/kvcache" binlog "github.com/pingcap/tipb/go-binlog" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "github.com/spaolacci/murmur3" "golang.org/x/net/context" @@ -97,14 +97,14 @@ func MockTableFromMeta(tblInfo *model.TableInfo) table.Table { // TableFromMeta creates a Table instance from model.TableInfo. func TableFromMeta(alloc autoid.Allocator, tblInfo *model.TableInfo) (table.Table, error) { if tblInfo.State == model.StateNone { - return nil, table.ErrTableStateCantNone.Gen("table %s can't be in none state", tblInfo.Name) + return nil, table.ErrTableStateCantNone.GenWithStack("table %s can't be in none state", tblInfo.Name) } colsLen := len(tblInfo.Columns) columns := make([]*table.Column, 0, colsLen) for i, colInfo := range tblInfo.Columns { if colInfo.State == model.StateNone { - return nil, table.ErrColumnStateCantNone.Gen("column %s can't be in none state", colInfo.Name) + return nil, table.ErrColumnStateCantNone.GenWithStack("column %s can't be in none state", colInfo.Name) } // Print some information when the column's offset isn't equal to i. @@ -158,7 +158,7 @@ func initTableIndices(t *tableCommon) error { tblInfo := t.meta for _, idxInfo := range tblInfo.Indices { if idxInfo.State == model.StateNone { - return table.ErrIndexStateCantNone.Gen("index %s can't be in none state", idxInfo.Name) + return table.ErrIndexStateCantNone.GenWithStack("index %s can't be in none state", idxInfo.Name) } // Use partition ID for index, because tableCommon may be table or partition. diff --git a/tablecodec/tablecodec.go b/tablecodec/tablecodec.go index b1fde23c8fc55..ec07f38b0f05e 100644 --- a/tablecodec/tablecodec.go +++ b/tablecodec/tablecodec.go @@ -19,13 +19,13 @@ import ( "math" "time" - "github.com/juju/errors" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/sessionctx/stmtctx" "github.com/pingcap/tidb/terror" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/codec" + "github.com/pkg/errors" ) var ( @@ -97,12 +97,12 @@ func hasRecordPrefixSep(key kv.Key) bool { // DecodeRecordKey decodes the key and gets the tableID, handle. func DecodeRecordKey(key kv.Key) (tableID int64, handle int64, err error) { if len(key) <= prefixLen { - return 0, 0, errInvalidRecordKey.Gen("invalid record key - %q", key) + return 0, 0, errInvalidRecordKey.GenWithStack("invalid record key - %q", key) } k := key if !hasTablePrefix(key) { - return 0, 0, errInvalidRecordKey.Gen("invalid record key - %q", k) + return 0, 0, errInvalidRecordKey.GenWithStack("invalid record key - %q", k) } key = key[tablePrefixLength:] @@ -112,7 +112,7 @@ func DecodeRecordKey(key kv.Key) (tableID int64, handle int64, err error) { } if !hasRecordPrefixSep(key) { - return 0, 0, errInvalidRecordKey.Gen("invalid record key - %q", k) + return 0, 0, errInvalidRecordKey.GenWithStack("invalid record key - %q", k) } key = key[recordPrefixSepLength:] @@ -132,7 +132,7 @@ func DecodeIndexKey(key kv.Key) (tableID int64, indexID int64, indexValues []str return 0, 0, nil, errors.Trace(err) } if isRecord { - return 0, 0, nil, errInvalidIndexKey.Gen("invalid index key - %q", k) + return 0, 0, nil, errInvalidIndexKey.GenWithStack("invalid index key - %q", k) } key = key[prefixLen+idLen:] @@ -141,11 +141,11 @@ func DecodeIndexKey(key kv.Key) (tableID int64, indexID int64, indexValues []str // the column. For instance, MysqlTime is internally saved as uint64. remain, d, e := codec.DecodeOne(key) if e != nil { - return 0, 0, nil, errInvalidIndexKey.Gen("invalid index key - %q %v", k, e) + return 0, 0, nil, errInvalidIndexKey.GenWithStack("invalid index key - %q %v", k, e) } str, e1 := d.ToString() if e1 != nil { - return 0, 0, nil, errInvalidIndexKey.Gen("invalid index key - %q %v", k, e1) + return 0, 0, nil, errInvalidIndexKey.GenWithStack("invalid index key - %q %v", k, e1) } indexValues = append(indexValues, str) key = remain @@ -158,7 +158,7 @@ func DecodeKeyHead(key kv.Key) (tableID int64, indexID int64, isRecordKey bool, isRecordKey = false k := key if !key.HasPrefix(tablePrefix) { - err = errInvalidKey.Gen("invalid key - %q", k) + err = errInvalidKey.GenWithStack("invalid key - %q", k) return } @@ -174,7 +174,7 @@ func DecodeKeyHead(key kv.Key) (tableID int64, indexID int64, isRecordKey bool, return } if !key.HasPrefix(indexPrefixSep) { - err = errInvalidKey.Gen("invalid key - %q", k) + err = errInvalidKey.GenWithStack("invalid key - %q", k) return } @@ -203,7 +203,7 @@ func DecodeTableID(key kv.Key) int64 { // DecodeRowKey decodes the key and gets the handle. func DecodeRowKey(key kv.Key) (int64, error) { if len(key) != recordRowKeyLen || !hasTablePrefix(key) || !hasRecordPrefixSep(key[prefixLen-2:]) { - return 0, errInvalidKey.Gen("invalid key - %q", key) + return 0, errInvalidKey.GenWithStack("invalid key - %q", key) } u := binary.BigEndian.Uint64(key[prefixLen:]) return codec.DecodeCmpUintToInt(u), nil diff --git a/terror/terror.go b/terror/terror.go index 20a61ee56d305..3cc1c2d17105c 100644 --- a/terror/terror.go +++ b/terror/terror.go @@ -16,11 +16,10 @@ package terror import ( "encoding/json" "fmt" - "runtime" "strconv" - "github.com/juju/errors" "github.com/pingcap/tidb/mysql" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" ) @@ -217,26 +216,24 @@ func (e *Error) getMsg() string { return e.message } -// Gen generates a new *Error with the same class and code, and a new formatted message. -func (e *Error) Gen(format string, args ...interface{}) *Error { +// GenWithStack generates a new *Error with the same class and code, and a new formatted message. +func (e *Error) GenWithStack(format string, args ...interface{}) error { err := *e err.message = format err.args = args - _, err.file, err.line, _ = runtime.Caller(1) - return &err + return errors.AddStack(&err) } -// GenByArgs generates a new *Error with the same class and code, and new arguments. -func (e *Error) GenByArgs(args ...interface{}) *Error { +// GenWithStackByArgs generates a new *Error with the same class and code, and new arguments. +func (e *Error) GenWithStackByArgs(args ...interface{}) error { err := *e err.args = args - _, err.file, err.line, _ = runtime.Caller(1) - return &err + return errors.AddStack(&err) } // FastGen generates a new *Error with the same class and code, and a new formatted message. // This will not call runtime.Caller to get file and line. -func (e *Error) FastGen(format string, args ...interface{}) *Error { +func (e *Error) FastGen(format string, args ...interface{}) error { err := *e err.message = format err.args = args diff --git a/terror/terror_test.go b/terror/terror_test.go index 0a3423e6b5c31..837ab32f4b2d9 100644 --- a/terror/terror_test.go +++ b/terror/terror_test.go @@ -18,9 +18,9 @@ import ( "strings" "testing" - "github.com/juju/errors" . "github.com/pingcap/check" "github.com/pingcap/tidb/util/testleak" + "github.com/pkg/errors" ) func TestT(t *testing.T) { @@ -54,7 +54,7 @@ func (s *testTErrorSuite) TestTError(c *C) { optimizerErr := ClassOptimizer.New(ErrCode(2), "abc") c.Assert(ClassOptimizer.EqualClass(errors.New("abc")), IsFalse) c.Assert(ClassOptimizer.EqualClass(nil), IsFalse) - c.Assert(optimizerErr.Equal(optimizerErr.Gen("def")), IsTrue) + c.Assert(optimizerErr.Equal(optimizerErr.GenWithStack("def")), IsTrue) c.Assert(optimizerErr.Equal(nil), IsFalse) c.Assert(optimizerErr.Equal(errors.New("abc")), IsFalse) @@ -68,11 +68,11 @@ func (s *testTErrorSuite) TestTError(c *C) { 1062: uint16(1062), } ErrClassToMySQLCodes[ClassKV] = kvMySQLErrCodes - sqlErr := e.ToSQLError() + sqlErr := errors.Cause(e).(*Error).ToSQLError() c.Assert(sqlErr.Message, Equals, "Duplicate entry '1' for key 'PRIMARY'") c.Assert(sqlErr.Code, Equals, uint16(1062)) - err := errors.Trace(ErrCritical.GenByArgs("test")) + err := errors.Trace(ErrCritical.GenWithStackByArgs("test")) c.Assert(ErrCritical.Equal(err), IsTrue) err = errors.Trace(ErrCritical) @@ -102,7 +102,7 @@ func example() error { } func call() error { - return predefinedErr.Gen("error message:%s", "abc") + return predefinedErr.GenWithStack("error message:%s", "abc") } func (s *testTErrorSuite) TestTraceAndLocation(c *C) { @@ -110,10 +110,15 @@ func (s *testTErrorSuite) TestTraceAndLocation(c *C) { err := example() stack := errors.ErrorStack(err) lines := strings.Split(stack, "\n") - c.Assert(len(lines), Equals, 2) + c.Assert(len(lines), Equals, 23) + var containTerr bool for _, v := range lines { - c.Assert(strings.Contains(v, "terror_test.go"), IsTrue) + if strings.Contains(v, "terror_test.go") { + containTerr = true + break + } } + c.Assert(containTerr, IsTrue) } func (s *testTErrorSuite) TestErrorEqual(c *C) { diff --git a/tidb-server/main.go b/tidb-server/main.go index acd8ffbf65538..9a1bcc019200a 100644 --- a/tidb-server/main.go +++ b/tidb-server/main.go @@ -25,7 +25,6 @@ import ( "syscall" "time" - "github.com/juju/errors" "github.com/opentracing/opentracing-go" "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/ddl" @@ -49,6 +48,7 @@ import ( "github.com/pingcap/tidb/util/systimemon" "github.com/pingcap/tidb/x-server" binlog "github.com/pingcap/tipb/go-binlog" + "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/push" log "github.com/sirupsen/logrus" diff --git a/types/binary_literal.go b/types/binary_literal.go index 7e72bca891cf0..da75a5d744807 100644 --- a/types/binary_literal.go +++ b/types/binary_literal.go @@ -22,8 +22,8 @@ import ( "strconv" "strings" - "github.com/juju/errors" "github.com/pingcap/tidb/sessionctx/stmtctx" + "github.com/pkg/errors" ) // BinaryLiteral is the internal type for storing bit / hex literal type. @@ -108,7 +108,7 @@ func (b BinaryLiteral) ToInt(sc *stmtctx.StatementContext) (uint64, error) { return 0, nil } if length > 8 { - var err error = ErrTruncatedWrongVal.GenByArgs("BINARY", b) + var err error = ErrTruncatedWrongVal.GenWithStackByArgs("BINARY", b) if sc != nil { err = sc.HandleTruncate(err) } diff --git a/types/convert.go b/types/convert.go index ab727258b76fd..b8eb173c4b7ce 100644 --- a/types/convert.go +++ b/types/convert.go @@ -22,12 +22,12 @@ import ( "strconv" "strings" - "github.com/juju/errors" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/sessionctx/stmtctx" "github.com/pingcap/tidb/terror" "github.com/pingcap/tidb/types/json" "github.com/pingcap/tidb/util/hack" + "github.com/pkg/errors" ) func truncateStr(str string, flen int) string { @@ -142,7 +142,7 @@ func StrToInt(sc *stmtctx.StatementContext, str string) (int64, error) { validPrefix, err := getValidIntPrefix(sc, str) iVal, err1 := strconv.ParseInt(validPrefix, 10, 64) if err1 != nil { - return iVal, ErrOverflow.GenByArgs("BIGINT", validPrefix) + return iVal, ErrOverflow.GenWithStackByArgs("BIGINT", validPrefix) } return iVal, errors.Trace(err) } @@ -156,7 +156,7 @@ func StrToUint(sc *stmtctx.StatementContext, str string) (uint64, error) { } uVal, err1 := strconv.ParseUint(validPrefix, 10, 64) if err1 != nil { - return uVal, ErrOverflow.GenByArgs("BIGINT UNSIGNED", validPrefix) + return uVal, ErrOverflow.GenWithStackByArgs("BIGINT UNSIGNED", validPrefix) } return uVal, errors.Trace(err) } @@ -204,12 +204,12 @@ func NumberToDuration(number int64, fsp int) (Duration, error) { } dur, err1 := MaxMySQLTime(fsp).ConvertToDuration() terror.Log(err1) - return dur, ErrOverflow.GenByArgs("Duration", strconv.Itoa(int(number))) + return dur, ErrOverflow.GenWithStackByArgs("Duration", strconv.Itoa(int(number))) } else if number < -TimeMaxValue { dur, err1 := MaxMySQLTime(fsp).ConvertToDuration() terror.Log(err1) dur.Duration = -dur.Duration - return dur, ErrOverflow.GenByArgs("Duration", strconv.Itoa(int(number))) + return dur, ErrOverflow.GenWithStackByArgs("Duration", strconv.Itoa(int(number))) } var neg bool if neg = number < 0; neg { @@ -217,7 +217,7 @@ func NumberToDuration(number int64, fsp int) (Duration, error) { } if number/10000 > TimeMaxHour || number%100 >= 60 || (number/100)%100 >= 60 { - return ZeroDuration, errors.Trace(ErrInvalidTimeFormat.GenByArgs(number)) + return ZeroDuration, errors.Trace(ErrInvalidTimeFormat.GenWithStackByArgs(number)) } t := Time{Time: FromDate(0, 0, 0, int(number/10000), int((number/100)%100), int(number%100), 0), Type: mysql.TypeDuration, Fsp: fsp} dur, err := t.ConvertToDuration() @@ -275,7 +275,7 @@ func floatStrToIntStr(sc *stmtctx.StatementContext, validFloat string, oriStr st } if exp > 0 && int64(intCnt) > (math.MaxInt64-int64(exp)) { // (exp + incCnt) overflows MaxInt64. - sc.AppendWarning(ErrOverflow.GenByArgs("BIGINT", oriStr)) + sc.AppendWarning(ErrOverflow.GenWithStackByArgs("BIGINT", oriStr)) return validFloat[:eIdx], nil } intCnt += exp @@ -293,7 +293,7 @@ func floatStrToIntStr(sc *stmtctx.StatementContext, validFloat string, oriStr st extraZeroCount := intCnt - len(digits) if extraZeroCount > 20 { // Append overflow warning and return to avoid allocating too much memory. - sc.AppendWarning(ErrOverflow.GenByArgs("BIGINT", oriStr)) + sc.AppendWarning(ErrOverflow.GenWithStackByArgs("BIGINT", oriStr)) return validFloat[:eIdx], nil } validInt = string(digits) + strings.Repeat("0", extraZeroCount) @@ -310,7 +310,7 @@ func StrToFloat(sc *stmtctx.StatementContext, str string) (float64, error) { if err2, ok := err1.(*strconv.NumError); ok { // value will truncate to MAX/MIN if out of range. if err2.Err == strconv.ErrRange { - err1 = sc.HandleTruncate(ErrTruncatedWrongVal.GenByArgs("DOUBLE", str)) + err1 = sc.HandleTruncate(ErrTruncatedWrongVal.GenWithStackByArgs("DOUBLE", str)) if math.IsInf(f, 1) { f = math.MaxFloat64 } else if math.IsInf(f, -1) { diff --git a/types/convert_test.go b/types/convert_test.go index 08657d627dae8..df35527d7e612 100644 --- a/types/convert_test.go +++ b/types/convert_test.go @@ -19,7 +19,6 @@ import ( "strconv" "time" - "github.com/juju/errors" . "github.com/pingcap/check" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/sessionctx/stmtctx" @@ -27,6 +26,7 @@ import ( "github.com/pingcap/tidb/types/json" "github.com/pingcap/tidb/util/charset" "github.com/pingcap/tidb/util/testleak" + "github.com/pkg/errors" ) var _ = Suite(&testTypeConvertSuite{}) diff --git a/types/datum.go b/types/datum.go index 4788318f4ff21..641cd889d32d9 100644 --- a/types/datum.go +++ b/types/datum.go @@ -22,13 +22,14 @@ import ( "time" "unicode/utf8" - "github.com/juju/errors" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/sessionctx/stmtctx" "github.com/pingcap/tidb/terror" "github.com/pingcap/tidb/types/json" "github.com/pingcap/tidb/util/charset" "github.com/pingcap/tidb/util/hack" + "github.com/pkg/errors" + log "github.com/sirupsen/logrus" ) // Kind constants. @@ -826,11 +827,11 @@ func ProduceStrWithSpecifiedTp(s string, tp *FieldType, sc *stmtctx.StatementCon } runeCount++ } - err = ErrDataTooLong.Gen("Data Too Long, field len %d, data len %d", flen, characterLen) + err = ErrDataTooLong.GenWithStack("Data Too Long, field len %d, data len %d", flen, characterLen) s = truncateStr(s, truncateLen) } } else if len(s) > flen { - err = ErrDataTooLong.Gen("Data Too Long, field len %d, data len %d", flen, len(s)) + err = ErrDataTooLong.GenWithStack("Data Too Long, field len %d, data len %d", flen, len(s)) s = truncateStr(s, flen) } else if tp.Tp == mysql.TypeString && IsBinaryStr(tp) && len(s) < flen { padding := make([]byte, flen-len(s)) @@ -1033,10 +1034,10 @@ func (d *Datum) convertToMysqlDuration(sc *stmtctx.StatementContext, target *Fie if timeNum > MaxDuration && timeNum < 10000000000 { // mysql return max in no strict sql mode. ret.SetValue(Duration{Duration: MaxTime, Fsp: 0}) - return ret, ErrInvalidTimeFormat.Gen("Incorrect time value: '%s'", timeStr) + return ret, ErrInvalidTimeFormat.GenWithStack("Incorrect time value: '%s'", timeStr) } if timeNum < -MaxDuration { - return ret, ErrInvalidTimeFormat.Gen("Incorrect time value: '%s'", timeStr) + return ret, ErrInvalidTimeFormat.GenWithStack("Incorrect time value: '%s'", timeStr) } t, err := ParseDuration(timeStr, fsp) ret.SetValue(t) @@ -1101,7 +1102,7 @@ func (d *Datum) convertToMysqlDecimal(sc *stmtctx.StatementContext, target *Fiel if dec.negative && mysql.HasUnsignedFlag(target.Flag) { *dec = zeroMyDecimal if err == nil { - err = ErrOverflow.GenByArgs("DECIMAL", fmt.Sprintf("(%d, %d)", target.Flen, target.Decimal)) + err = ErrOverflow.GenWithStackByArgs("DECIMAL", fmt.Sprintf("(%d, %d)", target.Flen, target.Decimal)) } } ret.SetValue(dec) @@ -1113,13 +1114,13 @@ func ProduceDecWithSpecifiedTp(dec *MyDecimal, tp *FieldType, sc *stmtctx.Statem flen, decimal := tp.Flen, tp.Decimal if flen != UnspecifiedLength && decimal != UnspecifiedLength { if flen < decimal { - return nil, ErrMBiggerThanD.GenByArgs("") + return nil, ErrMBiggerThanD.GenWithStackByArgs("") } prec, frac := dec.PrecisionAndFrac() if !dec.IsZero() && prec-frac > flen-decimal { dec = NewMaxOrMinDec(dec.IsNegative(), flen, decimal) // select (cast 111 as decimal(1)) causes a warning in MySQL. - err = ErrOverflow.GenByArgs("DECIMAL", fmt.Sprintf("(%d, %d)", flen, decimal)) + err = ErrOverflow.GenWithStackByArgs("DECIMAL", fmt.Sprintf("(%d, %d)", flen, decimal)) } else if frac != decimal { old := *dec err = dec.Round(dec, decimal, ModeHalfEven) @@ -1193,7 +1194,7 @@ func (d *Datum) convertToMysqlBit(sc *stmtctx.StatementContext, target *FieldTyp uintValue, err = uintDatum.GetUint64(), err1 } if target.Flen < 64 && uintValue >= 1<<(uint64(target.Flen)) { - return Datum{}, errors.Trace(ErrOverflow.GenByArgs("BIT", fmt.Sprintf("(%d)", target.Flen))) + return Datum{}, errors.Trace(ErrOverflow.GenWithStackByArgs("BIT", fmt.Sprintf("(%d)", target.Flen))) } byteSize := (target.Flen + 7) >> 3 ret.SetMysqlBit(NewBinaryLiteralFromUint(uintValue, byteSize)) @@ -1218,7 +1219,8 @@ func (d *Datum) convertToMysqlEnum(sc *stmtctx.StatementContext, target *FieldTy e, err = ParseEnumValue(target.Elems, uintDatum.GetUint64()) } if err != nil { - err = errors.Wrap(err, ErrTruncated) + log.Error(err) + err = errors.Trace(ErrTruncated) } ret.SetValue(e) return ret, err diff --git a/types/datum_eval.go b/types/datum_eval.go index 970f80e97e31b..af8a7f993402b 100644 --- a/types/datum_eval.go +++ b/types/datum_eval.go @@ -15,8 +15,8 @@ package types import ( "github.com/cznic/mathutil" - "github.com/juju/errors" "github.com/pingcap/tidb/parser/opcode" + "github.com/pkg/errors" ) // ComputePlus computes the result of a+b. diff --git a/types/enum.go b/types/enum.go index 4ba8e20b38fff..085e9b31874de 100644 --- a/types/enum.go +++ b/types/enum.go @@ -17,7 +17,7 @@ import ( "strconv" "strings" - "github.com/juju/errors" + "github.com/pkg/errors" ) // Enum is for MySQL enum type. diff --git a/types/etc.go b/types/etc.go index 56e551f9735bd..4f1bf1115d74e 100644 --- a/types/etc.go +++ b/types/etc.go @@ -21,11 +21,11 @@ import ( "io" "strings" - "github.com/juju/errors" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/parser/opcode" "github.com/pingcap/tidb/terror" "github.com/pingcap/tidb/util/charset" + "github.com/pkg/errors" ) // IsTypeBlob returns a boolean indicating whether the tp is a blob type. @@ -210,7 +210,7 @@ func InvOp2(x, y interface{}, o opcode.Op) (interface{}, error) { // overflow returns an overflowed error. func overflow(v interface{}, tp byte) error { - return ErrOverflow.Gen("constant %v overflows %s", v, TypeStr(tp)) + return ErrOverflow.GenWithStack("constant %v overflows %s", v, TypeStr(tp)) } // IsTypeTemporal checks if a type is a temporal type. diff --git a/types/fsp.go b/types/fsp.go index f962a4d2dde32..69dd32c352a0e 100644 --- a/types/fsp.go +++ b/types/fsp.go @@ -18,7 +18,7 @@ import ( "strconv" "strings" - "github.com/juju/errors" + "github.com/pkg/errors" ) const ( diff --git a/types/helper.go b/types/helper.go index 9b4734f849dd5..385921f479b9d 100644 --- a/types/helper.go +++ b/types/helper.go @@ -18,7 +18,7 @@ import ( "strings" "unicode" - "github.com/juju/errors" + "github.com/pkg/errors" ) // RoundFloat rounds float val to the nearest integer value with float64 format, like MySQL Round function. @@ -71,7 +71,7 @@ func getMaxFloat(flen int, decimal int) float64 { func TruncateFloat(f float64, flen int, decimal int) (float64, error) { if math.IsNaN(f) { // nan returns 0 - return 0, ErrOverflow.GenByArgs("DOUBLE", "") + return 0, ErrOverflow.GenWithStackByArgs("DOUBLE", "") } maxF := getMaxFloat(flen, decimal) @@ -83,10 +83,10 @@ func TruncateFloat(f float64, flen int, decimal int) (float64, error) { var err error if f > maxF { f = maxF - err = ErrOverflow.GenByArgs("DOUBLE", "") + err = ErrOverflow.GenWithStackByArgs("DOUBLE", "") } else if f < -maxF { f = -maxF - err = ErrOverflow.GenByArgs("DOUBLE", "") + err = ErrOverflow.GenWithStackByArgs("DOUBLE", "") } return f, errors.Trace(err) diff --git a/types/helper_test.go b/types/helper_test.go index ed513ea02f857..4a18f650af5da 100644 --- a/types/helper_test.go +++ b/types/helper_test.go @@ -16,8 +16,8 @@ package types import ( "strconv" - "github.com/juju/errors" . "github.com/pingcap/check" + "github.com/pkg/errors" ) var _ = Suite(&testTypeHelperSuite{}) diff --git a/types/json/binary.go b/types/json/binary.go index b8ded1e0a849e..8b10cdd44700c 100644 --- a/types/json/binary.go +++ b/types/json/binary.go @@ -25,9 +25,9 @@ import ( "strings" "unicode/utf8" - "github.com/juju/errors" "github.com/pingcap/tidb/terror" "github.com/pingcap/tidb/util/hack" + "github.com/pkg/errors" ) /* @@ -378,11 +378,11 @@ func marshalLiteralTo(b []byte, litType byte) []byte { // ParseBinaryFromString parses a json from string. func ParseBinaryFromString(s string) (bj BinaryJSON, err error) { if len(s) == 0 { - err = ErrInvalidJSONText.GenByArgs("The document is empty") + err = ErrInvalidJSONText.GenWithStackByArgs("The document is empty") return } if err = bj.UnmarshalJSON(hack.Slice(s)); err != nil { - err = ErrInvalidJSONText.GenByArgs(err) + err = ErrInvalidJSONText.GenWithStackByArgs(err) } return } diff --git a/types/json/binary_functions.go b/types/json/binary_functions.go index 2bcc804394cdc..21efcb46a58d1 100644 --- a/types/json/binary_functions.go +++ b/types/json/binary_functions.go @@ -22,8 +22,8 @@ import ( "unicode/utf8" "unsafe" - "github.com/juju/errors" "github.com/pingcap/tidb/util/hack" + "github.com/pkg/errors" ) // Type returns type of BinaryJSON as string. diff --git a/types/json/path_expr.go b/types/json/path_expr.go index 8bb9b7a7d6551..b58bf9f2729ae 100644 --- a/types/json/path_expr.go +++ b/types/json/path_expr.go @@ -18,7 +18,7 @@ import ( "strconv" "strings" - "github.com/juju/errors" + "github.com/pkg/errors" ) /* @@ -129,12 +129,12 @@ func ParseJSONPathExpr(pathExpr string) (pe PathExpression, err error) { // pathExpr[0: dollarIndex), return an ErrInvalidJSONPath error. dollarIndex := strings.Index(pathExpr, "$") if dollarIndex < 0 { - err = ErrInvalidJSONPath.GenByArgs(pathExpr) + err = ErrInvalidJSONPath.GenWithStackByArgs(pathExpr) return } for i := 0; i < dollarIndex; i++ { if !isBlank(rune(pathExpr[i])) { - err = ErrInvalidJSONPath.GenByArgs(pathExpr) + err = ErrInvalidJSONPath.GenWithStackByArgs(pathExpr) return } } @@ -142,7 +142,7 @@ func ParseJSONPathExpr(pathExpr string) (pe PathExpression, err error) { pathExprSuffix := strings.TrimFunc(pathExpr[dollarIndex+1:], isBlank) indices := jsonPathExprLegRe.FindAllStringIndex(pathExprSuffix, -1) if len(indices) == 0 && len(pathExprSuffix) != 0 { - err = ErrInvalidJSONPath.GenByArgs(pathExpr) + err = ErrInvalidJSONPath.GenWithStackByArgs(pathExpr) return } @@ -156,7 +156,7 @@ func ParseJSONPathExpr(pathExpr string) (pe PathExpression, err error) { // Check all characters between two legs are blank. for i := lastEnd; i < start; i++ { if !isBlank(rune(pathExprSuffix[i])) { - err = ErrInvalidJSONPath.GenByArgs(pathExpr) + err = ErrInvalidJSONPath.GenWithStackByArgs(pathExpr) return } } @@ -185,7 +185,7 @@ func ParseJSONPathExpr(pathExpr string) (pe PathExpression, err error) { } else if key[0] == '"' { // We need unquote the origin string. if key, err = unquoteString(key[1 : len(key)-1]); err != nil { - err = ErrInvalidJSONPath.GenByArgs(pathExpr) + err = ErrInvalidJSONPath.GenWithStackByArgs(pathExpr) return } } @@ -199,7 +199,7 @@ func ParseJSONPathExpr(pathExpr string) (pe PathExpression, err error) { if len(pe.legs) > 0 { // The last leg of a path expression cannot be '**'. if pe.legs[len(pe.legs)-1].typ == pathLegDoubleAsterisk { - err = ErrInvalidJSONPath.GenByArgs(pathExpr) + err = ErrInvalidJSONPath.GenWithStackByArgs(pathExpr) return } } diff --git a/types/mydecimal.go b/types/mydecimal.go index 5d2c88fbefe7c..97d037b80455b 100644 --- a/types/mydecimal.go +++ b/types/mydecimal.go @@ -17,9 +17,9 @@ import ( "math" "strconv" - "github.com/juju/errors" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/terror" + "github.com/pkg/errors" ) // RoundMode is the type for round mode. diff --git a/types/mytime.go b/types/mytime.go index 3fd655b78b504..0f546bf940913 100644 --- a/types/mytime.go +++ b/types/mytime.go @@ -16,7 +16,7 @@ package types import ( gotime "time" - "github.com/juju/errors" + "github.com/pkg/errors" ) // MysqlTime is the internal struct type for Time. @@ -112,7 +112,7 @@ func (t MysqlTime) GoTime(loc *gotime.Location) (gotime.Time, error) { if year != t.Year() || int(month) != t.Month() || day != t.Day() || hour != t.Hour() || minute != t.Minute() || second != t.Second() || microsec != t.Microsecond() { - return tm, errors.Trace(ErrInvalidTimeFormat.GenByArgs(t)) + return tm, errors.Trace(ErrInvalidTimeFormat.GenWithStackByArgs(t)) } return tm, nil } diff --git a/types/overflow.go b/types/overflow.go index f4c3316b66f9b..1be3742c29cc2 100644 --- a/types/overflow.go +++ b/types/overflow.go @@ -17,13 +17,13 @@ import ( "fmt" "math" - "github.com/juju/errors" + "github.com/pkg/errors" ) // AddUint64 adds uint64 a and b if no overflow, else returns error. func AddUint64(a uint64, b uint64) (uint64, error) { if math.MaxUint64-a < b { - return 0, ErrOverflow.GenByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%d, %d)", a, b)) + return 0, ErrOverflow.GenWithStackByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%d, %d)", a, b)) } return a + b, nil } @@ -32,7 +32,7 @@ func AddUint64(a uint64, b uint64) (uint64, error) { func AddInt64(a int64, b int64) (int64, error) { if (a > 0 && b > 0 && math.MaxInt64-a < b) || (a < 0 && b < 0 && math.MinInt64-a > b) { - return 0, ErrOverflow.GenByArgs("BIGINT", fmt.Sprintf("(%d, %d)", a, b)) + return 0, ErrOverflow.GenWithStackByArgs("BIGINT", fmt.Sprintf("(%d, %d)", a, b)) } return a + b, nil @@ -45,7 +45,7 @@ func AddInteger(a uint64, b int64) (uint64, error) { } if uint64(-b) > a { - return 0, ErrOverflow.GenByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%d, %d)", a, b)) + return 0, ErrOverflow.GenWithStackByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%d, %d)", a, b)) } return a - uint64(-b), nil } @@ -53,7 +53,7 @@ func AddInteger(a uint64, b int64) (uint64, error) { // SubUint64 subtracts uint64 a with b and returns uint64 if no overflow error. func SubUint64(a uint64, b uint64) (uint64, error) { if a < b { - return 0, ErrOverflow.GenByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%d, %d)", a, b)) + return 0, ErrOverflow.GenWithStackByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%d, %d)", a, b)) } return a - b, nil } @@ -63,7 +63,7 @@ func SubInt64(a int64, b int64) (int64, error) { if (a > 0 && b < 0 && math.MaxInt64-a < -b) || (a < 0 && b > 0 && math.MinInt64-a > -b) || (a == 0 && b == math.MinInt64) { - return 0, ErrOverflow.GenByArgs("BIGINT", fmt.Sprintf("(%d, %d)", a, b)) + return 0, ErrOverflow.GenWithStackByArgs("BIGINT", fmt.Sprintf("(%d, %d)", a, b)) } return a - b, nil } @@ -79,7 +79,7 @@ func SubUintWithInt(a uint64, b int64) (uint64, error) { // SubIntWithUint subtracts int64 a with uint64 b and returns uint64 if no overflow error. func SubIntWithUint(a int64, b uint64) (uint64, error) { if a < 0 || uint64(a) < b { - return 0, ErrOverflow.GenByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%d, %d)", a, b)) + return 0, ErrOverflow.GenWithStackByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%d, %d)", a, b)) } return uint64(a) - b, nil } @@ -87,7 +87,7 @@ func SubIntWithUint(a int64, b uint64) (uint64, error) { // MulUint64 multiplies uint64 a and b and returns uint64 if no overflow error. func MulUint64(a uint64, b uint64) (uint64, error) { if b > 0 && a > math.MaxUint64/b { - return 0, ErrOverflow.GenByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%d, %d)", a, b)) + return 0, ErrOverflow.GenWithStackByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%d, %d)", a, b)) } return a * b, nil } @@ -123,7 +123,7 @@ func MulInt64(a int64, b int64) (int64, error) { if negative { // negative result if res > math.MaxInt64+1 { - return 0, ErrOverflow.GenByArgs("BIGINT", fmt.Sprintf("(%d, %d)", a, b)) + return 0, ErrOverflow.GenWithStackByArgs("BIGINT", fmt.Sprintf("(%d, %d)", a, b)) } return -int64(res), nil @@ -131,7 +131,7 @@ func MulInt64(a int64, b int64) (int64, error) { // positive result if res > math.MaxInt64 { - return 0, ErrOverflow.GenByArgs("BIGINT", fmt.Sprintf("(%d, %d)", a, b)) + return 0, ErrOverflow.GenWithStackByArgs("BIGINT", fmt.Sprintf("(%d, %d)", a, b)) } return int64(res), nil @@ -144,7 +144,7 @@ func MulInteger(a uint64, b int64) (uint64, error) { } if b < 0 { - return 0, ErrOverflow.GenByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%d, %d)", a, b)) + return 0, ErrOverflow.GenWithStackByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%d, %d)", a, b)) } return MulUint64(a, uint64(b)) @@ -154,7 +154,7 @@ func MulInteger(a uint64, b int64) (uint64, error) { // It just checks overflow, if b is zero, a "divide by zero" panic throws. func DivInt64(a int64, b int64) (int64, error) { if a == math.MinInt64 && b == -1 { - return 0, ErrOverflow.GenByArgs("BIGINT", fmt.Sprintf("(%d, %d)", a, b)) + return 0, ErrOverflow.GenWithStackByArgs("BIGINT", fmt.Sprintf("(%d, %d)", a, b)) } return a / b, nil @@ -165,7 +165,7 @@ func DivInt64(a int64, b int64) (int64, error) { func DivUintWithInt(a uint64, b int64) (uint64, error) { if b < 0 { if a != 0 && uint64(-b) <= a { - return 0, ErrOverflow.GenByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%d, %d)", a, b)) + return 0, ErrOverflow.GenWithStackByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%d, %d)", a, b)) } return 0, nil @@ -179,7 +179,7 @@ func DivUintWithInt(a uint64, b int64) (uint64, error) { func DivIntWithUint(a int64, b uint64) (uint64, error) { if a < 0 { if uint64(-a) >= b { - return 0, ErrOverflow.GenByArgs("BIGINT", fmt.Sprintf("(%d, %d)", a, b)) + return 0, ErrOverflow.GenWithStackByArgs("BIGINT", fmt.Sprintf("(%d, %d)", a, b)) } return 0, nil diff --git a/types/set.go b/types/set.go index d4b893e7a6ff4..97d065e404160 100644 --- a/types/set.go +++ b/types/set.go @@ -17,7 +17,7 @@ import ( "strconv" "strings" - "github.com/juju/errors" + "github.com/pkg/errors" ) var zeroSet = Set{Name: "", Value: 0} diff --git a/types/time.go b/types/time.go index 7a1d916574982..a9c8a3f5144db 100644 --- a/types/time.go +++ b/types/time.go @@ -23,10 +23,10 @@ import ( gotime "time" "unicode" - "github.com/juju/errors" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/sessionctx/stmtctx" "github.com/pingcap/tidb/terror" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" ) @@ -386,7 +386,7 @@ func (t Time) RoundFrac(sc *stmtctx.StatementContext, fsp int) (Time, error) { // TODO: when hh:mm:ss overflow one day after rounding, it should be add to yy:mm:dd part, // but mm:dd may contain 0, it makes the code complex, so we ignore it here. if t2.Day()-1 > 0 { - return t, errors.Trace(ErrInvalidTimeFormat.GenByArgs(t.String())) + return t, errors.Trace(ErrInvalidTimeFormat.GenWithStackByArgs(t.String())) } nt = FromDate(t.Time.Year(), t.Time.Month(), t.Time.Day(), hour, minute, second, microsecond) } @@ -642,7 +642,7 @@ func parseDatetime(sc *stmtctx.StatementContext, str string, fsp int, isFloat bo _, err = fmt.Sscanf(seps[0], "%2d%2d%2d", &year, &month, &day) year = adjustYear(year) default: - return ZeroDatetime, errors.Trace(ErrInvalidTimeFormat.GenByArgs(str)) + return ZeroDatetime, errors.Trace(ErrInvalidTimeFormat.GenWithStackByArgs(str)) } if l == 6 || l == 8 { // YYMMDD or YYYYMMDD @@ -666,7 +666,7 @@ func parseDatetime(sc *stmtctx.StatementContext, str string, fsp int, isFloat bo _, err = fmt.Sscanf(fracStr, "%2d", &second) default: _, err = fmt.Sscanf(fracStr[:2], "%2d", &second) - sc.AppendWarning(ErrTruncatedWrongValue.GenByArgs("datetime", str)) + sc.AppendWarning(ErrTruncatedWrongValue.GenWithStackByArgs("datetime", str)) } } case 3: @@ -681,7 +681,7 @@ func parseDatetime(sc *stmtctx.StatementContext, str string, fsp int, isFloat bo err = scanTimeArgs(seps, &year, &month, &day, &hour, &minute, &second) hhmmss = true default: - return ZeroDatetime, errors.Trace(ErrInvalidTimeFormat.GenByArgs(str)) + return ZeroDatetime, errors.Trace(ErrInvalidTimeFormat.GenWithStackByArgs(str)) } if err != nil { return ZeroDatetime, errors.Trace(err) @@ -728,7 +728,7 @@ func parseDatetime(sc *stmtctx.StatementContext, str string, fsp int, isFloat bo func scanTimeArgs(seps []string, args ...*int) error { if len(seps) != len(args) { - return errors.Trace(ErrInvalidTimeFormat.GenByArgs(seps)) + return errors.Trace(ErrInvalidTimeFormat.GenWithStackByArgs(seps)) } var err error @@ -1037,7 +1037,7 @@ func ParseDuration(str string, fsp int) (Duration, error) { default: // Maybe contains date. t, err1 := ParseDatetime(nil, str) if err1 != nil { - return ZeroDuration, ErrTruncatedWrongVal.GenByArgs("time", origStr) + return ZeroDuration, ErrTruncatedWrongVal.GenWithStackByArgs("time", origStr) } var dur Duration dur, err1 = t.ConvertToDuration() @@ -1059,7 +1059,7 @@ func ParseDuration(str string, fsp int) (Duration, error) { _, err = fmt.Sscanf(integeralPart, "%2d:%2d:%2d", &hour, &minute, &second) } default: - return ZeroDuration, ErrTruncatedWrongVal.GenByArgs("time", origStr) + return ZeroDuration, ErrTruncatedWrongVal.GenWithStackByArgs("time", origStr) } if err != nil { @@ -1073,7 +1073,7 @@ func ParseDuration(str string, fsp int) (Duration, error) { // Invalid TIME values are converted to '00:00:00'. // See https://dev.mysql.com/doc/refman/5.7/en/time.html if minute >= 60 || second > 60 || (!overflow && second == 60) { - return ZeroDuration, ErrTruncatedWrongVal.GenByArgs("time", origStr) + return ZeroDuration, ErrTruncatedWrongVal.GenWithStackByArgs("time", origStr) } d := gotime.Duration(day*24*3600+hour*3600+minute*60+second)*gotime.Second + gotime.Duration(fracPart)*gotime.Microsecond if sign == -1 { @@ -1087,9 +1087,9 @@ func ParseDuration(str string, fsp int) (Duration, error) { // TruncateOverflowMySQLTime truncates d when it overflows, and return ErrTruncatedWrongVal. func TruncateOverflowMySQLTime(d gotime.Duration) (gotime.Duration, error) { if d > MaxTime { - return MaxTime, ErrTruncatedWrongVal.GenByArgs("time", d.String()) + return MaxTime, ErrTruncatedWrongVal.GenWithStackByArgs("time", d.String()) } else if d < MinTime { - return MinTime, ErrTruncatedWrongVal.GenByArgs("time", d.String()) + return MinTime, ErrTruncatedWrongVal.GenWithStackByArgs("time", d.String()) } return d, nil @@ -1156,7 +1156,7 @@ func parseDateTimeFromNum(sc *stmtctx.StatementContext, num int64) (Time, error) // Check MMDD. if num < 101 { - return t, errors.Trace(ErrInvalidTimeFormat.GenByArgs(num)) + return t, errors.Trace(ErrInvalidTimeFormat.GenWithStackByArgs(num)) } // Adjust year @@ -1168,7 +1168,7 @@ func parseDateTimeFromNum(sc *stmtctx.StatementContext, num int64) (Time, error) // Check YYMMDD. if num < 70*10000+101 { - return t, errors.Trace(ErrInvalidTimeFormat.GenByArgs(num)) + return t, errors.Trace(ErrInvalidTimeFormat.GenWithStackByArgs(num)) } // Adjust year @@ -1180,7 +1180,7 @@ func parseDateTimeFromNum(sc *stmtctx.StatementContext, num int64) (Time, error) // Check YYYYMMDD. if num < 10000101 { - return t, errors.Trace(ErrInvalidTimeFormat.GenByArgs(num)) + return t, errors.Trace(ErrInvalidTimeFormat.GenWithStackByArgs(num)) } // Adjust hour/min/second. @@ -1191,7 +1191,7 @@ func parseDateTimeFromNum(sc *stmtctx.StatementContext, num int64) (Time, error) // Check MMDDHHMMSS. if num < 101000000 { - return t, errors.Trace(ErrInvalidTimeFormat.GenByArgs(num)) + return t, errors.Trace(ErrInvalidTimeFormat.GenWithStackByArgs(num)) } // Set TypeDatetime type. @@ -1206,7 +1206,7 @@ func parseDateTimeFromNum(sc *stmtctx.StatementContext, num int64) (Time, error) // Check YYYYMMDDHHMMSS. if num < 70*10000000000+101000000 { - return t, errors.Trace(ErrInvalidTimeFormat.GenByArgs(num)) + return t, errors.Trace(ErrInvalidTimeFormat.GenWithStackByArgs(num)) } // Adjust year @@ -1335,7 +1335,7 @@ func checkDateType(t MysqlTime, allowZeroInDate bool) error { } if !allowZeroInDate && (month == 0 || day == 0) { - return ErrIncorrectDatetimeValue.GenByArgs(fmt.Sprintf("%04d-%02d-%02d", year, month, day)) + return ErrIncorrectDatetimeValue.GenWithStackByArgs(fmt.Sprintf("%04d-%02d-%02d", year, month, day)) } if err := checkDateRange(t); err != nil { @@ -1353,17 +1353,17 @@ func checkDateRange(t MysqlTime) error { // Oddly enough, MySQL document says date range should larger than '1000-01-01', // but we can insert '0001-01-01' actually. if t.Year() < 0 || t.Month() < 0 || t.Day() < 0 { - return errors.Trace(ErrInvalidTimeFormat.GenByArgs(t)) + return errors.Trace(ErrInvalidTimeFormat.GenWithStackByArgs(t)) } if compareTime(t, MaxDatetime) > 0 { - return errors.Trace(ErrInvalidTimeFormat.GenByArgs(t)) + return errors.Trace(ErrInvalidTimeFormat.GenWithStackByArgs(t)) } return nil } func checkMonthDay(year, month, day int) error { if month < 0 || month > 12 { - return errors.Trace(ErrInvalidTimeFormat.GenByArgs(month)) + return errors.Trace(ErrInvalidTimeFormat.GenWithStackByArgs(month)) } maxDay := 31 @@ -1375,7 +1375,7 @@ func checkMonthDay(year, month, day int) error { } if day < 0 || day > maxDay { - return errors.Trace(ErrInvalidTimeFormat.GenByArgs(day)) + return errors.Trace(ErrInvalidTimeFormat.GenWithStackByArgs(day)) } return nil } @@ -1401,7 +1401,7 @@ func checkTimestampType(sc *stmtctx.StatementContext, t MysqlTime) error { checkTime = t } if compareTime(checkTime, maxTimestamp.Time) > 0 || compareTime(checkTime, MinTimestamp.Time) < 0 { - return errors.Trace(ErrInvalidTimeFormat.GenByArgs(t)) + return errors.Trace(ErrInvalidTimeFormat.GenWithStackByArgs(t)) } if _, err := t.GoTime(gotime.Local); err != nil { @@ -1418,13 +1418,13 @@ func checkDatetimeType(t MysqlTime, allowZeroInDate bool) error { hour, minute, second := t.Hour(), t.Minute(), t.Second() if hour < 0 || hour >= 24 { - return errors.Trace(ErrInvalidTimeFormat.GenByArgs(hour)) + return errors.Trace(ErrInvalidTimeFormat.GenWithStackByArgs(hour)) } if minute < 0 || minute >= 60 { - return errors.Trace(ErrInvalidTimeFormat.GenByArgs(minute)) + return errors.Trace(ErrInvalidTimeFormat.GenWithStackByArgs(minute)) } if second < 0 || second >= 60 { - return errors.Trace(ErrInvalidTimeFormat.GenByArgs(second)) + return errors.Trace(ErrInvalidTimeFormat.GenWithStackByArgs(second)) } return nil @@ -1509,7 +1509,7 @@ func ExtractDurationNum(d *Duration, unit string) (int64, error) { func extractSingleTimeValue(unit string, format string) (int64, int64, int64, gotime.Duration, error) { iv, err := strconv.ParseInt(format, 10, 64) if err != nil { - return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenByArgs(format) + return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenWithStackByArgs(format) } v := gotime.Duration(iv) @@ -1541,17 +1541,17 @@ func extractSingleTimeValue(unit string, format string) (int64, int64, int64, go func extractSecondMicrosecond(format string) (int64, int64, int64, gotime.Duration, error) { fields := strings.Split(format, ".") if len(fields) != 2 { - return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenByArgs(format) + return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenWithStackByArgs(format) } seconds, err := strconv.ParseInt(fields[0], 10, 64) if err != nil { - return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenByArgs(format) + return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenWithStackByArgs(format) } microseconds, err := strconv.ParseInt(alignFrac(fields[1], MaxFsp), 10, 64) if err != nil { - return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenByArgs(format) + return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenWithStackByArgs(format) } return 0, 0, 0, gotime.Duration(seconds)*gotime.Second + gotime.Duration(microseconds)*gotime.Microsecond, nil @@ -1561,12 +1561,12 @@ func extractSecondMicrosecond(format string) (int64, int64, int64, gotime.Durati func extractMinuteMicrosecond(format string) (int64, int64, int64, gotime.Duration, error) { fields := strings.Split(format, ":") if len(fields) != 2 { - return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenByArgs(format) + return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenWithStackByArgs(format) } minutes, err := strconv.ParseInt(fields[0], 10, 64) if err != nil { - return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenByArgs(format) + return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenWithStackByArgs(format) } _, _, _, value, err := extractSecondMicrosecond(fields[1]) @@ -1581,17 +1581,17 @@ func extractMinuteMicrosecond(format string) (int64, int64, int64, gotime.Durati func extractMinuteSecond(format string) (int64, int64, int64, gotime.Duration, error) { fields := strings.Split(format, ":") if len(fields) != 2 { - return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenByArgs(format) + return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenWithStackByArgs(format) } minutes, err := strconv.ParseInt(fields[0], 10, 64) if err != nil { - return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenByArgs(format) + return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenWithStackByArgs(format) } seconds, err := strconv.ParseInt(fields[1], 10, 64) if err != nil { - return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenByArgs(format) + return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenWithStackByArgs(format) } return 0, 0, 0, gotime.Duration(minutes)*gotime.Minute + gotime.Duration(seconds)*gotime.Second, nil @@ -1601,17 +1601,17 @@ func extractMinuteSecond(format string) (int64, int64, int64, gotime.Duration, e func extractHourMicrosecond(format string) (int64, int64, int64, gotime.Duration, error) { fields := strings.Split(format, ":") if len(fields) != 3 { - return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenByArgs(format) + return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenWithStackByArgs(format) } hours, err := strconv.ParseInt(fields[0], 10, 64) if err != nil { - return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenByArgs(format) + return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenWithStackByArgs(format) } minutes, err := strconv.ParseInt(fields[1], 10, 64) if err != nil { - return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenByArgs(format) + return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenWithStackByArgs(format) } _, _, _, value, err := extractSecondMicrosecond(fields[2]) @@ -1626,22 +1626,22 @@ func extractHourMicrosecond(format string) (int64, int64, int64, gotime.Duration func extractHourSecond(format string) (int64, int64, int64, gotime.Duration, error) { fields := strings.Split(format, ":") if len(fields) != 3 { - return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenByArgs(format) + return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenWithStackByArgs(format) } hours, err := strconv.ParseInt(fields[0], 10, 64) if err != nil { - return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenByArgs(format) + return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenWithStackByArgs(format) } minutes, err := strconv.ParseInt(fields[1], 10, 64) if err != nil { - return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenByArgs(format) + return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenWithStackByArgs(format) } seconds, err := strconv.ParseInt(fields[2], 10, 64) if err != nil { - return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenByArgs(format) + return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenWithStackByArgs(format) } return 0, 0, 0, gotime.Duration(hours)*gotime.Hour + gotime.Duration(minutes)*gotime.Minute + gotime.Duration(seconds)*gotime.Second, nil @@ -1651,17 +1651,17 @@ func extractHourSecond(format string) (int64, int64, int64, gotime.Duration, err func extractHourMinute(format string) (int64, int64, int64, gotime.Duration, error) { fields := strings.Split(format, ":") if len(fields) != 2 { - return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenByArgs(format) + return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenWithStackByArgs(format) } hours, err := strconv.ParseInt(fields[0], 10, 64) if err != nil { - return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenByArgs(format) + return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenWithStackByArgs(format) } minutes, err := strconv.ParseInt(fields[1], 10, 64) if err != nil { - return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenByArgs(format) + return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenWithStackByArgs(format) } return 0, 0, 0, gotime.Duration(hours)*gotime.Hour + gotime.Duration(minutes)*gotime.Minute, nil @@ -1671,17 +1671,17 @@ func extractHourMinute(format string) (int64, int64, int64, gotime.Duration, err func extractDayMicrosecond(format string) (int64, int64, int64, gotime.Duration, error) { fields := strings.Split(format, " ") if len(fields) != 2 { - return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenByArgs(format) + return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenWithStackByArgs(format) } days, err := strconv.ParseInt(fields[0], 10, 64) if err != nil { - return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenByArgs(format) + return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenWithStackByArgs(format) } _, _, _, value, err := extractHourMicrosecond(fields[1]) if err != nil { - return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenByArgs(format) + return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenWithStackByArgs(format) } return 0, 0, days, value, nil @@ -1691,17 +1691,17 @@ func extractDayMicrosecond(format string) (int64, int64, int64, gotime.Duration, func extractDaySecond(format string) (int64, int64, int64, gotime.Duration, error) { fields := strings.Split(format, " ") if len(fields) != 2 { - return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenByArgs(format) + return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenWithStackByArgs(format) } days, err := strconv.ParseInt(fields[0], 10, 64) if err != nil { - return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenByArgs(format) + return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenWithStackByArgs(format) } _, _, _, value, err := extractHourSecond(fields[1]) if err != nil { - return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenByArgs(format) + return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenWithStackByArgs(format) } return 0, 0, days, value, nil @@ -1711,17 +1711,17 @@ func extractDaySecond(format string) (int64, int64, int64, gotime.Duration, erro func extractDayMinute(format string) (int64, int64, int64, gotime.Duration, error) { fields := strings.Split(format, " ") if len(fields) != 2 { - return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenByArgs(format) + return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenWithStackByArgs(format) } days, err := strconv.ParseInt(fields[0], 10, 64) if err != nil { - return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenByArgs(format) + return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenWithStackByArgs(format) } _, _, _, value, err := extractHourMinute(fields[1]) if err != nil { - return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenByArgs(format) + return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenWithStackByArgs(format) } return 0, 0, days, value, nil @@ -1731,17 +1731,17 @@ func extractDayMinute(format string) (int64, int64, int64, gotime.Duration, erro func extractDayHour(format string) (int64, int64, int64, gotime.Duration, error) { fields := strings.Split(format, " ") if len(fields) != 2 { - return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenByArgs(format) + return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenWithStackByArgs(format) } days, err := strconv.ParseInt(fields[0], 10, 64) if err != nil { - return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenByArgs(format) + return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenWithStackByArgs(format) } hours, err := strconv.ParseInt(fields[1], 10, 64) if err != nil { - return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenByArgs(format) + return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenWithStackByArgs(format) } return 0, 0, days, gotime.Duration(hours) * gotime.Hour, nil @@ -1751,17 +1751,17 @@ func extractDayHour(format string) (int64, int64, int64, gotime.Duration, error) func extractYearMonth(format string) (int64, int64, int64, gotime.Duration, error) { fields := strings.Split(format, "-") if len(fields) != 2 { - return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenByArgs(format) + return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenWithStackByArgs(format) } years, err := strconv.ParseInt(fields[0], 10, 64) if err != nil { - return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenByArgs(format) + return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenWithStackByArgs(format) } months, err := strconv.ParseInt(fields[1], 10, 64) if err != nil { - return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenByArgs(format) + return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenWithStackByArgs(format) } return years, months, 0, 0, nil @@ -1868,13 +1868,13 @@ func (t Time) convertDateFormat(b rune, buf *bytes.Buffer) error { case 'b': m := t.Time.Month() if m == 0 || m > 12 { - return errors.Trace(ErrInvalidTimeFormat.GenByArgs(m)) + return errors.Trace(ErrInvalidTimeFormat.GenWithStackByArgs(m)) } buf.WriteString(MonthNames[m-1][:3]) case 'M': m := t.Time.Month() if m == 0 || m > 12 { - return errors.Trace(ErrInvalidTimeFormat.GenByArgs(m)) + return errors.Trace(ErrInvalidTimeFormat.GenWithStackByArgs(m)) } buf.WriteString(MonthNames[m-1]) case 'm': @@ -2026,7 +2026,7 @@ func mysqlTimeFix(t *MysqlTime, ctx map[string]int) error { } if valueAMorPm, ok := ctx["%p"]; ok { if t.hour == 0 { - return ErrInvalidTimeFormat.GenByArgs(t) + return ErrInvalidTimeFormat.GenWithStackByArgs(t) } if t.hour == 12 { // 12 is a special hour. diff --git a/util/admin/admin.go b/util/admin/admin.go index 97a0e6d2dac3d..d71434e7bcf3b 100644 --- a/util/admin/admin.go +++ b/util/admin/admin.go @@ -19,7 +19,6 @@ import ( "reflect" "sort" - "github.com/juju/errors" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/meta" @@ -35,6 +34,7 @@ import ( "github.com/pingcap/tidb/util" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/sqlexec" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" ) @@ -369,7 +369,7 @@ func checkIndexAndRecord(sessCtx sessionctx.Context, txn kv.Transaction, t table vals2 = tables.TruncateIndexValuesIfNeeded(t.Meta(), idx.Meta(), vals2) if kv.ErrNotExist.Equal(err) { record := &RecordData{Handle: h, Values: vals1} - err = ErrDataInConsistent.Gen("index:%#v != record:%#v", record, nil) + err = ErrDataInConsistent.GenWithStack("index:%#v != record:%#v", record, nil) } if err != nil { return errors.Trace(err) @@ -378,7 +378,7 @@ func checkIndexAndRecord(sessCtx sessionctx.Context, txn kv.Transaction, t table if !reflect.DeepEqual(vals1, vals2) { record1 := &RecordData{Handle: h, Values: vals1} record2 := &RecordData{Handle: h, Values: vals2} - return ErrDataInConsistent.Gen("index:%#v != record:%#v", record1, record2) + return ErrDataInConsistent.GenWithStack("index:%#v != record:%#v", record1, record2) } } @@ -413,14 +413,14 @@ func CheckRecordAndIndex(sessCtx sessionctx.Context, txn kv.Transaction, t table if kv.ErrKeyExists.Equal(err) { record1 := &RecordData{Handle: h1, Values: vals1} record2 := &RecordData{Handle: h2, Values: vals1} - return false, ErrDataInConsistent.Gen("index:%#v != record:%#v", record2, record1) + return false, ErrDataInConsistent.GenWithStack("index:%#v != record:%#v", record2, record1) } if err != nil { return false, errors.Trace(err) } if !isExist { record := &RecordData{Handle: h1, Values: vals1} - return false, ErrDataInConsistent.Gen("index:%#v != record:%#v", nil, record) + return false, ErrDataInConsistent.GenWithStack("index:%#v != record:%#v", nil, record) } return true, nil @@ -497,7 +497,7 @@ func CompareTableRecord(sessCtx sessionctx.Context, txn kv.Transaction, t table. m := make(map[int64][]types.Datum, len(data)) for _, r := range data { if _, ok := m[r.Handle]; ok { - return errRepeatHandle.Gen("handle:%d is repeated in data", r.Handle) + return errRepeatHandle.GenWithStack("handle:%d is repeated in data", r.Handle) } m[r.Handle] = r.Values } @@ -507,7 +507,7 @@ func CompareTableRecord(sessCtx sessionctx.Context, txn kv.Transaction, t table. vals2, ok := m[h] if !ok { record := &RecordData{Handle: h, Values: vals} - return false, ErrDataInConsistent.Gen("data:%#v != record:%#v", nil, record) + return false, ErrDataInConsistent.GenWithStack("data:%#v != record:%#v", nil, record) } if !exact { delete(m, h) @@ -517,7 +517,7 @@ func CompareTableRecord(sessCtx sessionctx.Context, txn kv.Transaction, t table. if !reflect.DeepEqual(vals, vals2) { record1 := &RecordData{Handle: h, Values: vals2} record2 := &RecordData{Handle: h, Values: vals} - return false, ErrDataInConsistent.Gen("data:%#v != record:%#v", record1, record2) + return false, ErrDataInConsistent.GenWithStack("data:%#v != record:%#v", record1, record2) } delete(m, h) @@ -531,7 +531,7 @@ func CompareTableRecord(sessCtx sessionctx.Context, txn kv.Transaction, t table. for h, vals := range m { record := &RecordData{Handle: h, Values: vals} - return ErrDataInConsistent.Gen("data:%#v != record:%#v", record, nil) + return ErrDataInConsistent.GenWithStack("data:%#v != record:%#v", record, nil) } return nil @@ -552,7 +552,7 @@ func rowWithCols(sessCtx sessionctx.Context, txn kv.Retriever, t table.Table, h continue } if col.State != model.StatePublic { - return nil, errInvalidColumnState.Gen("Cannot use none public column - %v", cols) + return nil, errInvalidColumnState.GenWithStack("Cannot use none public column - %v", cols) } if col.IsPKHandleColumn(t.Meta()) { if mysql.HasUnsignedFlag(col.Flag) { @@ -596,7 +596,7 @@ func rowWithCols(sessCtx sessionctx.Context, txn kv.Retriever, t table.Table, h } if col.State != model.StatePublic { // TODO: check this - return nil, errInvalidColumnState.Gen("Cannot use none public column - %v", cols) + return nil, errInvalidColumnState.GenWithStack("Cannot use none public column - %v", cols) } if col.IsPKHandleColumn(t.Meta()) { continue diff --git a/util/auth/auth.go b/util/auth/auth.go index 26117fd6283ff..0c60b7d67d892 100644 --- a/util/auth/auth.go +++ b/util/auth/auth.go @@ -19,8 +19,8 @@ import ( "encoding/hex" "fmt" - "github.com/juju/errors" "github.com/pingcap/tidb/terror" + "github.com/pkg/errors" ) // UserIdentity represents username and hostname. diff --git a/util/charset/charset.go b/util/charset/charset.go index e4a26ee0424ff..6967b9537a65c 100644 --- a/util/charset/charset.go +++ b/util/charset/charset.go @@ -16,8 +16,8 @@ package charset import ( "strings" - "github.com/juju/errors" "github.com/pingcap/tidb/mysql" + "github.com/pkg/errors" ) // Charset is a charset. diff --git a/util/chunk/list.go b/util/chunk/list.go index afd0bcc28804c..9c89ebbce6ad1 100644 --- a/util/chunk/list.go +++ b/util/chunk/list.go @@ -14,9 +14,9 @@ package chunk import ( - "github.com/juju/errors" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/memory" + "github.com/pkg/errors" ) // List holds a slice of chunks, use to append rows with max chunk size properly handled. diff --git a/util/codec/bytes.go b/util/codec/bytes.go index 6ec0e15d7fb21..0d988c4c69883 100644 --- a/util/codec/bytes.go +++ b/util/codec/bytes.go @@ -18,7 +18,7 @@ import ( "runtime" "unsafe" - "github.com/juju/errors" + "github.com/pkg/errors" ) const ( diff --git a/util/codec/codec.go b/util/codec/codec.go index 1af3817445635..01d330ae8f68e 100644 --- a/util/codec/codec.go +++ b/util/codec/codec.go @@ -17,13 +17,13 @@ import ( "encoding/binary" "time" - "github.com/juju/errors" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/sessionctx/stmtctx" "github.com/pingcap/tidb/terror" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/types/json" "github.com/pingcap/tidb/util/chunk" + "github.com/pkg/errors" ) // First byte in the encoded value which specifies the encoding type. diff --git a/util/codec/decimal.go b/util/codec/decimal.go index b3a2d12e010b8..ed61aa1d5b752 100644 --- a/util/codec/decimal.go +++ b/util/codec/decimal.go @@ -14,8 +14,8 @@ package codec import ( - "github.com/juju/errors" "github.com/pingcap/tidb/types" + "github.com/pkg/errors" ) // EncodeDecimal encodes a decimal into a byte slice which can be sorted lexicographically later. diff --git a/util/codec/float.go b/util/codec/float.go index c2107f166061e..bf846b867c6c8 100644 --- a/util/codec/float.go +++ b/util/codec/float.go @@ -16,7 +16,7 @@ package codec import ( "math" - "github.com/juju/errors" + "github.com/pkg/errors" ) func encodeFloatToCmpUint64(f float64) uint64 { diff --git a/util/codec/number.go b/util/codec/number.go index 39db0c553d5a5..d23117fa3ac10 100644 --- a/util/codec/number.go +++ b/util/codec/number.go @@ -17,7 +17,7 @@ import ( "encoding/binary" "math" - "github.com/juju/errors" + "github.com/pkg/errors" ) const signMask uint64 = 0x8000000000000000 diff --git a/util/encrypt/aes.go b/util/encrypt/aes.go index deeea49e48976..3f0e77061a4bd 100644 --- a/util/encrypt/aes.go +++ b/util/encrypt/aes.go @@ -18,7 +18,7 @@ import ( "crypto/aes" "crypto/cipher" - "github.com/juju/errors" + "github.com/pkg/errors" ) type ecb struct { diff --git a/util/filesort/filesort.go b/util/filesort/filesort.go index 9bb1d137e04ae..6701ca825324e 100644 --- a/util/filesort/filesort.go +++ b/util/filesort/filesort.go @@ -25,11 +25,11 @@ import ( "sync/atomic" "time" - "github.com/juju/errors" "github.com/pingcap/tidb/sessionctx/stmtctx" "github.com/pingcap/tidb/terror" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/codec" + "github.com/pkg/errors" ) type comparableRow struct { diff --git a/util/kvencoder/kv_encoder.go b/util/kvencoder/kv_encoder.go index 9f448980eec6e..9fb4167172619 100644 --- a/util/kvencoder/kv_encoder.go +++ b/util/kvencoder/kv_encoder.go @@ -20,7 +20,6 @@ import ( "sync" "sync/atomic" - "github.com/juju/errors" "github.com/pingcap/tidb/domain" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/meta" @@ -29,6 +28,7 @@ import ( "github.com/pingcap/tidb/session" "github.com/pingcap/tidb/store/mockstore" "github.com/pingcap/tidb/tablecodec" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "golang.org/x/net/context" ) diff --git a/util/kvencoder/kv_encoder_test.go b/util/kvencoder/kv_encoder_test.go index 83f2ac1049d1d..fcd50e0820edf 100644 --- a/util/kvencoder/kv_encoder_test.go +++ b/util/kvencoder/kv_encoder_test.go @@ -23,7 +23,6 @@ import ( "github.com/pingcap/tidb/meta/autoid" "github.com/pingcap/tidb/store/mockstore" - "github.com/juju/errors" . "github.com/pingcap/check" "github.com/pingcap/tidb/domain" "github.com/pingcap/tidb/kv" @@ -35,6 +34,7 @@ import ( "github.com/pingcap/tidb/util/codec" "github.com/pingcap/tidb/util/testkit" "github.com/pingcap/tidb/util/testleak" + "github.com/pkg/errors" ) var _ = Suite(&testKvEncoderSuite{}) diff --git a/util/logutil/log.go b/util/logutil/log.go index 81f3908b0bb07..d9681cd56009b 100644 --- a/util/logutil/log.go +++ b/util/logutil/log.go @@ -22,7 +22,7 @@ import ( "sort" "strings" - "github.com/juju/errors" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "gopkg.in/natefinch/lumberjack.v2" ) diff --git a/util/memory/action.go b/util/memory/action.go index 06a2d39deded8..1873d3c2cca24 100644 --- a/util/memory/action.go +++ b/util/memory/action.go @@ -41,7 +41,7 @@ func (a *LogOnExceed) Action(t *Tracker) { defer a.mutex.Unlock() if !a.acted { a.acted = true - log.Warnf(errMemExceedThreshold.GenByArgs(t.label, t.BytesConsumed(), t.bytesLimit, t.String()).Error()) + log.Warnf(errMemExceedThreshold.GenWithStackByArgs(t.label, t.BytesConsumed(), t.bytesLimit, t.String()).Error()) } } diff --git a/util/misc.go b/util/misc.go index e6210af24ca9b..ffb60cf12ed52 100644 --- a/util/misc.go +++ b/util/misc.go @@ -17,7 +17,7 @@ import ( "runtime" "time" - "github.com/juju/errors" + "github.com/pkg/errors" ) const ( diff --git a/util/misc_test.go b/util/misc_test.go index 5d921f8a0d414..517b34909f295 100644 --- a/util/misc_test.go +++ b/util/misc_test.go @@ -14,9 +14,9 @@ package util import ( - "github.com/juju/errors" . "github.com/pingcap/check" "github.com/pingcap/tidb/util/testleak" + "github.com/pkg/errors" ) var _ = Suite(&testMiscSuite{}) diff --git a/util/mock/context.go b/util/mock/context.go index d28a6016ba870..2eb7631e16769 100644 --- a/util/mock/context.go +++ b/util/mock/context.go @@ -19,7 +19,6 @@ import ( "sync" "time" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/owner" @@ -30,6 +29,7 @@ import ( "github.com/pingcap/tidb/util/kvcache" "github.com/pingcap/tidb/util/sqlexec" binlog "github.com/pingcap/tipb/go-binlog" + "github.com/pkg/errors" "golang.org/x/net/context" ) @@ -97,7 +97,7 @@ func (c *Context) GetClient() kv.Client { func (c *Context) GetGlobalSysVar(ctx sessionctx.Context, name string) (string, error) { v := variable.GetSysVar(name) if v == nil { - return "", variable.UnknownSystemVar.GenByArgs(name) + return "", variable.UnknownSystemVar.GenWithStackByArgs(name) } return v.Value, nil } @@ -106,7 +106,7 @@ func (c *Context) GetGlobalSysVar(ctx sessionctx.Context, name string) (string, func (c *Context) SetGlobalSysVar(ctx sessionctx.Context, name string, value string) error { v := variable.GetSysVar(name) if v == nil { - return variable.UnknownSystemVar.GenByArgs(name) + return variable.UnknownSystemVar.GenWithStackByArgs(name) } v.Value = value return nil diff --git a/util/prefix_helper.go b/util/prefix_helper.go index da91c87362fa9..ccfd1ece9d633 100644 --- a/util/prefix_helper.go +++ b/util/prefix_helper.go @@ -20,8 +20,8 @@ package util import ( "bytes" - "github.com/juju/errors" "github.com/pingcap/tidb/kv" + "github.com/pkg/errors" ) // ScanMetaWithPrefix scans metadata with the prefix. diff --git a/util/ranger/detacher.go b/util/ranger/detacher.go index 5a31ff8328e95..31be5566d0843 100644 --- a/util/ranger/detacher.go +++ b/util/ranger/detacher.go @@ -14,12 +14,12 @@ package ranger import ( - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/model" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/types" + "github.com/pkg/errors" ) // detachColumnCNFConditions detaches the condition for calculating range from the other conditions. diff --git a/util/ranger/points.go b/util/ranger/points.go index ed42ef4503b74..4f31943d88f53 100644 --- a/util/ranger/points.go +++ b/util/ranger/points.go @@ -18,7 +18,6 @@ import ( "math" "sort" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/mysql" @@ -26,6 +25,7 @@ import ( "github.com/pingcap/tidb/terror" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" + "github.com/pkg/errors" ) // Error instances. @@ -302,12 +302,12 @@ func (r *builder) buildFromIn(expr *expression.ScalarFunction) ([]point, bool) { for _, e := range list { v, ok := e.(*expression.Constant) if !ok { - r.err = ErrUnsupportedType.Gen("expr:%v is not constant", e) + r.err = ErrUnsupportedType.GenWithStack("expr:%v is not constant", e) return fullRange, hasNull } dt, err := v.Eval(chunk.Row{}) if err != nil { - r.err = ErrUnsupportedType.Gen("expr:%v is not evaluated", e) + r.err = ErrUnsupportedType.GenWithStack("expr:%v is not evaluated", e) return fullRange, hasNull } if dt.IsNull() { @@ -458,7 +458,7 @@ func (r *builder) buildFromNot(expr *expression.ScalarFunction) []point { return retRangePoints case ast.Like: // Pattern not like is not supported. - r.err = ErrUnsupportedType.Gen("NOT LIKE is not supported.") + r.err = ErrUnsupportedType.GenWithStack("NOT LIKE is not supported.") return fullRange case ast.IsNull: startPoint := point{value: types.MinNotNullDatum(), start: true} diff --git a/util/ranger/ranger.go b/util/ranger/ranger.go index cc9721a100046..2a7c1ca87d7b4 100644 --- a/util/ranger/ranger.go +++ b/util/ranger/ranger.go @@ -19,7 +19,6 @@ import ( "sort" "unicode/utf8" - "github.com/juju/errors" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/kv" @@ -29,6 +28,7 @@ import ( "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/charset" "github.com/pingcap/tidb/util/codec" + "github.com/pkg/errors" ) func validInterval(sc *stmtctx.StatementContext, low, high point) (bool, error) { diff --git a/util/ranger/ranger_test.go b/util/ranger/ranger_test.go index ff91a2666e661..6836f2e57f196 100644 --- a/util/ranger/ranger_test.go +++ b/util/ranger/ranger_test.go @@ -17,7 +17,6 @@ import ( "fmt" "testing" - "github.com/juju/errors" . "github.com/pingcap/check" "github.com/pingcap/tidb/domain" "github.com/pingcap/tidb/expression" @@ -32,6 +31,7 @@ import ( "github.com/pingcap/tidb/util/ranger" "github.com/pingcap/tidb/util/testkit" "github.com/pingcap/tidb/util/testleak" + "github.com/pkg/errors" ) func TestT(t *testing.T) { diff --git a/util/ranger/types.go b/util/ranger/types.go index 8bf178d2a78fb..c17964845d25d 100644 --- a/util/ranger/types.go +++ b/util/ranger/types.go @@ -18,9 +18,9 @@ import ( "math" "strings" - "github.com/juju/errors" "github.com/pingcap/tidb/sessionctx/stmtctx" "github.com/pingcap/tidb/types" + "github.com/pkg/errors" ) // Range represents a range generated in physical plan building phase. diff --git a/util/stringutil/string_util.go b/util/stringutil/string_util.go index c81a8101d8409..6aa22b36736ff 100644 --- a/util/stringutil/string_util.go +++ b/util/stringutil/string_util.go @@ -17,8 +17,8 @@ import ( "strings" "unicode/utf8" - "github.com/juju/errors" "github.com/pingcap/tidb/util/hack" + "github.com/pkg/errors" ) // ErrSyntax indicates that a value does not have the right syntax for the target type. diff --git a/util/testkit/testkit.go b/util/testkit/testkit.go index 4da9712f20860..08cc9a2d87355 100644 --- a/util/testkit/testkit.go +++ b/util/testkit/testkit.go @@ -19,12 +19,12 @@ import ( "sort" "sync/atomic" - "github.com/juju/errors" "github.com/pingcap/check" "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/session" "github.com/pingcap/tidb/util/testutil" + "github.com/pkg/errors" "golang.org/x/net/context" ) diff --git a/vendor/github.com/juju/errors/LICENSE b/vendor/github.com/juju/errors/LICENSE deleted file mode 100644 index ade9307b390c0..0000000000000 --- a/vendor/github.com/juju/errors/LICENSE +++ /dev/null @@ -1,191 +0,0 @@ -All files in this repository are licensed as follows. If you contribute -to this repository, it is assumed that you license your contribution -under the same license unless you state otherwise. - -All files Copyright (C) 2015 Canonical Ltd. unless otherwise specified in the file. - -This software is licensed under the LGPLv3, included below. - -As a special exception to the GNU Lesser General Public License version 3 -("LGPL3"), the copyright holders of this Library give you permission to -convey to a third party a Combined Work that links statically or dynamically -to this Library without providing any Minimal Corresponding Source or -Minimal Application Code as set out in 4d or providing the installation -information set out in section 4e, provided that you comply with the other -provisions of LGPL3 and provided that you meet, for the Application the -terms and conditions of the license(s) which apply to the Application. - -Except as stated in this special exception, the provisions of LGPL3 will -continue to comply in full to this Library. If you modify this Library, you -may apply this exception to your version of this Library, but you are not -obliged to do so. If you do not wish to do so, delete this exception -statement from your version. This exception does not (and cannot) modify any -license terms which apply to the Application, with which you must still -comply. - - - GNU LESSER GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - - This version of the GNU Lesser General Public License incorporates -the terms and conditions of version 3 of the GNU General Public -License, supplemented by the additional permissions listed below. - - 0. Additional Definitions. - - As used herein, "this License" refers to version 3 of the GNU Lesser -General Public License, and the "GNU GPL" refers to version 3 of the GNU -General Public License. - - "The Library" refers to a covered work governed by this License, -other than an Application or a Combined Work as defined below. - - An "Application" is any work that makes use of an interface provided -by the Library, but which is not otherwise based on the Library. -Defining a subclass of a class defined by the Library is deemed a mode -of using an interface provided by the Library. - - A "Combined Work" is a work produced by combining or linking an -Application with the Library. The particular version of the Library -with which the Combined Work was made is also called the "Linked -Version". - - The "Minimal Corresponding Source" for a Combined Work means the -Corresponding Source for the Combined Work, excluding any source code -for portions of the Combined Work that, considered in isolation, are -based on the Application, and not on the Linked Version. - - The "Corresponding Application Code" for a Combined Work means the -object code and/or source code for the Application, including any data -and utility programs needed for reproducing the Combined Work from the -Application, but excluding the System Libraries of the Combined Work. - - 1. Exception to Section 3 of the GNU GPL. - - You may convey a covered work under sections 3 and 4 of this License -without being bound by section 3 of the GNU GPL. - - 2. Conveying Modified Versions. - - If you modify a copy of the Library, and, in your modifications, a -facility refers to a function or data to be supplied by an Application -that uses the facility (other than as an argument passed when the -facility is invoked), then you may convey a copy of the modified -version: - - a) under this License, provided that you make a good faith effort to - ensure that, in the event an Application does not supply the - function or data, the facility still operates, and performs - whatever part of its purpose remains meaningful, or - - b) under the GNU GPL, with none of the additional permissions of - this License applicable to that copy. - - 3. Object Code Incorporating Material from Library Header Files. - - The object code form of an Application may incorporate material from -a header file that is part of the Library. You may convey such object -code under terms of your choice, provided that, if the incorporated -material is not limited to numerical parameters, data structure -layouts and accessors, or small macros, inline functions and templates -(ten or fewer lines in length), you do both of the following: - - a) Give prominent notice with each copy of the object code that the - Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the object code with a copy of the GNU GPL and this license - document. - - 4. Combined Works. - - You may convey a Combined Work under terms of your choice that, -taken together, effectively do not restrict modification of the -portions of the Library contained in the Combined Work and reverse -engineering for debugging such modifications, if you also do each of -the following: - - a) Give prominent notice with each copy of the Combined Work that - the Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the Combined Work with a copy of the GNU GPL and this license - document. - - c) For a Combined Work that displays copyright notices during - execution, include the copyright notice for the Library among - these notices, as well as a reference directing the user to the - copies of the GNU GPL and this license document. - - d) Do one of the following: - - 0) Convey the Minimal Corresponding Source under the terms of this - License, and the Corresponding Application Code in a form - suitable for, and under terms that permit, the user to - recombine or relink the Application with a modified version of - the Linked Version to produce a modified Combined Work, in the - manner specified by section 6 of the GNU GPL for conveying - Corresponding Source. - - 1) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (a) uses at run time - a copy of the Library already present on the user's computer - system, and (b) will operate properly with a modified version - of the Library that is interface-compatible with the Linked - Version. - - e) Provide Installation Information, but only if you would otherwise - be required to provide such information under section 6 of the - GNU GPL, and only to the extent that such information is - necessary to install and execute a modified version of the - Combined Work produced by recombining or relinking the - Application with a modified version of the Linked Version. (If - you use option 4d0, the Installation Information must accompany - the Minimal Corresponding Source and Corresponding Application - Code. If you use option 4d1, you must provide the Installation - Information in the manner specified by section 6 of the GNU GPL - for conveying Corresponding Source.) - - 5. Combined Libraries. - - You may place library facilities that are a work based on the -Library side by side in a single library together with other library -facilities that are not Applications and are not covered by this -License, and convey such a combined library under terms of your -choice, if you do both of the following: - - a) Accompany the combined library with a copy of the same work based - on the Library, uncombined with any other library facilities, - conveyed under the terms of this License. - - b) Give prominent notice with the combined library that part of it - is a work based on the Library, and explaining where to find the - accompanying uncombined form of the same work. - - 6. Revised Versions of the GNU Lesser General Public License. - - The Free Software Foundation may publish revised and/or new versions -of the GNU Lesser General Public License from time to time. Such new -versions will be similar in spirit to the present version, but may -differ in detail to address new problems or concerns. - - Each version is given a distinguishing version number. If the -Library as you received it specifies that a certain numbered version -of the GNU Lesser General Public License "or any later version" -applies to it, you have the option of following the terms and -conditions either of that published version or of any later version -published by the Free Software Foundation. If the Library as you -received it does not specify a version number of the GNU Lesser -General Public License, you may choose any version of the GNU Lesser -General Public License ever published by the Free Software Foundation. - - If the Library as you received it specifies that a proxy can decide -whether future versions of the GNU Lesser General Public License shall -apply, that proxy's public statement of acceptance of any version is -permanent authorization for you to choose that version for the -Library. diff --git a/vendor/github.com/juju/errors/doc.go b/vendor/github.com/juju/errors/doc.go deleted file mode 100644 index 35b119aa34595..0000000000000 --- a/vendor/github.com/juju/errors/doc.go +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright 2013, 2014 Canonical Ltd. -// Licensed under the LGPLv3, see LICENCE file for details. - -/* -[godoc-link-here] - -The juju/errors provides an easy way to annotate errors without losing the -orginal error context. - -The exported `New` and `Errorf` functions are designed to replace the -`errors.New` and `fmt.Errorf` functions respectively. The same underlying -error is there, but the package also records the location at which the error -was created. - -A primary use case for this library is to add extra context any time an -error is returned from a function. - - if err := SomeFunc(); err != nil { - return err - } - -This instead becomes: - - if err := SomeFunc(); err != nil { - return errors.Trace(err) - } - -which just records the file and line number of the Trace call, or - - if err := SomeFunc(); err != nil { - return errors.Annotate(err, "more context") - } - -which also adds an annotation to the error. - -When you want to check to see if an error is of a particular type, a helper -function is normally exported by the package that returned the error, like the -`os` package does. The underlying cause of the error is available using the -`Cause` function. - - os.IsNotExist(errors.Cause(err)) - -The result of the `Error()` call on an annotated error is the annotations joined -with colons, then the result of the `Error()` method for the underlying error -that was the cause. - - err := errors.Errorf("original") - err = errors.Annotatef(err, "context") - err = errors.Annotatef(err, "more context") - err.Error() -> "more context: context: original" - -Obviously recording the file, line and functions is not very useful if you -cannot get them back out again. - - errors.ErrorStack(err) - -will return something like: - - first error - github.com/juju/errors/annotation_test.go:193: - github.com/juju/errors/annotation_test.go:194: annotation - github.com/juju/errors/annotation_test.go:195: - github.com/juju/errors/annotation_test.go:196: more context - github.com/juju/errors/annotation_test.go:197: - -The first error was generated by an external system, so there was no location -associated. The second, fourth, and last lines were generated with Trace calls, -and the other two through Annotate. - -Sometimes when responding to an error you want to return a more specific error -for the situation. - - if err := FindField(field); err != nil { - return errors.Wrap(err, errors.NotFoundf(field)) - } - -This returns an error where the complete error stack is still available, and -`errors.Cause()` will return the `NotFound` error. - -*/ -package errors diff --git a/vendor/github.com/juju/errors/error.go b/vendor/github.com/juju/errors/error.go deleted file mode 100644 index 8c51c45b39e7d..0000000000000 --- a/vendor/github.com/juju/errors/error.go +++ /dev/null @@ -1,145 +0,0 @@ -// Copyright 2014 Canonical Ltd. -// Licensed under the LGPLv3, see LICENCE file for details. - -package errors - -import ( - "fmt" - "reflect" - "runtime" -) - -// Err holds a description of an error along with information about -// where the error was created. -// -// It may be embedded in custom error types to add extra information that -// this errors package can understand. -type Err struct { - // message holds an annotation of the error. - message string - - // cause holds the cause of the error as returned - // by the Cause method. - cause error - - // previous holds the previous error in the error stack, if any. - previous error - - // file and line hold the source code location where the error was - // created. - file string - line int -} - -// NewErr is used to return an Err for the purpose of embedding in other -// structures. The location is not specified, and needs to be set with a call -// to SetLocation. -// -// For example: -// type FooError struct { -// errors.Err -// code int -// } -// -// func NewFooError(code int) error { -// err := &FooError{errors.NewErr("foo"), code} -// err.SetLocation(1) -// return err -// } -func NewErr(format string, args ...interface{}) Err { - return Err{ - message: fmt.Sprintf(format, args...), - } -} - -// NewErrWithCause is used to return an Err with case by other error for the purpose of embedding in other -// structures. The location is not specified, and needs to be set with a call -// to SetLocation. -// -// For example: -// type FooError struct { -// errors.Err -// code int -// } -// -// func (e *FooError) Annotate(format string, args ...interface{}) error { -// err := &FooError{errors.NewErrWithCause(e.Err, format, args...), e.code} -// err.SetLocation(1) -// return err -// }) -func NewErrWithCause(other error, format string, args ...interface{}) Err { - return Err{ - message: fmt.Sprintf(format, args...), - cause: Cause(other), - previous: other, - } -} - -// Location is the file and line of where the error was most recently -// created or annotated. -func (e *Err) Location() (filename string, line int) { - return e.file, e.line -} - -// Underlying returns the previous error in the error stack, if any. A client -// should not ever really call this method. It is used to build the error -// stack and should not be introspected by client calls. Or more -// specifically, clients should not depend on anything but the `Cause` of an -// error. -func (e *Err) Underlying() error { - return e.previous -} - -// The Cause of an error is the most recent error in the error stack that -// meets one of these criteria: the original error that was raised; the new -// error that was passed into the Wrap function; the most recently masked -// error; or nil if the error itself is considered the Cause. Normally this -// method is not invoked directly, but instead through the Cause stand alone -// function. -func (e *Err) Cause() error { - return e.cause -} - -// Message returns the message stored with the most recent location. This is -// the empty string if the most recent call was Trace, or the message stored -// with Annotate or Mask. -func (e *Err) Message() string { - return e.message -} - -// Error implements error.Error. -func (e *Err) Error() string { - // We want to walk up the stack of errors showing the annotations - // as long as the cause is the same. - err := e.previous - if !sameError(Cause(err), e.cause) && e.cause != nil { - err = e.cause - } - switch { - case err == nil: - return e.message - case e.message == "": - return err.Error() - } - return fmt.Sprintf("%s: %v", e.message, err) -} - -// SetLocation records the source location of the error at callDepth stack -// frames above the call. -func (e *Err) SetLocation(callDepth int) { - _, file, line, _ := runtime.Caller(callDepth + 1) - e.file = trimGoPath(file) - e.line = line -} - -// StackTrace returns one string for each location recorded in the stack of -// errors. The first value is the originating error, with a line for each -// other annotation or tracing of the error. -func (e *Err) StackTrace() []string { - return errorStack(e) -} - -// Ideally we'd have a way to check identity, but deep equals will do. -func sameError(e1, e2 error) bool { - return reflect.DeepEqual(e1, e2) -} diff --git a/vendor/github.com/juju/errors/errortypes.go b/vendor/github.com/juju/errors/errortypes.go deleted file mode 100644 index 10b3b19c22af6..0000000000000 --- a/vendor/github.com/juju/errors/errortypes.go +++ /dev/null @@ -1,284 +0,0 @@ -// Copyright 2014 Canonical Ltd. -// Licensed under the LGPLv3, see LICENCE file for details. - -package errors - -import ( - "fmt" -) - -// wrap is a helper to construct an *wrapper. -func wrap(err error, format, suffix string, args ...interface{}) Err { - newErr := Err{ - message: fmt.Sprintf(format+suffix, args...), - previous: err, - } - newErr.SetLocation(2) - return newErr -} - -// notFound represents an error when something has not been found. -type notFound struct { - Err -} - -// NotFoundf returns an error which satisfies IsNotFound(). -func NotFoundf(format string, args ...interface{}) error { - return ¬Found{wrap(nil, format, " not found", args...)} -} - -// NewNotFound returns an error which wraps err that satisfies -// IsNotFound(). -func NewNotFound(err error, msg string) error { - return ¬Found{wrap(err, msg, "")} -} - -// IsNotFound reports whether err was created with NotFoundf() or -// NewNotFound(). -func IsNotFound(err error) bool { - err = Cause(err) - _, ok := err.(*notFound) - return ok -} - -// userNotFound represents an error when an inexistent user is looked up. -type userNotFound struct { - Err -} - -// UserNotFoundf returns an error which satisfies IsUserNotFound(). -func UserNotFoundf(format string, args ...interface{}) error { - return &userNotFound{wrap(nil, format, " user not found", args...)} -} - -// NewUserNotFound returns an error which wraps err and satisfies -// IsUserNotFound(). -func NewUserNotFound(err error, msg string) error { - return &userNotFound{wrap(err, msg, "")} -} - -// IsUserNotFound reports whether err was created with UserNotFoundf() or -// NewUserNotFound(). -func IsUserNotFound(err error) bool { - err = Cause(err) - _, ok := err.(*userNotFound) - return ok -} - -// unauthorized represents an error when an operation is unauthorized. -type unauthorized struct { - Err -} - -// Unauthorizedf returns an error which satisfies IsUnauthorized(). -func Unauthorizedf(format string, args ...interface{}) error { - return &unauthorized{wrap(nil, format, "", args...)} -} - -// NewUnauthorized returns an error which wraps err and satisfies -// IsUnauthorized(). -func NewUnauthorized(err error, msg string) error { - return &unauthorized{wrap(err, msg, "")} -} - -// IsUnauthorized reports whether err was created with Unauthorizedf() or -// NewUnauthorized(). -func IsUnauthorized(err error) bool { - err = Cause(err) - _, ok := err.(*unauthorized) - return ok -} - -// notImplemented represents an error when something is not -// implemented. -type notImplemented struct { - Err -} - -// NotImplementedf returns an error which satisfies IsNotImplemented(). -func NotImplementedf(format string, args ...interface{}) error { - return ¬Implemented{wrap(nil, format, " not implemented", args...)} -} - -// NewNotImplemented returns an error which wraps err and satisfies -// IsNotImplemented(). -func NewNotImplemented(err error, msg string) error { - return ¬Implemented{wrap(err, msg, "")} -} - -// IsNotImplemented reports whether err was created with -// NotImplementedf() or NewNotImplemented(). -func IsNotImplemented(err error) bool { - err = Cause(err) - _, ok := err.(*notImplemented) - return ok -} - -// alreadyExists represents and error when something already exists. -type alreadyExists struct { - Err -} - -// AlreadyExistsf returns an error which satisfies IsAlreadyExists(). -func AlreadyExistsf(format string, args ...interface{}) error { - return &alreadyExists{wrap(nil, format, " already exists", args...)} -} - -// NewAlreadyExists returns an error which wraps err and satisfies -// IsAlreadyExists(). -func NewAlreadyExists(err error, msg string) error { - return &alreadyExists{wrap(err, msg, "")} -} - -// IsAlreadyExists reports whether the error was created with -// AlreadyExistsf() or NewAlreadyExists(). -func IsAlreadyExists(err error) bool { - err = Cause(err) - _, ok := err.(*alreadyExists) - return ok -} - -// notSupported represents an error when something is not supported. -type notSupported struct { - Err -} - -// NotSupportedf returns an error which satisfies IsNotSupported(). -func NotSupportedf(format string, args ...interface{}) error { - return ¬Supported{wrap(nil, format, " not supported", args...)} -} - -// NewNotSupported returns an error which wraps err and satisfies -// IsNotSupported(). -func NewNotSupported(err error, msg string) error { - return ¬Supported{wrap(err, msg, "")} -} - -// IsNotSupported reports whether the error was created with -// NotSupportedf() or NewNotSupported(). -func IsNotSupported(err error) bool { - err = Cause(err) - _, ok := err.(*notSupported) - return ok -} - -// notValid represents an error when something is not valid. -type notValid struct { - Err -} - -// NotValidf returns an error which satisfies IsNotValid(). -func NotValidf(format string, args ...interface{}) error { - return ¬Valid{wrap(nil, format, " not valid", args...)} -} - -// NewNotValid returns an error which wraps err and satisfies IsNotValid(). -func NewNotValid(err error, msg string) error { - return ¬Valid{wrap(err, msg, "")} -} - -// IsNotValid reports whether the error was created with NotValidf() or -// NewNotValid(). -func IsNotValid(err error) bool { - err = Cause(err) - _, ok := err.(*notValid) - return ok -} - -// notProvisioned represents an error when something is not yet provisioned. -type notProvisioned struct { - Err -} - -// NotProvisionedf returns an error which satisfies IsNotProvisioned(). -func NotProvisionedf(format string, args ...interface{}) error { - return ¬Provisioned{wrap(nil, format, " not provisioned", args...)} -} - -// NewNotProvisioned returns an error which wraps err that satisfies -// IsNotProvisioned(). -func NewNotProvisioned(err error, msg string) error { - return ¬Provisioned{wrap(err, msg, "")} -} - -// IsNotProvisioned reports whether err was created with NotProvisionedf() or -// NewNotProvisioned(). -func IsNotProvisioned(err error) bool { - err = Cause(err) - _, ok := err.(*notProvisioned) - return ok -} - -// notAssigned represents an error when something is not yet assigned to -// something else. -type notAssigned struct { - Err -} - -// NotAssignedf returns an error which satisfies IsNotAssigned(). -func NotAssignedf(format string, args ...interface{}) error { - return ¬Assigned{wrap(nil, format, " not assigned", args...)} -} - -// NewNotAssigned returns an error which wraps err that satisfies -// IsNotAssigned(). -func NewNotAssigned(err error, msg string) error { - return ¬Assigned{wrap(err, msg, "")} -} - -// IsNotAssigned reports whether err was created with NotAssignedf() or -// NewNotAssigned(). -func IsNotAssigned(err error) bool { - err = Cause(err) - _, ok := err.(*notAssigned) - return ok -} - -// badRequest represents an error when a request has bad parameters. -type badRequest struct { - Err -} - -// BadRequestf returns an error which satisfies IsBadRequest(). -func BadRequestf(format string, args ...interface{}) error { - return &badRequest{wrap(nil, format, "", args...)} -} - -// NewBadRequest returns an error which wraps err that satisfies -// IsBadRequest(). -func NewBadRequest(err error, msg string) error { - return &badRequest{wrap(err, msg, "")} -} - -// IsBadRequest reports whether err was created with BadRequestf() or -// NewBadRequest(). -func IsBadRequest(err error) bool { - err = Cause(err) - _, ok := err.(*badRequest) - return ok -} - -// methodNotAllowed represents an error when an HTTP request -// is made with an inappropriate method. -type methodNotAllowed struct { - Err -} - -// MethodNotAllowedf returns an error which satisfies IsMethodNotAllowed(). -func MethodNotAllowedf(format string, args ...interface{}) error { - return &methodNotAllowed{wrap(nil, format, "", args...)} -} - -// NewMethodNotAllowed returns an error which wraps err that satisfies -// IsMethodNotAllowed(). -func NewMethodNotAllowed(err error, msg string) error { - return &methodNotAllowed{wrap(err, msg, "")} -} - -// IsMethodNotAllowed reports whether err was created with MethodNotAllowedf() or -// NewMethodNotAllowed(). -func IsMethodNotAllowed(err error) bool { - err = Cause(err) - _, ok := err.(*methodNotAllowed) - return ok -} diff --git a/vendor/github.com/juju/errors/functions.go b/vendor/github.com/juju/errors/functions.go deleted file mode 100644 index 994208d8d77be..0000000000000 --- a/vendor/github.com/juju/errors/functions.go +++ /dev/null @@ -1,330 +0,0 @@ -// Copyright 2014 Canonical Ltd. -// Licensed under the LGPLv3, see LICENCE file for details. - -package errors - -import ( - "fmt" - "strings" -) - -// New is a drop in replacement for the standard libary errors module that records -// the location that the error is created. -// -// For example: -// return errors.New("validation failed") -// -func New(message string) error { - err := &Err{message: message} - err.SetLocation(1) - return err -} - -// Errorf creates a new annotated error and records the location that the -// error is created. This should be a drop in replacement for fmt.Errorf. -// -// For example: -// return errors.Errorf("validation failed: %s", message) -// -func Errorf(format string, args ...interface{}) error { - err := &Err{message: fmt.Sprintf(format, args...)} - err.SetLocation(1) - return err -} - -// Trace adds the location of the Trace call to the stack. The Cause of the -// resulting error is the same as the error parameter. If the other error is -// nil, the result will be nil. -// -// For example: -// if err := SomeFunc(); err != nil { -// return errors.Trace(err) -// } -// -func Trace(other error) error { - if other == nil { - return nil - } - err := &Err{previous: other, cause: Cause(other)} - err.SetLocation(1) - return err -} - -// Annotate is used to add extra context to an existing error. The location of -// the Annotate call is recorded with the annotations. The file, line and -// function are also recorded. -// -// For example: -// if err := SomeFunc(); err != nil { -// return errors.Annotate(err, "failed to frombulate") -// } -// -func Annotate(other error, message string) error { - if other == nil { - return nil - } - err := &Err{ - previous: other, - cause: Cause(other), - message: message, - } - err.SetLocation(1) - return err -} - -// Annotatef is used to add extra context to an existing error. The location of -// the Annotate call is recorded with the annotations. The file, line and -// function are also recorded. -// -// For example: -// if err := SomeFunc(); err != nil { -// return errors.Annotatef(err, "failed to frombulate the %s", arg) -// } -// -func Annotatef(other error, format string, args ...interface{}) error { - if other == nil { - return nil - } - err := &Err{ - previous: other, - cause: Cause(other), - message: fmt.Sprintf(format, args...), - } - err.SetLocation(1) - return err -} - -// DeferredAnnotatef annotates the given error (when it is not nil) with the given -// format string and arguments (like fmt.Sprintf). If *err is nil, DeferredAnnotatef -// does nothing. This method is used in a defer statement in order to annotate any -// resulting error with the same message. -// -// For example: -// -// defer DeferredAnnotatef(&err, "failed to frombulate the %s", arg) -// -func DeferredAnnotatef(err *error, format string, args ...interface{}) { - if *err == nil { - return - } - newErr := &Err{ - message: fmt.Sprintf(format, args...), - cause: Cause(*err), - previous: *err, - } - newErr.SetLocation(1) - *err = newErr -} - -// Wrap changes the Cause of the error. The location of the Wrap call is also -// stored in the error stack. -// -// For example: -// if err := SomeFunc(); err != nil { -// newErr := &packageError{"more context", private_value} -// return errors.Wrap(err, newErr) -// } -// -func Wrap(other, newDescriptive error) error { - err := &Err{ - previous: other, - cause: newDescriptive, - } - err.SetLocation(1) - return err -} - -// Wrapf changes the Cause of the error, and adds an annotation. The location -// of the Wrap call is also stored in the error stack. -// -// For example: -// if err := SomeFunc(); err != nil { -// return errors.Wrapf(err, simpleErrorType, "invalid value %q", value) -// } -// -func Wrapf(other, newDescriptive error, format string, args ...interface{}) error { - err := &Err{ - message: fmt.Sprintf(format, args...), - previous: other, - cause: newDescriptive, - } - err.SetLocation(1) - return err -} - -// Mask masks the given error with the given format string and arguments (like -// fmt.Sprintf), returning a new error that maintains the error stack, but -// hides the underlying error type. The error string still contains the full -// annotations. If you want to hide the annotations, call Wrap. -func Maskf(other error, format string, args ...interface{}) error { - if other == nil { - return nil - } - err := &Err{ - message: fmt.Sprintf(format, args...), - previous: other, - } - err.SetLocation(1) - return err -} - -// Mask hides the underlying error type, and records the location of the masking. -func Mask(other error) error { - if other == nil { - return nil - } - err := &Err{ - previous: other, - } - err.SetLocation(1) - return err -} - -// Cause returns the cause of the given error. This will be either the -// original error, or the result of a Wrap or Mask call. -// -// Cause is the usual way to diagnose errors that may have been wrapped by -// the other errors functions. -func Cause(err error) error { - var diag error - if err, ok := err.(causer); ok { - diag = err.Cause() - } - if diag != nil { - return diag - } - return err -} - -type causer interface { - Cause() error -} - -type wrapper interface { - // Message returns the top level error message, - // not including the message from the Previous - // error. - Message() string - - // Underlying returns the Previous error, or nil - // if there is none. - Underlying() error -} - -type locationer interface { - Location() (string, int) -} - -var ( - _ wrapper = (*Err)(nil) - _ locationer = (*Err)(nil) - _ causer = (*Err)(nil) -) - -// Details returns information about the stack of errors wrapped by err, in -// the format: -// -// [{filename:99: error one} {otherfile:55: cause of error one}] -// -// This is a terse alternative to ErrorStack as it returns a single line. -func Details(err error) string { - if err == nil { - return "[]" - } - var s []byte - s = append(s, '[') - for { - s = append(s, '{') - if err, ok := err.(locationer); ok { - file, line := err.Location() - if file != "" { - s = append(s, fmt.Sprintf("%s:%d", file, line)...) - s = append(s, ": "...) - } - } - if cerr, ok := err.(wrapper); ok { - s = append(s, cerr.Message()...) - err = cerr.Underlying() - } else { - s = append(s, err.Error()...) - err = nil - } - s = append(s, '}') - if err == nil { - break - } - s = append(s, ' ') - } - s = append(s, ']') - return string(s) -} - -// ErrorStack returns a string representation of the annotated error. If the -// error passed as the parameter is not an annotated error, the result is -// simply the result of the Error() method on that error. -// -// If the error is an annotated error, a multi-line string is returned where -// each line represents one entry in the annotation stack. The full filename -// from the call stack is used in the output. -// -// first error -// github.com/juju/errors/annotation_test.go:193: -// github.com/juju/errors/annotation_test.go:194: annotation -// github.com/juju/errors/annotation_test.go:195: -// github.com/juju/errors/annotation_test.go:196: more context -// github.com/juju/errors/annotation_test.go:197: -func ErrorStack(err error) string { - return strings.Join(errorStack(err), "\n") -} - -func errorStack(err error) []string { - if err == nil { - return nil - } - - // We want the first error first - var lines []string - for { - var buff []byte - if err, ok := err.(locationer); ok { - file, line := err.Location() - // Strip off the leading GOPATH/src path elements. - file = trimGoPath(file) - if file != "" { - buff = append(buff, fmt.Sprintf("%s:%d", file, line)...) - buff = append(buff, ": "...) - } - } - if cerr, ok := err.(wrapper); ok { - message := cerr.Message() - buff = append(buff, message...) - // If there is a cause for this error, and it is different to the cause - // of the underlying error, then output the error string in the stack trace. - var cause error - if err1, ok := err.(causer); ok { - cause = err1.Cause() - } - err = cerr.Underlying() - if cause != nil && !sameError(Cause(err), cause) { - if message != "" { - buff = append(buff, ": "...) - } - buff = append(buff, cause.Error()...) - } - } else { - buff = append(buff, err.Error()...) - err = nil - } - lines = append(lines, string(buff)) - if err == nil { - break - } - } - // reverse the lines to get the original error, which was at the end of - // the list, back to the start. - var result []string - for i := len(lines); i > 0; i-- { - result = append(result, lines[i-1]) - } - return result -} diff --git a/vendor/github.com/juju/errors/path.go b/vendor/github.com/juju/errors/path.go deleted file mode 100644 index a7b726ab094c5..0000000000000 --- a/vendor/github.com/juju/errors/path.go +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2013, 2014 Canonical Ltd. -// Licensed under the LGPLv3, see LICENCE file for details. - -package errors - -import ( - "runtime" - "strings" -) - -// prefixSize is used internally to trim the user specific path from the -// front of the returned filenames from the runtime call stack. -var prefixSize int - -// goPath is the deduced path based on the location of this file as compiled. -var goPath string - -func init() { - _, file, _, ok := runtime.Caller(0) - if file == "?" { - return - } - if ok { - // We know that the end of the file should be: - // github.com/juju/errors/path.go - size := len(file) - suffix := len("github.com/juju/errors/path.go") - goPath = file[:size-suffix] - prefixSize = len(goPath) - } -} - -func trimGoPath(filename string) string { - if strings.HasPrefix(filename, goPath) { - return filename[prefixSize:] - } - return filename -} diff --git a/vendor/github.com/pingcap/pd/pd-client/client.go b/vendor/github.com/pingcap/pd/pd-client/client.go index b94328bae4203..31d039558f609 100644 --- a/vendor/github.com/pingcap/pd/pd-client/client.go +++ b/vendor/github.com/pingcap/pd/pd-client/client.go @@ -135,10 +135,10 @@ func NewClient(pdAddrs []string, security SecurityOption) (Client, error) { c.connMu.clientConns = make(map[string]*grpc.ClientConn) if err := c.initClusterID(); err != nil { - return nil, errors.WithStack(err) + return nil, err } if err := c.updateLeader(); err != nil { - return nil, errors.WithStack(err) + return nil, err } log.Infof("[pd] init cluster id %v", c.clusterID) @@ -192,10 +192,7 @@ func (c *client) updateLeader() error { } } c.updateURLs(members.GetMembers()) - if err = c.switchLeader(members.GetLeader().GetClientUrls()); err != nil { - return errors.WithStack(err) - } - return nil + return c.switchLeader(members.GetLeader().GetClientUrls()) } return errors.Errorf("failed to get leader from %v", c.urls) } @@ -203,7 +200,7 @@ func (c *client) updateLeader() error { func (c *client) getMembers(ctx context.Context, url string) (*pdpb.GetMembersResponse, error) { cc, err := c.getOrCreateGRPCConn(url) if err != nil { - return nil, errors.WithStack(err) + return nil, err } members, err := pdpb.NewPDClient(cc).GetMembers(ctx, &pdpb.GetMembersRequest{}) if err != nil { @@ -226,7 +223,7 @@ func (c *client) switchLeader(addrs []string) error { log.Infof("[pd] leader switches to: %v, previous: %v", addr, oldLeader) if _, err := c.getOrCreateGRPCConn(addr); err != nil { - return errors.WithStack(err) + return err } c.connMu.Lock() @@ -370,7 +367,7 @@ func (c *client) tsLoop() { log.Errorf("[pd] create tso stream error: %v", err) c.ScheduleCheckLeader() cancel() - c.revokeTSORequest(err) + c.revokeTSORequest(errors.WithStack(err)) select { case <-time.After(time.Second): case <-loopCtx.Done(): @@ -443,21 +440,21 @@ func (c *client) processTSORequests(stream pdpb.PD_TsoClient, requests []*tsoReq } if err := stream.Send(req); err != nil { + err = errors.WithStack(err) c.finishTSORequest(requests, 0, 0, err) - return errors.WithStack(err) + return err } resp, err := stream.Recv() if err != nil { - c.finishTSORequest(requests, 0, 0, errors.WithStack(err)) - return errors.WithStack(err) + err = errors.WithStack(err) + c.finishTSORequest(requests, 0, 0, err) + return err } requestDuration.WithLabelValues("tso").Observe(time.Since(start).Seconds()) - if err == nil && resp.GetCount() != uint32(len(requests)) { - err = errTSOLength - } - if err != nil { - c.finishTSORequest(requests, 0, 0, errors.WithStack(err)) - return errors.WithStack(err) + if resp.GetCount() != uint32(len(requests)) { + err = errors.WithStack(errTSOLength) + c.finishTSORequest(requests, 0, 0, err) + return err } physical, logical := resp.GetTimestamp().GetPhysical(), resp.GetTimestamp().GetLogical() @@ -481,7 +478,7 @@ func (c *client) revokeTSORequest(err error) { n := len(c.tsoRequests) for i := 0; i < n; i++ { req := <-c.tsoRequests - req.done <- errors.WithStack(err) + req.done <- err } } @@ -489,7 +486,7 @@ func (c *client) Close() { c.cancel() c.wg.Wait() - c.revokeTSORequest(errClosing) + c.revokeTSORequest(errors.WithStack(errClosing)) c.connMu.Lock() defer c.connMu.Unlock() @@ -565,10 +562,11 @@ func (req *tsoRequest) Wait() (physical int64, logical int64, err error) { cmdDuration.WithLabelValues("tso_async_wait").Observe(time.Since(req.start).Seconds()) select { case err = <-req.done: + err = errors.WithStack(err) defer tsoReqPool.Put(req) if err != nil { cmdFailedDuration.WithLabelValues("tso").Observe(time.Since(req.start).Seconds()) - return 0, 0, errors.WithStack(err) + return 0, 0, err } physical, logical = req.physical, req.logical cmdDuration.WithLabelValues("tso").Observe(time.Since(req.start).Seconds()) diff --git a/vendor/github.com/pkg/errors/errors.go b/vendor/github.com/pkg/errors/errors.go index 842ee80456dba..0168061fd5276 100644 --- a/vendor/github.com/pkg/errors/errors.go +++ b/vendor/github.com/pkg/errors/errors.go @@ -13,24 +13,24 @@ // // Adding context to an error // -// The errors.Wrap function returns a new error that adds context to the -// original error by recording a stack trace at the point Wrap is called, +// The errors.Annotate function returns a new error that adds context to the +// original error by recording a stack trace at the point Annotate is called, // and the supplied message. For example // // _, err := ioutil.ReadAll(r) // if err != nil { -// return errors.Wrap(err, "read failed") +// return errors.Annotate(err, "read failed") // } // -// If additional control is required the errors.WithStack and errors.WithMessage -// functions destructure errors.Wrap into its component operations of annotating +// If additional control is required the errors.AddStack and errors.WithMessage +// functions destructure errors.Annotate into its component operations of annotating // an error with a stack trace and an a message, respectively. // // Retrieving the cause of an error // -// Using errors.Wrap constructs a stack of errors, adding context to the +// Using errors.Annotate constructs a stack of errors, adding context to the // preceding error. Depending on the nature of the error it may be necessary -// to reverse the operation of errors.Wrap to retrieve the original error +// to reverse the operation of errors.Annotate to retrieve the original error // for inspection. Any error value which implements this interface // // type causer interface { @@ -50,6 +50,7 @@ // // causer interface is not exported by this package, but is considered a part // of stable public API. +// errors.Unwrap is also available: this will retrieve the next error in the chain. // // Formatted printing of errors // @@ -64,14 +65,9 @@ // // Retrieving the stack trace of an error or wrapper // -// New, Errorf, Wrap, and Wrapf record a stack trace at the point they are -// invoked. This information can be retrieved with the following interface. -// -// type stackTracer interface { -// StackTrace() errors.StackTrace -// } -// -// Where errors.StackTrace is defined as +// New, Errorf, Annotate, and Annotatef record a stack trace at the point they are invoked. +// This information can be retrieved with the StackTracer interface that returns +// a StackTrace. Where errors.StackTrace is defined as // // type StackTrace []Frame // @@ -79,16 +75,15 @@ // the fmt.Formatter interface that can be used for printing information about // the stack trace of this error. For example: // -// if err, ok := err.(stackTracer); ok { -// for _, f := range err.StackTrace() { +// if stacked := errors.GetStackTracer(err); stacked != nil { +// for _, f := range stacked.StackTrace() { // fmt.Printf("%+s:%d", f) // } // } // -// stackTracer interface is not exported by this package, but is considered a part -// of stable public API. -// // See the documentation for Frame.Format for more details. +// +// errors.Find can be used to search for an error in the error chain. package errors import ( @@ -115,6 +110,21 @@ func Errorf(format string, args ...interface{}) error { } } +// StackTraceAware is an optimization to avoid repetitive traversals of an error chain. +// HasStack checks for this marker first. +// Annotate/Wrap and Annotatef/Wrapf will produce this marker. +type StackTraceAware interface { + HasStack() bool +} + +// HasStack tells whether a StackTracer exists in the error chain +func HasStack(err error) bool { + if errWithStack, ok := err.(StackTraceAware); ok { + return errWithStack.HasStack() + } + return GetStackTracer(err) != nil +} + // fundamental is an error that has a message and a stack, but no caller. type fundamental struct { msg string @@ -141,16 +151,44 @@ func (f *fundamental) Format(s fmt.State, verb rune) { // WithStack annotates err with a stack trace at the point WithStack was called. // If err is nil, WithStack returns nil. +// +// Deprecated: use AddStack func WithStack(err error) error { if err == nil { return nil } + return &withStack{ err, callers(), } } +// AddStack is similar to WithStack. +// However, it will first check with HasStack to see if a stack trace already exists in the causer chain before creating another one. +func AddStack(err error) error { + if HasStack(err) { + return err + } + return WithStack(err) +} + +// GetStackTracer will return the first StackTracer in the causer chain. +// This function is used by AddStack to avoid creating redundant stack traces. +// +// You can also use the StackTracer interface on the returned error to get the stack trace. +func GetStackTracer(origErr error) StackTracer { + var stacked StackTracer + WalkDeep(origErr, func(err error) bool { + if stackTracer, ok := err.(StackTracer); ok { + stacked = stackTracer + return true + } + return false + }) + return stacked +} + type withStack struct { error *stack @@ -175,15 +213,19 @@ func (w *withStack) Format(s fmt.State, verb rune) { } // Wrap returns an error annotating err with a stack trace -// at the point Wrap is called, and the supplied message. -// If err is nil, Wrap returns nil. +// at the point Annotate is called, and the supplied message. +// If err is nil, Annotate returns nil. +// +// Deprecated: use Annotate instead func Wrap(err error, message string) error { if err == nil { return nil } + hasStack := HasStack(err) err = &withMessage{ - cause: err, - msg: message, + cause: err, + msg: message, + causeHasStack: hasStack, } return &withStack{ err, @@ -192,15 +234,19 @@ func Wrap(err error, message string) error { } // Wrapf returns an error annotating err with a stack trace -// at the point Wrapf is call, and the format specifier. -// If err is nil, Wrapf returns nil. +// at the point Annotatef is call, and the format specifier. +// If err is nil, Annotatef returns nil. +// +// Deprecated: use Annotatef instead func Wrapf(err error, format string, args ...interface{}) error { if err == nil { return nil } + hasStack := HasStack(err) err = &withMessage{ - cause: err, - msg: fmt.Sprintf(format, args...), + cause: err, + msg: fmt.Sprintf(format, args...), + causeHasStack: hasStack, } return &withStack{ err, @@ -215,18 +261,21 @@ func WithMessage(err error, message string) error { return nil } return &withMessage{ - cause: err, - msg: message, + cause: err, + msg: message, + causeHasStack: HasStack(err), } } type withMessage struct { - cause error - msg string + cause error + msg string + causeHasStack bool } -func (w *withMessage) Error() string { return w.msg + ": " + w.cause.Error() } -func (w *withMessage) Cause() error { return w.cause } +func (w *withMessage) Error() string { return w.msg + ": " + w.cause.Error() } +func (w *withMessage) Cause() error { return w.cause } +func (w *withMessage) HasStack() bool { return w.causeHasStack } func (w *withMessage) Format(s fmt.State, verb rune) { switch verb { @@ -254,16 +303,35 @@ func (w *withMessage) Format(s fmt.State, verb rune) { // be returned. If the error is nil, nil will be returned without further // investigation. func Cause(err error) error { + cause := Unwrap(err) + if cause == nil { + return err + } + return Cause(cause) +} + +// Unwrap uses causer to return the next error in the chain or nil. +// This goes one-level deeper, whereas Cause goes as far as possible +func Unwrap(err error) error { type causer interface { Cause() error } + if unErr, ok := err.(causer); ok { + return unErr.Cause() + } + return nil +} - for err != nil { - cause, ok := err.(causer) - if !ok { - break +// Find an error in the chain that matches a test function. +// returns nil if no error is found. +func Find(origErr error, test func(error) bool) error { + var foundErr error + WalkDeep(origErr, func(err error) bool { + if test(err) { + foundErr = err + return true } - err = cause.Cause() - } - return err + return false + }) + return foundErr } diff --git a/vendor/github.com/pkg/errors/group.go b/vendor/github.com/pkg/errors/group.go new file mode 100644 index 0000000000000..003932c95e865 --- /dev/null +++ b/vendor/github.com/pkg/errors/group.go @@ -0,0 +1,33 @@ +package errors + +// ErrorGroup is an interface for multiple errors that are not a chain. +// This happens for example when executing multiple operations in parallel. +type ErrorGroup interface { + Errors() []error +} + +// WalkDeep does a depth-first traversal of all errors. +// Any ErrorGroup is traversed (after going deep). +// The visitor function can return true to end the traversal early +// In that case, WalkDeep will return true, otherwise false. +func WalkDeep(err error, visitor func(err error) bool) bool { + // Go deep + unErr := err + for unErr != nil { + if done := visitor(unErr); done { + return true + } + unErr = Unwrap(unErr) + } + + // Go wide + if group, ok := err.(ErrorGroup); ok { + for _, err := range group.Errors() { + if early := WalkDeep(err, visitor); early { + return true + } + } + } + + return false +} diff --git a/vendor/github.com/pkg/errors/juju_adaptor.go b/vendor/github.com/pkg/errors/juju_adaptor.go new file mode 100644 index 0000000000000..773a1970866c7 --- /dev/null +++ b/vendor/github.com/pkg/errors/juju_adaptor.go @@ -0,0 +1,76 @@ +package errors + +import ( + "fmt" +) + +// ==================== juju adaptor start ======================== + +// Trace annotates err with a stack trace at the point WithStack was called. +// If err is nil or already contain stack trace return directly. +func Trace(err error) error { + return AddStack(err) +} + +func Annotate(err error, message string) error { + if err == nil { + return nil + } + hasStack := HasStack(err) + err = &withMessage{ + cause: err, + msg: message, + causeHasStack: hasStack, + } + if hasStack { + return err + } + return &withStack{ + err, + callers(), + } +} + +func Annotatef(err error, format string, args ...interface{}) error { + if err == nil { + return nil + } + hasStack := HasStack(err) + err = &withMessage{ + cause: err, + msg: fmt.Sprintf(format, args...), + causeHasStack: hasStack, + } + if hasStack { + return err + } + return &withStack{ + err, + callers(), + } +} + +// ErrorStack will format a stack trace if it is available, otherwise it will be Error() +func ErrorStack(err error) string { + if err == nil { + return "" + } + return fmt.Sprintf("%+v", err) +} + +// NotFoundf represents an error with not found message. +func NotFoundf(format string, args ...interface{}) error { + return Errorf(format+" not found", args...) +} + +// BadRequestf represents an error with bad request message. +func BadRequestf(format string, args ...interface{}) error { + return Errorf(format+" bad request", args...) +} + +// NotSupportedf represents an error with not supported message. +func NotSupportedf(format string, args ...interface{}) error { + return Errorf(format+" not supported", args...) +} + +// ==================== juju adaptor end ======================== diff --git a/vendor/github.com/pkg/errors/stack.go b/vendor/github.com/pkg/errors/stack.go index 6b1f2891a5ac0..6edd7e5699f79 100644 --- a/vendor/github.com/pkg/errors/stack.go +++ b/vendor/github.com/pkg/errors/stack.go @@ -8,6 +8,12 @@ import ( "strings" ) +// StackTracer retrieves the StackTrace +// Generally you would want to use the GetStackTracer function to do that. +type StackTracer interface { + StackTrace() StackTrace +} + // Frame represents a program counter inside a stack frame. type Frame uintptr @@ -46,7 +52,8 @@ func (f Frame) line() int { // // Format accepts flags that alter the printing of some verbs, as follows: // -// %+s path of source file relative to the compile time GOPATH +// %+s function name and path of source file relative to the compile time +// GOPATH separated by \n\t (\n\t) // %+v equivalent to %+s:%d func (f Frame) Format(s fmt.State, verb rune) { switch verb { @@ -79,6 +86,14 @@ func (f Frame) Format(s fmt.State, verb rune) { // StackTrace is stack of Frames from innermost (newest) to outermost (oldest). type StackTrace []Frame +// Format formats the stack of Frames according to the fmt.Formatter interface. +// +// %s lists source files for each Frame in the stack +// %v lists the source file and line number for each Frame in the stack +// +// Format accepts flags that alter the printing of some verbs, as follows: +// +// %+v Prints filename, function, and line number for each Frame in the stack. func (st StackTrace) Format(s fmt.State, verb rune) { switch verb { case 'v': @@ -122,9 +137,13 @@ func (s *stack) StackTrace() StackTrace { } func callers() *stack { + return callersSkip(4) +} + +func callersSkip(skip int) *stack { const depth = 32 var pcs [depth]uintptr - n := runtime.Callers(3, pcs[:]) + n := runtime.Callers(skip, pcs[:]) var st stack = pcs[0:n] return &st } @@ -137,42 +156,15 @@ func funcname(name string) string { return name[i+1:] } -func trimGOPATH(name, file string) string { - // Here we want to get the source file path relative to the compile time - // GOPATH. As of Go 1.6.x there is no direct way to know the compiled - // GOPATH at runtime, but we can infer the number of path segments in the - // GOPATH. We note that fn.Name() returns the function name qualified by - // the import path, which does not include the GOPATH. Thus we can trim - // segments from the beginning of the file path until the number of path - // separators remaining is one more than the number of path separators in - // the function name. For example, given: - // - // GOPATH /home/user - // file /home/user/src/pkg/sub/file.go - // fn.Name() pkg/sub.Type.Method - // - // We want to produce: - // - // pkg/sub/file.go - // - // From this we can easily see that fn.Name() has one less path separator - // than our desired output. We count separators from the end of the file - // path until it finds two more than in the function name and then move - // one character forward to preserve the initial path segment without a - // leading separator. - const sep = "/" - goal := strings.Count(name, sep) + 2 - i := len(file) - for n := 0; n < goal; n++ { - i = strings.LastIndex(file[:i], sep) - if i == -1 { - // not enough separators found, set i so that the slice expression - // below leaves file unmodified - i = -len(sep) - break - } - } - // get back to 0 or trim the leading separator - file = file[i+len(sep):] - return file +// NewStack is for library implementers that want to generate a stack trace. +// Normally you should insted use AddStack to get an error with a stack trace. +// +// The result of this function can be turned into a stack trace by calling .StackTrace() +// +// This function takes an argument for the number of stack frames to skip. +// This avoids putting stack generation function calls like this one in the stack trace. +// A value of 0 will give you the line that called NewStack(0) +// A library author wrapping this in their own function will want to use a value of at least 1. +func NewStack(skip int) StackTracer { + return callersSkip(skip + 3) } diff --git a/x-server/conn.go b/x-server/conn.go index 8a27ae588b47d..cf17b745733d1 100644 --- a/x-server/conn.go +++ b/x-server/conn.go @@ -17,9 +17,9 @@ import ( "io" "net" - "github.com/juju/errors" "github.com/pingcap/tidb/terror" "github.com/pingcap/tidb/util/arena" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" ) diff --git a/x-server/server.go b/x-server/server.go index 115a8b4566d78..9e460a306ae19 100644 --- a/x-server/server.go +++ b/x-server/server.go @@ -20,12 +20,12 @@ import ( "sync/atomic" "time" - "github.com/juju/errors" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/server" "github.com/pingcap/tidb/terror" "github.com/pingcap/tidb/util" "github.com/pingcap/tidb/util/arena" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" )