diff --git a/crates/sargon/src/core/error/common_error.rs b/crates/sargon/src/core/error/common_error.rs index 48a760836..e96dc3902 100644 --- a/crates/sargon/src/core/error/common_error.rs +++ b/crates/sargon/src/core/error/common_error.rs @@ -870,7 +870,11 @@ impl CommonError { matches!(self, CommonError::FailedToDeserializeJSONToValue { .. }) } - pub fn from_address_error(s: String, expected_network: NetworkID) -> Self { + pub fn from_address_error( + s: String, + expected_network: NetworkID, + fallback_underlying: String, + ) -> Self { use radix_engine_toolkit::functions::address::decode as RET_decode_address; let Some(Some(network_id)) = RET_decode_address(&s) .map(|t| t.0) @@ -887,13 +891,13 @@ impl CommonError { } } else { CommonError::InvalidInstructionsString { - underlying: "Failed to determine why an address was invalid" - .to_owned(), + underlying: fallback_underlying, } } } pub fn from_scrypto_compile_error( + manifest_string: &str, err: ScryptoCompileError, expected_network: NetworkID, ) -> Self { @@ -902,16 +906,28 @@ impl CommonError { use GeneratorError; use GeneratorErrorKind::*; let n = expected_network; + + let pretty_diagnostics = scrypto_compile_error_diagnostics( + manifest_string, + err.clone(), + ScryptoCompileErrorDiagnosticsStyle::PlainText, + ); match err { ScryptoCompileError::GeneratorError(GeneratorError { error_kind: gen_err, .. }) => match gen_err { - InvalidPackageAddress(a) => Self::from_address_error(a, n), - InvalidResourceAddress(a) => Self::from_address_error(a, n), - InvalidGlobalAddress(a) => Self::from_address_error(a, n), + InvalidPackageAddress(a) => { + Self::from_address_error(a, n, pretty_diagnostics) + } + InvalidResourceAddress(a) => { + Self::from_address_error(a, n, pretty_diagnostics) + } + InvalidGlobalAddress(a) => { + Self::from_address_error(a, n, pretty_diagnostics) + } _ => CommonError::InvalidInstructionsString { - underlying: format!("GeneratorError: {:?}", gen_err), + underlying: pretty_diagnostics, }, }, ScryptoCompileError::ParserError(ParserError { @@ -921,7 +937,7 @@ impl CommonError { max: max as u16, }, _ => CommonError::InvalidInstructionsString { - underlying: format!("{:?}", err), + underlying: pretty_diagnostics, }, } } diff --git a/crates/sargon/src/lib.rs b/crates/sargon/src/lib.rs index 2b5e88723..0a16014ed 100644 --- a/crates/sargon/src/lib.rs +++ b/crates/sargon/src/lib.rs @@ -199,6 +199,7 @@ pub mod prelude { }, manifest::{ compile as scrypto_compile, + compile_error_diagnostics as scrypto_compile_error_diagnostics, compile_manifest as scrypto_compile_manifest, decompile as scrypto_decompile, generator::{GeneratorError, GeneratorErrorKind}, @@ -214,6 +215,7 @@ pub mod prelude { }, token::{Position, Span}, CompileError as ScryptoCompileError, + CompileErrorDiagnosticsStyle as ScryptoCompileErrorDiagnosticsStyle, KnownManifestObjectNames as ScryptoKnownManifestObjectNames, ManifestObjectNames as ScryptoManifestObjectNames, MockBlobProvider as ScryptoMockBlobProvider, diff --git a/crates/sargon/src/wrapped_radix_engine_toolkit/low_level/v1/transaction_manifest/instructions/instructions.rs b/crates/sargon/src/wrapped_radix_engine_toolkit/low_level/v1/transaction_manifest/instructions/instructions.rs index 69c0060e9..166e4e92f 100644 --- a/crates/sargon/src/wrapped_radix_engine_toolkit/low_level/v1/transaction_manifest/instructions/instructions.rs +++ b/crates/sargon/src/wrapped_radix_engine_toolkit/low_level/v1/transaction_manifest/instructions/instructions.rs @@ -72,7 +72,13 @@ impl Instructions { &network_definition, blob_provider, ) - .map_err(|e| CommonError::from_scrypto_compile_error(e, network_id)) + .map_err(|e| { + CommonError::from_scrypto_compile_error( + instructions_string.as_ref(), + e, + network_id, + ) + }) .and_then(|manifest| { Self::try_from((manifest.instructions.as_ref(), network_id)) }) diff --git a/crates/sargon/src/wrapped_radix_engine_toolkit/low_level/v2/transaction_manifest_v2/instructions_v2/instructions_v2.rs b/crates/sargon/src/wrapped_radix_engine_toolkit/low_level/v2/transaction_manifest_v2/instructions_v2/instructions_v2.rs index c754b9b44..0261ba3eb 100644 --- a/crates/sargon/src/wrapped_radix_engine_toolkit/low_level/v2/transaction_manifest_v2/instructions_v2/instructions_v2.rs +++ b/crates/sargon/src/wrapped_radix_engine_toolkit/low_level/v2/transaction_manifest_v2/instructions_v2/instructions_v2.rs @@ -87,7 +87,13 @@ impl InstructionsV2 { &network_definition, blob_provider, ) - .map_err(|e| CommonError::from_scrypto_compile_error(e, network_id)) + .map_err(|e| { + CommonError::from_scrypto_compile_error( + instructions_string.as_ref(), + e, + network_id, + ) + }) .and_then(|manifest: ScryptoTransactionManifestV2| { Self::try_from((manifest.instructions.as_ref(), network_id)) })