Skip to content

Commit

Permalink
Update error wording to reflect actual cause
Browse files Browse the repository at this point in the history
  • Loading branch information
losman0s committed Dec 17, 2021
1 parent 713d436 commit aa7b7e6
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions lang/src/accounts/account.rs
Expand Up @@ -38,7 +38,7 @@ impl<'a, T: AccountSerialize + AccountDeserialize + Owner + Clone> Account<'a, T
return Err(ErrorCode::AccountNotInitialized.into());
}
if info.owner != &T::owner() {
return Err(ErrorCode::AccountNotProgramOwned.into());
return Err(ErrorCode::AccountOwnedByWrongProgram.into());
}
let mut data: &[u8] = &info.try_borrow_data()?;
Ok(Account::new(info.clone(), T::try_deserialize(&mut data)?))
Expand All @@ -53,7 +53,7 @@ impl<'a, T: AccountSerialize + AccountDeserialize + Owner + Clone> Account<'a, T
return Err(ErrorCode::AccountNotInitialized.into());
}
if info.owner != &T::owner() {
return Err(ErrorCode::AccountNotProgramOwned.into());
return Err(ErrorCode::AccountOwnedByWrongProgram.into());
}
let mut data: &[u8] = &info.try_borrow_data()?;
Ok(Account::new(
Expand Down
4 changes: 2 additions & 2 deletions lang/src/accounts/loader.rs
Expand Up @@ -59,7 +59,7 @@ impl<'info, T: ZeroCopy> Loader<'info, T> {
acc_info: &AccountInfo<'info>,
) -> Result<Loader<'info, T>, ProgramError> {
if acc_info.owner != program_id {
return Err(ErrorCode::AccountNotProgramOwned.into());
return Err(ErrorCode::AccountOwnedByWrongProgram.into());
}
let data: &[u8] = &acc_info.try_borrow_data()?;
// Discriminator must match.
Expand All @@ -79,7 +79,7 @@ impl<'info, T: ZeroCopy> Loader<'info, T> {
acc_info: &AccountInfo<'info>,
) -> Result<Loader<'info, T>, ProgramError> {
if acc_info.owner != program_id {
return Err(ErrorCode::AccountNotProgramOwned.into());
return Err(ErrorCode::AccountOwnedByWrongProgram.into());
}
Ok(Loader::new(acc_info.clone()))
}
Expand Down
4 changes: 2 additions & 2 deletions lang/src/accounts/loader_account.rs
Expand Up @@ -55,7 +55,7 @@ impl<'info, T: ZeroCopy + Owner> AccountLoader<'info, T> {
acc_info: &AccountInfo<'info>,
) -> Result<AccountLoader<'info, T>, ProgramError> {
if acc_info.owner != &T::owner() {
return Err(ErrorCode::AccountNotProgramOwned.into());
return Err(ErrorCode::AccountOwnedByWrongProgram.into());
}
let data: &[u8] = &acc_info.try_borrow_data()?;
// Discriminator must match.
Expand All @@ -74,7 +74,7 @@ impl<'info, T: ZeroCopy + Owner> AccountLoader<'info, T> {
acc_info: &AccountInfo<'info>,
) -> Result<AccountLoader<'info, T>, ProgramError> {
if acc_info.owner != &T::owner() {
return Err(ErrorCode::AccountNotProgramOwned.into());
return Err(ErrorCode::AccountOwnedByWrongProgram.into());
}
Ok(AccountLoader::new(acc_info.clone()))
}
Expand Down
4 changes: 2 additions & 2 deletions lang/src/accounts/program_account.rs
Expand Up @@ -41,7 +41,7 @@ impl<'a, T: AccountSerialize + AccountDeserialize + Clone> ProgramAccount<'a, T>
info: &AccountInfo<'a>,
) -> Result<ProgramAccount<'a, T>, ProgramError> {
if info.owner != program_id {
return Err(ErrorCode::AccountNotProgramOwned.into());
return Err(ErrorCode::AccountOwnedByWrongProgram.into());
}
let mut data: &[u8] = &info.try_borrow_data()?;
Ok(ProgramAccount::new(
Expand All @@ -59,7 +59,7 @@ impl<'a, T: AccountSerialize + AccountDeserialize + Clone> ProgramAccount<'a, T>
info: &AccountInfo<'a>,
) -> Result<ProgramAccount<'a, T>, ProgramError> {
if info.owner != program_id {
return Err(ErrorCode::AccountNotProgramOwned.into());
return Err(ErrorCode::AccountOwnedByWrongProgram.into());
}
let mut data: &[u8] = &info.try_borrow_data()?;
Ok(ProgramAccount::new(
Expand Down
2 changes: 1 addition & 1 deletion lang/src/accounts/state.rs
Expand Up @@ -43,7 +43,7 @@ impl<'a, T: AccountSerialize + AccountDeserialize + Clone> ProgramState<'a, T> {
info: &AccountInfo<'a>,
) -> Result<ProgramState<'a, T>, ProgramError> {
if info.owner != program_id {
return Err(ErrorCode::AccountNotProgramOwned.into());
return Err(ErrorCode::AccountOwnedByWrongProgram.into());
}
if info.key != &Self::address(program_id) {
solana_program::msg!("Invalid state address");
Expand Down
4 changes: 2 additions & 2 deletions lang/src/error.rs
Expand Up @@ -77,8 +77,8 @@ pub enum ErrorCode {
AccountNotEnoughKeys,
#[msg("The given account is not mutable")]
AccountNotMutable,
#[msg("The given account is not owned by the executing program")]
AccountNotProgramOwned,
#[msg("The given account is owned by a different program than expected")]
AccountOwnedByWrongProgram,
#[msg("Program ID was not as expected")]
InvalidProgramId,
#[msg("Program account is not executable")]
Expand Down
2 changes: 1 addition & 1 deletion tests/bpf-upgradeable-state/tests/bpf-upgradable-state.ts
Expand Up @@ -122,7 +122,7 @@ describe("bpf_upgradeable_state", () => {
assert.equal(err.code, 3007);
assert.equal(
err.msg,
"The given account is not owned by the executing program"
"The given account is owned by a different program than expected"
);
}
});
Expand Down
6 changes: 3 additions & 3 deletions ts/src/error.ts
Expand Up @@ -91,7 +91,7 @@ const LangErrorCode = {
AccountDidNotSerialize: 3004,
AccountNotEnoughKeys: 3005,
AccountNotMutable: 3006,
AccountNotProgramOwned: 3007,
AccountOwnedByWrongProgram: 3007,
InvalidProgramId: 3008,
InvalidProgramExecutable: 3009,
AccountNotSigner: 3010,
Expand Down Expand Up @@ -189,8 +189,8 @@ const LangErrorMessage = new Map([
],
[LangErrorCode.AccountNotMutable, "The given account is not mutable"],
[
LangErrorCode.AccountNotProgramOwned,
"The given account is not owned by the executing program",
LangErrorCode.AccountOwnedByWrongProgram,
"The given account is owned by a different program than expected",
],
[LangErrorCode.InvalidProgramId, "Program ID was not as expected"],
[LangErrorCode.InvalidProgramExecutable, "Program account is not executable"],
Expand Down

0 comments on commit aa7b7e6

Please sign in to comment.