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

ts: better public key error msgs #1098

Merged

Conversation

paul-schaaf
Copy link
Contributor

when you add a non publickey/string to the accounts object for an instruction you currently get this error.

Error: Non-base58 character

This PR changes the code so you get a more helpful error

Error: Wrong input type for account "authority" in the instruction accounts object for instruction "initialize". Expected PublicKey or string.

@paul-schaaf paul-schaaf marked this pull request as ready for review December 4, 2021 02:30
@paul-schaaf
Copy link
Contributor Author

my guess is that it fails because something that is neither a string nor a public key is passed into translateAddress. whatever it is can also be made into a pubkey but it's the wrong pubkey. will investigate later

@paul-schaaf
Copy link
Contributor Author

it works now, hacky solution but think this is good enough for now and we can try finding the source and fixing it in the other issue I linked

@armaniferrante armaniferrante merged commit 517838e into coral-xyz:master Dec 4, 2021
@paul-schaaf paul-schaaf deleted the ts__better_publickey_errormsgs branch December 5, 2021 02:25
@@ -58,8 +58,10 @@ export function translateAddress(address: Address): PublicKey {
if (typeof address === "string") {
const pk = new PublicKey(address);
return pk;
} else {
} else if (address.constructor.prototype.constructor.name === "PublicKey") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has introduced some bugs in our production build. I believe this is because JS is minifying the code and changing the name of constructors.

A couple suggestions to avoid this:

  • check if the method toBase58 exists on the object
  • add a name or type to the PublicKey constructor object similar to how Phantom adds isPhantom to window.solana

What do you think? Happy to open a PR that fixes this :)

cc @paul-schaaf

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry for that, didnt consider this, my mistake!

fix is already on the way #1138

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks for the pointer there @paul-schaaf :)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have the full picture of the codebase and the issue, just wanted to chime in that some time ago I fixed precisely the same bug replacing such a clause with an instanceofaddress instanceof PublicKey.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can try again but it didnt work for us before #1101

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.

None yet

4 participants