From c7c4f30688778f1c469ed858f3825ce02f6bd02b Mon Sep 17 00:00:00 2001 From: Vadim Obradovich Date: Tue, 10 Sep 2024 16:40:39 +0200 Subject: [PATCH] fix(gtest, gclient): Extract error message from reply payload (#517) --- examples/demo/app/tests/gclient.rs | 5 +++-- examples/demo/app/tests/gtest.rs | 5 +++-- rs/src/errors.rs | 4 ++-- rs/src/gclient/calls.rs | 5 ++++- rs/src/gtest/calls.rs | 3 ++- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/examples/demo/app/tests/gclient.rs b/examples/demo/app/tests/gclient.rs index 2b009ad7..415e8cdc 100644 --- a/examples/demo/app/tests/gclient.rs +++ b/examples/demo/app/tests/gclient.rs @@ -227,8 +227,9 @@ async fn counter_query_not_enough_gas() { assert!(matches!( result, Err(sails_rs::errors::Error::Rtl(RtlError::ReplyHasError( - ErrorReplyReason::Execution(SimpleExecutionError::RanOutOfGas) - ))) + ErrorReplyReason::Execution(SimpleExecutionError::RanOutOfGas), + message + ))) if message == "Not enough gas to handle program data" )); } diff --git a/examples/demo/app/tests/gtest.rs b/examples/demo/app/tests/gtest.rs index 4d76e4d1..622fee9b 100644 --- a/examples/demo/app/tests/gtest.rs +++ b/examples/demo/app/tests/gtest.rs @@ -139,8 +139,9 @@ async fn counter_query_not_enough_gas() { assert!(matches!( result, Err(sails_rs::errors::Error::Rtl(RtlError::ReplyHasError( - ErrorReplyReason::Execution(SimpleExecutionError::RanOutOfGas) - ))) + ErrorReplyReason::Execution(SimpleExecutionError::RanOutOfGas), + message + ))) if message == "Not enough gas to handle program data" )); } diff --git a/rs/src/errors.rs b/rs/src/errors.rs index 9cb1eeda..36f3a4a4 100644 --- a/rs/src/errors.rs +++ b/rs/src/errors.rs @@ -37,8 +37,8 @@ pub enum RtlError { ReplyIsAmbiguous, #[error("reply code is missing")] ReplyCodeIsMissing, - #[error("reply error: {0}")] - ReplyHasError(ErrorReplyReason), + #[error("reply error: {0} {1}")] + ReplyHasError(ErrorReplyReason, String), #[error("program code is not found")] ProgramCodeIsNotFound, #[error("program is not found")] diff --git a/rs/src/gclient/calls.rs b/rs/src/gclient/calls.rs index 3d3e2009..ee9d3ecf 100644 --- a/rs/src/gclient/calls.rs +++ b/rs/src/gclient/calls.rs @@ -130,7 +130,10 @@ impl Remoting for GClientRemoting { match reply_info.code { ReplyCode::Success(_) => Ok(reply_info.payload), - ReplyCode::Error(reason) => Err(RtlError::ReplyHasError(reason))?, + ReplyCode::Error(reason) => { + let message = String::from_utf8_lossy(&reply_info.payload).to_string(); + Err(RtlError::ReplyHasError(reason, message))? + } ReplyCode::Unsupported => Err(RtlError::ReplyIsMissing)?, } } diff --git a/rs/src/gtest/calls.rs b/rs/src/gtest/calls.rs index 6bbbd3cc..51ef23a6 100644 --- a/rs/src/gtest/calls.rs +++ b/rs/src/gtest/calls.rs @@ -78,7 +78,8 @@ impl GTestRemoting { } let reply_code = reply.reply_code().ok_or(RtlError::ReplyCodeIsMissing)?; if let ReplyCode::Error(reason) = reply_code { - Err(RtlError::ReplyHasError(reason))? + let message = String::from_utf8_lossy(reply.payload()).to_string(); + Err(RtlError::ReplyHasError(reason, message))? } if reply_code != ReplyCode::Success(SuccessReplyReason::Manual) { Err(RtlError::ReplyIsMissing)?