Skip to content

Commit

Permalink
fixup! fixup! fixup! fixup! [CLI] Add clever error support to Sui CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
tzakian committed Jun 18, 2024
1 parent e631df8 commit e4d4115
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
8 changes: 5 additions & 3 deletions crates/sui/tests/cli_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3730,8 +3730,10 @@ async fn test_clever_errors() -> Result<(), anyhow::Error> {
.unwrap();

let elide_transaction_digest = |s: String| -> String {
let mut x = s.splitn(3, '\'').collect::<Vec<_>>();
x[1] = "<ELIDED_TRANSACTION_DIGEST>";
let mut x = s.splitn(5, '\'').collect::<Vec<_>>();
x[1] = "ELIDED_TRANSACTION_DIGEST";
let tmp = format!("ELIDED_ADDRESS{}", &x[3][66..]);
x[3] = &tmp;
x.join("'")
};

Expand Down Expand Up @@ -3793,7 +3795,7 @@ async fn test_clever_errors() -> Result<(), anyhow::Error> {

let error_string = format!(
"Non-clever-abort\n---\n{}\n---\nLine-only-abort\n---\n{}\n---\nClever-error-utf8\n---\n{}\n---\nClever-error-non-utf8\n---\n{}\n---\n",
elide_transaction_digest(non_clever_abort.to_string()),
elide_transaction_digest(non_clever_abort.to_string()),
elide_transaction_digest(line_only_abort.to_string()),
elide_transaction_digest(clever_error_utf8.to_string()),
elide_transaction_digest(clever_error_non_utf8.to_string())
Expand Down
8 changes: 4 additions & 4 deletions crates/sui/tests/snapshots/cli_tests__body_fn.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ expression: error_string
---
Non-clever-abort
---
Error executing transaction '<ELIDED_TRANSACTION_DIGEST>': 1st command aborted within function '0x04becddebc3ae9e7e48c3f31144860e0f99a7414e533716a16db14a831ac4be6::clever_errors::aborter' at instruction 1 with code 0
Error executing transaction 'ELIDED_TRANSACTION_DIGEST': 1st command aborted within function 'ELIDED_ADDRESS::clever_errors::aborter' at instruction 1 with code 0
---
Line-only-abort
---
Error executing transaction '<ELIDED_TRANSACTION_DIGEST>': 1st command aborted within function '0x04becddebc3ae9e7e48c3f31144860e0f99a7414e533716a16db14a831ac4be6::clever_errors::aborter_line_no' at line 18
Error executing transaction 'ELIDED_TRANSACTION_DIGEST': 1st command aborted within function 'ELIDED_ADDRESS::clever_errors::aborter_line_no' at line 18
---
Clever-error-utf8
---
Error executing transaction '<ELIDED_TRANSACTION_DIGEST>': 1st command aborted within function '0x04becddebc3ae9e7e48c3f31144860e0f99a7414e533716a16db14a831ac4be6::clever_errors::clever_aborter' at line 22. Aborted with 'ENotFound' -- 'Element not found in vector 💥 🚀 🌠'
Error executing transaction 'ELIDED_TRANSACTION_DIGEST': 1st command aborted within function 'ELIDED_ADDRESS::clever_errors::clever_aborter' at line 22. Aborted with 'ENotFound' -- 'Element not found in vector 💥 🚀 🌠'
---
Clever-error-non-utf8
---
Error executing transaction '<ELIDED_TRANSACTION_DIGEST>': 1st command aborted within function '0x04becddebc3ae9e7e48c3f31144860e0f99a7414e533716a16db14a831ac4be6::clever_errors::clever_aborter_not_a_string' at line 26. Aborted with 'ENotAString' -- 'BAEAAAAAAAAAAgAAAAAAAAADAAAAAAAAAAQAAAAAAAAA'
Error executing transaction 'ELIDED_TRANSACTION_DIGEST': 1st command aborted within function 'ELIDED_ADDRESS::clever_errors::clever_aborter_not_a_string' at line 26. Aborted with 'ENotAString' -- 'BAEAAAAAAAAAAgAAAAAAAAADAAAAAAAAAAQAAAAAAAAA'
---

Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ use move_core_types::{identifier::IdentStr, language_storage::ModuleId};
use move_coverage::coverage_map::{ExecCoverageMap, FunctionCoverage};
use move_ir_types::location::Loc;

const PREVIEW_LEN: usize = 4;

/// Holds the various options that we support while disassembling code.
#[derive(Debug, Default, Parser)]
pub struct DisassemblerOptions {
Expand Down Expand Up @@ -438,18 +440,19 @@ impl<'a> Disassembler<'a> {
}

fn preview_const(slice: &[u8]) -> String {
if slice.len() <= 4 {
// Account for the .. in the preview
if slice.len() <= PREVIEW_LEN + 2 {
hex::encode(slice)
} else {
format!("{}..", hex::encode(&slice[..4]))
format!("{}..", hex::encode(&slice[..PREVIEW_LEN]))
}
}

fn preview_string(s: &str) -> String {
if s.len() <= 4 {
if s.len() <= PREVIEW_LEN + 2 {
s.to_string()
} else {
format!("{}..", &s[..4])
format!("{}..", &s[..PREVIEW_LEN])
}
}

Expand Down

0 comments on commit e4d4115

Please sign in to comment.