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

Feature Request: Make accounts tell me what accounts I need to pass #3111

Closed
jacobcreech opened this issue Jul 24, 2024 · 4 comments · Fixed by #3207
Closed

Feature Request: Make accounts tell me what accounts I need to pass #3111

jacobcreech opened this issue Jul 24, 2024 · 4 comments · Fixed by #3207

Comments

@jacobcreech
Copy link

I commonly am using accounts and getting a very ugly error:

Expected 1 arguments, but got 0.ts(2554)
methods.d.ts(67, 14): An argument for 'accounts' was not provided.
(method) MethodsBuilder<TokenLottery, { name: "initialize"; discriminator: [175, 175, 109, 31, 13, 152, 155, 237]; accounts: [{ "name": "payer"; "writable": true;

...

It is fantastic that it points out I am missing an account, however I spend a decent amount of time trying to figure out what that account is. If the error could tell me exact what is not being auto-resolved, I can move a lot faster as a developer.

@acheroncrypto
Copy link
Collaborator

I'm not sure if there is a way to change this error message to show which accounts are missing when the error message is generated by the TypeScript compiler.

The easiest way to see which accounts are potentially needed is to simply use CMD+Space when your cursor is inside .accounts({...}).

@jacobcreech
Copy link
Author

What ends up happening if you pass the incorrect accounts is the error Error: Reached maximum depth for account resolution which is not incredibly helpful. I understand it'll hit this error if I run pda resolutions > 16 depth, but not if I give the incorrect account.

What could be done to make the error more helpful at least would be to log the account(s) it had trouble resolving. I found that my pda resolution was looping on https://github.com/coral-xyz/anchor/blob/master/ts/packages/anchor/src/program/accounts-resolver.ts#L291-L293 until it hit 16 because I didn't provide the right list of accounts required. It'd be nice to catch the account's name and log with the error a list of accounts potentially missed, or the list of accounts it couldn't resolve. That'll help me quickly pinpoint the missing accounts I need to pass.

@acheroncrypto
Copy link
Collaborator

What ends up happening if you pass the incorrect accounts is the error Error: Reached maximum depth for account resolution which is not incredibly helpful.

By "incorrect accounts" do you mean missing accounts?

What could be done to make the error more helpful at least would be to log the account(s) it had trouble resolving.

Yeah, we should be able to do this.

@jacobcreech
Copy link
Author

By "incorrect accounts" do you mean missing accounts?
Both missing accounts and providing the incorrect derivation can result in this error. Give me the accounts that are missing in the error, that way I can either provide them or do accountsStrict/accountsPartial with them if I'm over the 16 resolution depth.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants