solitaire: Mention invalid value in InvalidMutability

Change-Id: I240518737243eb7dabbf8ec31bd11148b4475832
This commit is contained in:
Stan Drozd 2021-08-30 16:34:19 +02:00 committed by Stanislaw Drozd
parent 9a85dbafe5
commit f7979ee8b1
2 changed files with 12 additions and 5 deletions

View File

@ -12,8 +12,9 @@ pub type ErrBox = Box<dyn std::error::Error>;
/// 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),

View File

@ -69,7 +69,9 @@ impl<'a, 'b: 'a, 'c, T: Peel<'a, 'b, 'c>> Peel<'a, 'b, 'c> for Mut<T> {
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<I>(ctx: &'c mut Context<'a, 'b, 'c, I>) -> Result<Self> {
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<I>(ctx: &'c mut Context<'a, 'b, 'c, I>) -> Result<Self> {
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.