Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
GhenadieVP committed Dec 20, 2024
1 parent c4ed26a commit 65ce4de
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
32 changes: 24 additions & 8 deletions crates/sargon/src/core/error/common_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -921,7 +937,7 @@ impl CommonError {
max: max as u16,
},
_ => CommonError::InvalidInstructionsString {
underlying: format!("{:?}", err),
underlying: pretty_diagnostics,
},
}
}
Expand Down
2 changes: 2 additions & 0 deletions crates/sargon/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
Expand Down

0 comments on commit 65ce4de

Please sign in to comment.