From e4d4115a9c1bc638c24ba327a23dd1805da369b3 Mon Sep 17 00:00:00 2001 From: Timothy Zakian Date: Mon, 17 Jun 2024 15:24:47 -0700 Subject: [PATCH] fixup! fixup! fixup! fixup! [CLI] Add clever error support to Sui CLI --- crates/sui/tests/cli_tests.rs | 8 +++++--- crates/sui/tests/snapshots/cli_tests__body_fn.snap | 8 ++++---- .../move/crates/move-disassembler/src/disassembler.rs | 11 +++++++---- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/crates/sui/tests/cli_tests.rs b/crates/sui/tests/cli_tests.rs index 7ededba2f40331..924ea8892f9254 100644 --- a/crates/sui/tests/cli_tests.rs +++ b/crates/sui/tests/cli_tests.rs @@ -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::>(); - x[1] = ""; + let mut x = s.splitn(5, '\'').collect::>(); + x[1] = "ELIDED_TRANSACTION_DIGEST"; + let tmp = format!("ELIDED_ADDRESS{}", &x[3][66..]); + x[3] = &tmp; x.join("'") }; @@ -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()) diff --git a/crates/sui/tests/snapshots/cli_tests__body_fn.snap b/crates/sui/tests/snapshots/cli_tests__body_fn.snap index a39a058e9ed260..32fb1f76f42e75 100644 --- a/crates/sui/tests/snapshots/cli_tests__body_fn.snap +++ b/crates/sui/tests/snapshots/cli_tests__body_fn.snap @@ -4,18 +4,18 @@ expression: error_string --- Non-clever-abort --- -Error executing transaction '': 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 '': 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 '': 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 '': 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' --- diff --git a/external-crates/move/crates/move-disassembler/src/disassembler.rs b/external-crates/move/crates/move-disassembler/src/disassembler.rs index 8aba54f80c1a94..e03a684a579f5c 100644 --- a/external-crates/move/crates/move-disassembler/src/disassembler.rs +++ b/external-crates/move/crates/move-disassembler/src/disassembler.rs @@ -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 { @@ -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]) } }