Skip to content

Commit

Permalink
Merge pull request #54 from aurora-is-near/chore/aleksuss/err_msg_omp…
Browse files Browse the repository at this point in the history
…timize

chore: optimise converting error into message
  • Loading branch information
mrLSD authored May 19, 2023
2 parents b1308fd + e497cd5 commit 0344f6e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions eth-connector-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ hex = "0.4.3"
ethabi = "18.0"
rlp = { version = "0.5.0", default-features = false }
aurora-engine-migration-tool = { git = "https://github.com/aurora-is-near/aurora-engine-migration-tool.git" }
aurora-workspace-eth-connector = { git = "https://github.com/aurora-is-near/aurora-workspace.git", rev = "9a7e87cc4e3b96ead6c28417482728f0141b1dea" }
aurora-workspace-utils = { git = "https://github.com/aurora-is-near/aurora-workspace.git", rev = "9a7e87cc4e3b96ead6c28417482728f0141b1dea" }
aurora-workspace-eth-connector = { git = "https://github.com/aurora-is-near/aurora-workspace.git", tag = "0.2.0" }
aurora-workspace-utils = { git = "https://github.com/aurora-is-near/aurora-workspace.git", tag = "0.2.0" }

[features]
migration-tests = []
11 changes: 9 additions & 2 deletions eth-connector/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use aurora_engine_types::str::from_utf8;
use near_sdk::env::panic_str;

const INVALID_UTF8_ERR_STRING: &str = "INVALID_UTF8_ERR_STRING";

#[macro_export]
macro_rules! log {
($($args:tt)*) => {
Expand All @@ -10,7 +13,7 @@ macro_rules! log {

/// Panic with the message from the error argument.
pub fn panic_err<E: AsRef<[u8]>>(err: E) -> ! {
panic_str(&String::from_utf8_lossy(err.as_ref()))
panic_str(err_to_str(&err))
}

pub trait SdkExpect<T> {
Expand Down Expand Up @@ -41,6 +44,10 @@ impl<T> SdkUnwrap<T> for Option<T> {

impl<T, E: AsRef<[u8]>> SdkUnwrap<T> for Result<T, E> {
fn sdk_unwrap(self) -> T {
self.unwrap_or_else(|e| panic_str(&String::from_utf8_lossy(e.as_ref())))
self.unwrap_or_else(|e| panic_str(err_to_str(&e)))
}
}

fn err_to_str<E: AsRef<[u8]>>(err: &E) -> &str {
from_utf8(err.as_ref()).unwrap_or(INVALID_UTF8_ERR_STRING)
}

0 comments on commit 0344f6e

Please sign in to comment.