From f3e35a06e1e6972796f774ad6f444a50a9844213 Mon Sep 17 00:00:00 2001 From: Georgy Moshkin <gmoshkin@picodata.io> Date: Tue, 9 Jul 2024 16:29:56 +0300 Subject: [PATCH] fix: tweak NoSuchReplicaset error --- picoplugin/src/error_code.rs | 1 + src/traft/error.rs | 5 ++++- test/conftest.py | 1 + test/int/test_plugin.py | 10 +++++----- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/picoplugin/src/error_code.rs b/picoplugin/src/error_code.rs index 6c23eb3399..0de0c5db2a 100644 --- a/picoplugin/src/error_code.rs +++ b/picoplugin/src/error_code.rs @@ -36,6 +36,7 @@ tarantool::define_enum_with_introspection! { WrongPluginVersion = 10015, NoSuchInstance = 10016, + NoSuchReplicaset = 10017, // TODO: put in particular compare-and-swap related ones, but also other ones diff --git a/src/traft/error.rs b/src/traft/error.rs index 8cbb7f6f6f..02e7028a8c 100644 --- a/src/traft/error.rs +++ b/src/traft/error.rs @@ -54,7 +54,7 @@ pub enum Error { Tarantool(#[from] ::tarantool::error::Error), #[error("instance with {} not found", DisplayIdOfInstance(.0))] NoSuchInstance(Result<RaftId, InstanceId>), - #[error("replicaset with {} \"{id}\" not found", if *.id_is_uuid { "uuid" } else { "id" })] + #[error("replicaset with {} \"{id}\" not found", if *.id_is_uuid { "replicaset_uuid" } else { "replicaset_id" })] NoSuchReplicaset { id: String, id_is_uuid: bool }, #[error("address of peer with id {0} not found")] AddressUnknownForRaftId(RaftId), @@ -207,6 +207,9 @@ impl IntoBoxError for Error { Self::NoSuchInstance { .. } => { BoxError::new(ErrorCode::NoSuchInstance, self.to_string()) } + Self::NoSuchReplicaset { .. } => { + BoxError::new(ErrorCode::NoSuchReplicaset, self.to_string()) + } // TODO: give other error types specific codes other => BoxError::new(ErrorCode::Other, other.to_string()), } diff --git a/test/conftest.py b/test/conftest.py index 855a4193ba..4ff0dbcd3f 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -59,6 +59,7 @@ PICO_SERVICE_ID = 32 class ErrorCode: Loading = 116 NoSuchInstance = 10016 + NoSuchReplicaset = 10017 def eprint(*args, **kwargs): diff --git a/test/int/test_plugin.py b/test/int/test_plugin.py index e6a32f5c39..c8bdb09248 100644 --- a/test/int/test_plugin.py +++ b/test/int/test_plugin.py @@ -1810,11 +1810,7 @@ def test_plugin_rpc_sdk_send_request(cluster: Cluster): ) # Check requesting RPC to unknown replicaset - with pytest.raises( - TarantoolError, - # FIXME: do a better error message - match='replicaset with id "NO_SUCH_REPLICASET" not found', - ): + with pytest.raises(TarantoolError) as e: context = make_context() input = dict( path="/ping", @@ -1822,6 +1818,10 @@ def test_plugin_rpc_sdk_send_request(cluster: Cluster): input=msgpack.dumps([]), ) i1.call(".proc_rpc_dispatch", "/proxy", msgpack.dumps(input), context) + assert e.value.args[:2] == ( + ErrorCode.NoSuchReplicaset, + 'replicaset with replicaset_id "NO_SUCH_REPLICASET" not found', + ) # Check requesting RPC to unknown bucket id with pytest.raises( -- GitLab