Skip to content

Commit

Permalink
cli: Remove panic!s (#3263)
Browse files Browse the repository at this point in the history
  • Loading branch information
acheroncrypto authored Sep 20, 2024
1 parent 28582a4 commit 9671271
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2928,25 +2928,26 @@ fn account(
.expect("Not in workspace.")
.read_all_programs()
.expect("Workspace must contain atleast one program.")
.iter()
.find(|&p| p.lib_name == *program_name)
.unwrap_or_else(|| panic!("Program {program_name} not found in workspace."))
.idl
.as_ref()
.expect("IDL not found. Please build the program atleast once to generate the IDL.")
.clone()
.into_iter()
.find(|p| p.lib_name == *program_name)
.ok_or_else(|| anyhow!("Program {program_name} not found in workspace."))
.map(|p| p.idl)?
.ok_or_else(|| {
anyhow!(
"IDL not found. Please build the program atleast once to generate the IDL."
)
})
},
|idl_path| {
let bytes = fs::read(idl_path).expect("Unable to read IDL.");
let idl: Idl = serde_json::from_reader(&*bytes).expect("Invalid IDL format.");

if idl.metadata.name != program_name {
panic!("IDL does not match program {program_name}.");
return Err(anyhow!("IDL does not match program {program_name}."));
}

idl
Ok(idl)
},
);
)?;

let cluster = match &cfg_override.cluster {
Some(cluster) => cluster.clone(),
Expand Down Expand Up @@ -3020,7 +3021,7 @@ fn deserialize_idl_defined_type_to_json(

let variant = variants
.get(repr as usize)
.unwrap_or_else(|| panic!("Error while deserializing enum variant {repr}"));
.ok_or_else(|| anyhow!("Error while deserializing enum variant {repr}"))?;

let mut value = json!({});

Expand Down

0 comments on commit 9671271

Please sign in to comment.