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

incorrectly named argument throws cryptic error when calling contract #171

Closed
amgando opened this issue Jan 9, 2020 · 5 comments
Closed
Assignees
Labels
blocked bug Something isn't working devx P2 Pretty important

Comments

@amgando
Copy link
Contributor

amgando commented Jan 9, 2020

steps to recreate

1. use nearlib to call any contract method with incorrect or non-existent named argument

the error will appear in the client-side JS console

why/where/when did this happen?

this happened by accident while following the [Zero to Hero](https://docs.nearprotocol.com/docs/tutorials/zero-to-hero) tutorial in our docs

 // incorrect (will reproduce this error)
 await contract.setResponse(

 { string: "here we are" } 

)

// vs

// correct (will not produce the error)
 await contract.setResponse(

 { apiResponse: "here we are" } 

)

detail

i think this is the right place to submit this since nearlib could handle this error gracefully but i don't see enough information in the error message to be useful to the developer.

failed transaction on TestNet [here](https://explorer.nearprotocol.com/transactions/9c5JPRgKeAdWrw2GW6YChukDHJUxdSw76AQzfAgoNopV)

this error appears in the

Uncaught (in promise) Error: Transaction 9c5JPRgKeAdWrw2GW6YChukDHJUxdSw76AQzfAgoNopV failed. WebAssembly trap: unknown Error: Transaction 9c5JPRgKeAdWrw2GW6YChukDHJUxdSw76AQzfAgoNopV failed. WebAssembly trap: unknown
at Account.signAndSendTransaction (nearlib.js:97)
at async Contract.value <span class="error">[as setResponse]</span> (nearlib.js:294)
at /app/gbgfhnucs/async <anonymous>:1
TypedError @ nearlib.js:763
signAndSendTransaction @ nearlib.js:97
@janedegtiareva janedegtiareva added bug Something isn't working devx P1 Very important labels May 26, 2020
@janedegtiareva
Copy link
Contributor

This is a common developer mistake and currently can be a big devx detractor.

@janedegtiareva
Copy link
Contributor

In NAJ, when we receive the arguments, we can check the arguments. We need contract metadata.

@janedegtiareva
Copy link
Contributor

This needs design. Estimate is for following up with other teams to find out how to do this.

@frol
Copy link
Collaborator

frol commented Mar 5, 2021

Just for the record, currently, the error message is less cryptic:

Error:  Error: Querying call/dev-1614893283391-2068372/get_status failed: wasm execution failed with error: FunctionCallError(HostError(GuestPanic { panic_msg: "panicked at \'Failed to deserialize input from JSON.: Error(\"missing field `account_id`\", line: 1, column: 40)\', src/lib.rs:22:1" })).
{
  "error": "wasm execution failed with error: FunctionCallError(HostError(GuestPanic { panic_msg: \"panicked at \\'Failed to deserialize input from JSON.: Error(\\\"missing field `account_id`\\\", line: 1, column: 40)\\', src/lib.rs:22:1\" }))",
  "logs": [],
  "block_height": 38844509,
  "block_hash": "APNzn7CxYTr2hdV7d29Gtt8KaWgBrGxTiif6pydVHK9n"
}
    at JsonRpcProvider.query (/usr/lib/node_modules/near-shell/node_modules/near-api-js/lib/providers/json-rpc-provider.js:67:19)
    at processTicksAndRejections (node:internal/process/task_queues:94:5)
    at async Account.viewFunction (/usr/lib/node_modules/near-shell/node_modules/near-api-js/lib/account.js:272:24)
    at async exports.callViewFunction (/usr/lib/node_modules/near-shell/index.js:64:48)
    at async Object.handler (/usr/lib/node_modules/near-shell/utils/exit-on-error.js:37:9)

Yet, it depends on how the contract itself reports the error. JSON parser in Rust provides a helpful message while JSON parser in AssemblyScript might be not that friendly. If AssemblyScript contracts still just crash without any message, we need to address it on the near-sdk-as level.

That said, these are errors from inside the smart contract, these two are generated by JSON parser compiled into the contract.

To do anything with that, we need to define some sort of error API layer for the smart contracts just like we discuss the events API, and come up with some helpful magic for the end-users on the SDK side.

@volovyks
Copy link
Collaborator

Downgrading to P2 since it's not near-api-js issue.
Further actions:

@volovyks volovyks added P2 Pretty important and removed P1 Very important labels Mar 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked bug Something isn't working devx P2 Pretty important
Projects
None yet
Development

No branches or pull requests

5 participants