Improve error message for FixedAccountRetriever (#566)

When an invalid number of accounts is passed in, which is one of the
most common error messages new integrators will see.
This commit is contained in:
Christian Kamm 2023-05-05 09:11:25 +02:00 committed by GitHub
parent 953e2f76b2
commit 2f4976e81f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -99,6 +99,8 @@ pub enum MangoError {
HealthRegionBadInnerInstruction,
#[msg("token is in force close")]
TokenInForceClose,
#[msg("incorrect number of health accounts")]
InvalidHealthAccountCount,
}
impl MangoError {

View File

@ -66,7 +66,11 @@ pub fn new_fixed_order_account_retriever<'a, 'info>(
let expected_ais = active_token_len * 2 // banks + oracles
+ active_perp_len * 2 // PerpMarkets + Oracles
+ active_serum3_len; // open_orders
require_eq!(ais.len(), expected_ais);
require_msg_typed!(ais.len() == expected_ais, MangoError::InvalidHealthAccountCount,
"received {} accounts but expected {} ({} banks, {} bank oracles, {} perp markets, {} perp oracles, {} serum3 oos)",
ais.len(), expected_ais,
active_token_len, active_token_len, active_perp_len, active_perp_len, active_serum3_len
);
Ok(FixedOrderAccountRetriever {
ais: AccountInfoRef::borrow_slice(ais)?,