Skip to content

Commit

Permalink
fix(gtest, gclient): Extract error message from reply payload (#517)
Browse files Browse the repository at this point in the history
  • Loading branch information
vobradovich authored Sep 10, 2024
1 parent 021744e commit c7c4f30
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
5 changes: 3 additions & 2 deletions examples/demo/app/tests/gclient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
));
}

Expand Down
5 changes: 3 additions & 2 deletions examples/demo/app/tests/gtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
));
}

Expand Down
4 changes: 2 additions & 2 deletions rs/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
5 changes: 4 additions & 1 deletion rs/src/gclient/calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?,
}
}
Expand Down
3 changes: 2 additions & 1 deletion rs/src/gtest/calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?
Expand Down

0 comments on commit c7c4f30

Please sign in to comment.