Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update error wording to reflect actual cause #1154

Merged
merged 1 commit into from Dec 17, 2021

Conversation

losman0s
Copy link
Contributor

@losman0s losman0s commented Dec 16, 2021

Problem

Error message thrown in case of wrong account ownership is too restrictive, and can mislead the developer.

Any Account<'info, XXX> in an endpoint's derive(Accounts) struct is automatically validated at runtime to be owned by the program (~crate) it was created in (c.f. here for the check, and here to see how the #[account] macro automatically sets an account struct's owner). However, when a client call provides an account owned by an unexpected program, the validation fails (good) with the confusing error message The given account is not owned by the executing program (bad).

This does not reflect that fact that an account can very well be owned by any program other than the one executing.

Summary of Changes

Move to suggested error enum name and error message:

#[msg("The given account is owned by a different program than expected")]
AccountOwnedByWrongProgram,

Fixes #1100

@losman0s losman0s force-pushed the man0s/error-wording branch 4 times, most recently from aa7b7e6 to 6178141 Compare December 17, 2021 09:18
CHANGELOG.md Outdated Show resolved Hide resolved
@paul-schaaf paul-schaaf marked this pull request as ready for review December 17, 2021 09:26
@paul-schaaf
Copy link
Contributor

@losman0s pls sign the commits in this pr and force push

@losman0s losman0s force-pushed the man0s/error-wording branch 2 times, most recently from ac64f9c to 9fac17d Compare December 17, 2021 10:40
@losman0s
Copy link
Contributor Author

@losman0s pls sign the commits in this pr and force push

@paul-schaaf Done

@paul-schaaf
Copy link
Contributor

Problem

Error message thrown in case of wrong account ownership is too restrictive, and can mislead the developer.

Example: an Account<'info, MyData> in an endpoint's derive(Accounts) struct is validated to be owned by program Z (#[account( owner = Z::ID )]), but when a client call provides instead an account owned by Y, the validation fails (good) with the confusing error message The given account is not owned by the executing program (bad).

Summary of Changes

Move to suggested error enum name and error message:

#[msg("The given account is owned by a different program than expected")]
AccountOwnedByWrongProgram,

Fixes #1100

this is not correct btw. this error is not thrown when an owner check fails (which would be the ConstraintOwner error)

@paul-schaaf
Copy link
Contributor

#1154 (comment)

because this is wrong, the changelog isnt quite accurate either. this change does not affect the owner validation macro. It's the Account<'a, T> owner validation that fails

@losman0s
Copy link
Contributor Author

@paul-schaaf Does the updated PR description and changelog fit better now?

@paul-schaaf
Copy link
Contributor

@losman0s yes

@paul-schaaf paul-schaaf merged commit 561f7cd into coral-xyz:master Dec 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

lang: improve AccountNotProgramOwned error msg or add new error
2 participants