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

error from contract returned as string not as object #12646

Closed
MonarthS opened this issue Nov 10, 2021 · 5 comments
Closed

error from contract returned as string not as object #12646

MonarthS opened this issue Nov 10, 2021 · 5 comments
Assignees
Labels
area-api Sev2-normal Normal severity; minor loss of service or inconvenience. stale issues and PRs marked as stale type-bug

Comments

@MonarthS
Copy link

Error thrown from contract returned as string, so can not parse specific error:

contract error

image

  • as you can see, actual error message from contract is Unauthorized Access!, but metamask returned it as string(message + json object).

other errors

image

  • other metamask errors are returned as object.

Expected behavior

  • Should return error as object same as other metamask errors.

Browser details (please complete the following information):

  • OS: OS X
  • Browser: Chrome Version 95.0.4638.69 (Official Build) (x86_64)
  • MetaMask Version: 10.4.1
@MonarthS MonarthS reopened this Nov 11, 2021
@danjm danjm added type-bug area-api Sev2-normal Normal severity; minor loss of service or inconvenience. labels Nov 18, 2021
@BelfordZ
Copy link
Contributor

@MonarthS Im having trouble reproducing this issue. From what I can tell, there is a related issue though - errors returned from smart contracts are returned as nested errors the error.message has the real json-rpc error inside of it.

Any chance you could let me know if you are still running into this, and if so, how i might reproduce the output from the screenshot provided.

Thank you!

@BelfordZ
Copy link
Contributor

BelfordZ commented Jun 22, 2022

here is some notes from trying out different errors in the playground, which uses only the json rpc api:

  1. errors can come from the promise api, or from the event api. Both are have somewhat different formats (varying uses of error.data, in some cases the errors are nested inside of the error.message, which is probably the case you are running into)
  2. A large subset of the possible errors returned from metamask largely depend on the underlying network/rpcUrl that metamask is conencted to. For example, the errors I get from ganache are different than the ones I get from using rinkby, same as if I use an entirely different ethereum-like network such as celo.

Just for Here is some examples of errors you can get from using ganache & playground:

  1. bad nonce for the account set manually by the user
    image

  2. wrong method name for request permissions. (note the data section, and well formed message)
    image

  3. signature denied by the user:
    image

  4. intentionally failing contract tx:
    image

  5. intentionally failing contract call (eth_call instead eth_sendTransaction)
    image

@BelfordZ
Copy link
Contributor

followup questions:

  1. What is sending {value: { error... } } ? are we wrapping with value?
  2. When the error returned from rpc api is not formatted according to expectation, we could return a better result than wrapping the object in a string

@github-actions
Copy link
Contributor

This issue has been automatically marked as stale because it has not had recent activity in the last 90 days. It will be closed in 45 days if there is no further activity. The MetaMask team intends on reviewing this issue before close, and removing the stale label if it is still a bug. We welcome new comments on this issue. We do not intend on closing issues if they report bugs that are still reproducible. Thank you for your contributions.

@github-actions github-actions bot added the stale issues and PRs marked as stale label Jul 23, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Sep 6, 2023

This issue was closed because there has been no follow up activity in the last 45 days. If you feel this was closed in error, please reopen and provide evidence on the latest release of the extension. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-api Sev2-normal Normal severity; minor loss of service or inconvenience. stale issues and PRs marked as stale type-bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants