From a3875bcbc94f97b4e3d96bd6639d217d19714362 Mon Sep 17 00:00:00 2001 From: you06 Date: Thu, 13 Jul 2023 13:48:52 +0800 Subject: [PATCH] Match error message correctly (#887) Signed-off-by: you06 --- internal/locate/region_request.go | 3 ++- internal/locate/region_request3_test.go | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/locate/region_request.go b/internal/locate/region_request.go index a4a612029..e05a5a820 100644 --- a/internal/locate/region_request.go +++ b/internal/locate/region_request.go @@ -1657,7 +1657,8 @@ func regionErrorToLabel(e *errorpb.Error) string { return "flashback_not_prepared" } else if e.GetIsWitness() != nil { return "peer_is_witness" - } else if strings.HasPrefix(e.Message, "mismatch peer id") { + } else if strings.Contains(e.Message, "mismatch peer id") { + // the error message is like "[components/raftstore/src/store/util.rs:428]: mismatch peer id ? != ?" // the `mismatch peer id` error does not has a specific error type, so we have to match the error message. // TODO: add a specific error type for `mismatch peer id`. return "mismatch_peer_id" diff --git a/internal/locate/region_request3_test.go b/internal/locate/region_request3_test.go index f82d8cae5..5bad3f3e9 100644 --- a/internal/locate/region_request3_test.go +++ b/internal/locate/region_request3_test.go @@ -1067,7 +1067,7 @@ func (s *testRegionRequestToThreeStoresSuite) TestReplicaReadFallbackToLeaderReg // Return `mismatch peer id` when accesses the leader. if addr == s.cluster.GetStore(s.storeIDs[0]).Address { return &tikvrpc.Response{Resp: &kvrpcpb.GetResponse{RegionError: &errorpb.Error{ - Message: "mismatch peer id 1 != 2", + Message: `"[components/raftstore/src/store/util.rs:428]: mismatch peer id 1 != 2"`, }}}, nil } return &tikvrpc.Response{Resp: &kvrpcpb.GetResponse{RegionError: &errorpb.Error{