From 3c609337ea421dfdd1400f2712e93a03703041e6 Mon Sep 17 00:00:00 2001 From: Georgy Moshkin <gmoshkin@picodata.io> Date: Tue, 18 Jul 2023 20:07:26 +0300 Subject: [PATCH] rename: change up error messages so they are easier to parse from strings --- src/cas.rs | 16 ++++++++++------ src/traft/error.rs | 8 ++++++-- test/int/test_cas.py | 12 ++++++------ 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/cas.rs b/src/cas.rs index 4ffe908bb2..2ee1417979 100644 --- a/src/cas.rs +++ b/src/cas.rs @@ -288,43 +288,47 @@ crate::define_rpc_request! { /// Usually it can't be handled and should be either retried from /// scratch or returned to a user as is. /// +// NOTE: these error messages are relied on in luamod.lua, +// don't forget to update them everywhere if you're changing them. #[derive(Debug, ::thiserror::Error)] pub enum Error { /// Can't check the predicate because raft log is compacted. - #[error("raft index {requested} is compacted at {compacted_index}")] + #[error("Compacted: raft index {requested} is compacted at {compacted_index}")] Compacted { requested: RaftIndex, compacted_index: RaftIndex, }, /// Nearly impossible error indicating invalid request. - #[error("raft entry at index {requested} does not exist yet, the last is {last_index}")] + #[error( + "NoSuchIndex: raft entry at index {requested} does not exist yet, the last is {last_index}" + )] NoSuchIndex { requested: RaftIndex, last_index: RaftIndex, }, /// Checking the predicate revealed a collision. - #[error("comparison failed for index {requested} as it conflicts with {conflict_index}")] + #[error("ConflictFound: comparison failed for index {requested} as it conflicts with {conflict_index}")] ConflictFound { requested: RaftIndex, conflict_index: RaftIndex, }, /// Checking the predicate revealed a collision. - #[error("entry at index {index} has term {actual_term}, request implies term {expected_term}")] + #[error("EntryTermMismatch: entry at index {index} has term {actual_term}, request implies term {expected_term}")] EntryTermMismatch { index: RaftIndex, expected_term: RaftTerm, actual_term: RaftTerm, }, - #[error("space {space} is prohibited for use in a predicate")] + #[error("SpaceNotAllowed: space {space} is prohibited for use in a predicate")] SpaceNotAllowed { space: String }, /// An error related to `key_def` operation arised from tarantool /// depths while checking the predicate. - #[error("failed comparing predicate ranges: {0}")] + #[error("KeyTypeMismatch: failed comparing predicate ranges: {0}")] KeyTypeMismatch(#[from] TntError), } diff --git a/src/traft/error.rs b/src/traft/error.rs index 0ccfc5fb4f..7915c205d8 100644 --- a/src/traft/error.rs +++ b/src/traft/error.rs @@ -35,11 +35,15 @@ pub enum Error { instance_rsid: String, requested_rsid: String, }, + // NOTE: this error message is relied on in luamod.lua, + // don't forget to update it everywhere if you're changing it. #[error("operation request from different term {requested}, current term is {current}")] TermMismatch { requested: RaftTerm, current: RaftTerm, }, + // NOTE: this error message is relied on in luamod.lua, + // don't forget to update it everywhere if you're changing it. #[error("not a leader")] NotALeader, #[error("lua error: {0}")] @@ -61,7 +65,7 @@ pub enum Error { #[error("governor has stopped")] GovernorStopped, - #[error("compare-and-swap request failed: {0}")] + #[error("compare-and-swap: {0}")] Cas(#[from] crate::cas::Error), #[error("ddl failed: {0}")] Ddl(#[from] crate::schema::DdlError), @@ -86,7 +90,7 @@ impl Error { /// Temporary solution until proc_cas returns structured errors pub fn is_cas_err(&self) -> bool { - self.to_string().contains("compare-and-swap request failed") + self.to_string().contains("compare-and-swap") } /// Temporary solution until proc_cas returns structured errors diff --git a/test/int/test_cas.py b/test/int/test_cas.py index e4bfc8cb00..5e1198dd0a 100644 --- a/test/int/test_cas.py +++ b/test/int/test_cas.py @@ -52,7 +52,7 @@ def test_cas_errors(instance: Instance): ) assert e3.value.args == ( "ER_PROC_C", - "compare-and-swap request failed: entry at index 1 has term 1, request implies term 2", + "compare-and-swap: EntryTermMismatch: entry at index 1 has term 1, request implies term 2", ) # Wrong index (too big) @@ -65,7 +65,7 @@ def test_cas_errors(instance: Instance): ) assert e4.value.args == ( "ER_PROC_C", - "compare-and-swap request failed: " + "compare-and-swap: NoSuchIndex: " + f"raft entry at index 2048 does not exist yet, the last is {index}", ) @@ -77,7 +77,7 @@ def test_cas_errors(instance: Instance): instance.cas("insert", "_pico_property", ["foo", "420"], index=index - 1) assert e5.value.args == ( "ER_PROC_C", - "compare-and-swap request failed: " + "compare-and-swap: Compacted: " + f"raft index {index-1} is compacted at {index}", ) @@ -92,7 +92,7 @@ def test_cas_errors(instance: Instance): ) assert e5.value.args == ( "ER_PROC_C", - f"compare-and-swap request failed: space {space} is prohibited for use " + f"compare-and-swap: SpaceNotAllowed: space {space} is prohibited for use " + "in a predicate", ) @@ -128,7 +128,7 @@ def test_cas_predicate(instance: Instance): ) assert e5.value.args == ( "ER_PROC_C", - "compare-and-swap request failed: " + "compare-and-swap: ConflictFound: " + f"comparison failed for index {read_index} " + f"as it conflicts with {read_index+1}", ) @@ -194,7 +194,7 @@ def test_cas_lua_api(cluster: Cluster): ranges=[CasRange(eq="fruit")], ) assert e5.value.args == ( - "compare-and-swap request failed: " + "compare-and-swap: ConflictFound: " + f"comparison failed for index {read_index} " + f"as it conflicts with {read_index+1}", ) -- GitLab