@@ -82,10 +82,7 @@ impl InspectArgs {
82
82
// Match on ContractArtifactFields and pretty-print
83
83
match field {
84
84
ContractArtifactField :: Abi => {
85
- let abi = artifact
86
- . abi
87
- . as_ref ( )
88
- . ok_or_else ( || eyre:: eyre!( "Failed to fetch lossless ABI" ) ) ?;
85
+ let abi = artifact. abi . as_ref ( ) . ok_or_else ( || missing_error ( "ABI" ) ) ?;
89
86
print_abi ( abi) ?;
90
87
}
91
88
ContractArtifactField :: Bytecode => {
@@ -276,7 +273,7 @@ fn internal_ty(ty: &InternalType) -> String {
276
273
277
274
pub fn print_storage_layout ( storage_layout : Option < & StorageLayout > ) -> Result < ( ) > {
278
275
let Some ( storage_layout) = storage_layout else {
279
- eyre :: bail! ( "Could not get storage layout") ;
276
+ return Err ( missing_error ( " storage layout") ) ;
280
277
} ;
281
278
282
279
if shell:: is_json ( ) {
@@ -309,7 +306,7 @@ pub fn print_storage_layout(storage_layout: Option<&StorageLayout>) -> Result<()
309
306
310
307
fn print_method_identifiers ( method_identifiers : & Option < BTreeMap < String , String > > ) -> Result < ( ) > {
311
308
let Some ( method_identifiers) = method_identifiers else {
312
- eyre :: bail! ( "Could not get method identifiers") ;
309
+ return Err ( missing_error ( " method identifiers") ) ;
313
310
} ;
314
311
315
312
if shell:: is_json ( ) {
@@ -541,7 +538,7 @@ fn print_json_str(obj: &impl serde::Serialize, key: Option<&str>) -> Result<()>
541
538
542
539
fn print_yul ( yul : Option < & str > , strip_comments : bool ) -> Result < ( ) > {
543
540
let Some ( yul) = yul else {
544
- eyre :: bail! ( "Could not get IR output") ;
541
+ return Err ( missing_error ( " IR output") ) ;
545
542
} ;
546
543
547
544
static YUL_COMMENTS : LazyLock < Regex > =
@@ -558,17 +555,24 @@ fn print_yul(yul: Option<&str>, strip_comments: bool) -> Result<()> {
558
555
559
556
fn get_json_str ( obj : & impl serde:: Serialize , key : Option < & str > ) -> Result < String > {
560
557
let value = serde_json:: to_value ( obj) ?;
561
- let mut value_ref = & value;
562
- if let Some ( key) = key
563
- && let Some ( value2) = value. get ( key)
558
+ let value = if let Some ( key) = key
559
+ && let Some ( value) = value. get ( key)
564
560
{
565
- value_ref = value2;
566
- }
567
- let s = match value_ref. as_str ( ) {
568
- Some ( s) => s. to_string ( ) ,
569
- None => format ! ( "{value_ref:#}" ) ,
561
+ value
562
+ } else {
563
+ & value
570
564
} ;
571
- Ok ( s)
565
+ Ok ( match value. as_str ( ) {
566
+ Some ( s) => s. to_string ( ) ,
567
+ None => format ! ( "{value:#}" ) ,
568
+ } )
569
+ }
570
+
571
+ fn missing_error ( field : & str ) -> eyre:: Error {
572
+ eyre ! (
573
+ "{field} missing from artifact; \
574
+ this could be a spurious caching issue, consider running `forge clean`"
575
+ )
572
576
}
573
577
574
578
#[ cfg( test) ]
0 commit comments