From f7979ee8b1863c7ce51a5f8cc4f0f878df544c10 Mon Sep 17 00:00:00 2001 From: Stan Drozd Date: Mon, 30 Aug 2021 16:34:19 +0200 Subject: [PATCH] solitaire: Mention invalid value in InvalidMutability Change-Id: I240518737243eb7dabbf8ec31bd11148b4475832 --- solana/solitaire/program/src/error.rs | 5 +++-- solana/solitaire/program/src/processors/peel.rs | 12 +++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/solana/solitaire/program/src/error.rs b/solana/solitaire/program/src/error.rs index 3c3b96501..6341c1d73 100644 --- a/solana/solitaire/program/src/error.rs +++ b/solana/solitaire/program/src/error.rs @@ -12,8 +12,9 @@ pub type ErrBox = Box; /// There are several places in Solitaire that might fail, we want descriptive errors. #[derive(Debug)] pub enum SolitaireError { - /// The AccountInfo parser expected a mutable key where a readonly was found, or vice versa. - InvalidMutability(Pubkey), + /// The AccountInfo parser expected a mutable key where a readonly + /// was found, or vice versa. Second item is the found value. + InvalidMutability(Pubkey, bool), /// The AccountInfo parser expected a Signer, but the account did not sign. InvalidSigner(Pubkey), diff --git a/solana/solitaire/program/src/processors/peel.rs b/solana/solitaire/program/src/processors/peel.rs index a9b529980..f55bf89f5 100644 --- a/solana/solitaire/program/src/processors/peel.rs +++ b/solana/solitaire/program/src/processors/peel.rs @@ -69,7 +69,9 @@ impl<'a, 'b: 'a, 'c, T: Peel<'a, 'b, 'c>> Peel<'a, 'b, 'c> for Mut { ctx.immutable = false; match ctx.info().is_writable { true => T::peel(ctx).map(|v| Mut(v)), - _ => Err(SolitaireError::InvalidMutability(*ctx.info().key).into()), + _ => Err( + SolitaireError::InvalidMutability(*ctx.info().key, ctx.info().is_writable).into(), + ), } } @@ -162,7 +164,9 @@ where impl<'a, 'b: 'a, 'c> Peel<'a, 'b, 'c> for Info<'b> { fn peel(ctx: &'c mut Context<'a, 'b, 'c, I>) -> Result { if ctx.immutable && ctx.info().is_writable { - return Err(SolitaireError::InvalidMutability(*ctx.info().key).into()); + return Err( + SolitaireError::InvalidMutability(*ctx.info().key, ctx.info().is_writable).into(), + ); } Ok(ctx.info().clone()) @@ -187,7 +191,9 @@ impl< { fn peel(ctx: &'c mut Context<'a, 'b, 'c, I>) -> Result { if ctx.immutable && ctx.info().is_writable { - return Err(SolitaireError::InvalidMutability(*ctx.info().key).into()); + return Err( + SolitaireError::InvalidMutability(*ctx.info().key, ctx.info().is_writable).into(), + ); } // If we're initializing the type, we should emit system/rent as deps.