near / near-cli

General purpose command line tools for interacting with NEAR Protocol
https://docs.near.org
MIT License
193 stars 91 forks source link

Return `near call` failure to shell #1028

Closed yipu3 closed 6 months ago

yipu3 commented 1 year ago

Is your feature request related to a problem? Please describe. I wrote a batch script to loop run multiple near call in bash. And I expected it to exit when one of the commands fail using command return @?. But near call still return success(0) when it fail.

Describe the solution you'd like return non-zero value when near call fails.

Describe alternatives you've considered Provide an option that near call failures return non-zero value.

Additional context

[Philip@MacBook-Pro ~]$ near call fund.abliukrny.testnet insert_receiver --args '{"receiver": {"Near": "airdrop.abliukrny.testnet"}, "weight": "14878628377924831543296"}' --account-id not-exist.testnet
Unable to find [ testnet ] credentials for [ not-exist.testnet ]...
Scheduling a call: fund.abliukrny.testnet.insert_receiver({"receiver": {"Near": "airdrop.abliukrny.testnet"}, "weight": "14878628377924831543296"})
Doing account.functionCall()
TypedError: Can not sign transactions for account not-exist.testnet on network testnet, no matching key pair found in InMemorySigner(MergeKeyStore(UnencryptedFileSystemKeyStore(/Users/Philip/.near-credentials), UnencryptedFileSystemKeyStore(/Users/Philip/neardev))).
    at Account.signTransaction (/usr/local/lib/node_modules/near-cli/node_modules/near-api-js/lib/account.js:93:19)
    at async /usr/local/lib/node_modules/near-cli/node_modules/near-api-js/lib/account.js:118:34
    at async Object.exponentialBackoff [as default] (/usr/local/lib/node_modules/near-cli/node_modules/near-api-js/lib/utils/exponential-backoff.js:7:24)
    at async Account.signAndSendTransactionV2 (/usr/local/lib/node_modules/near-cli/node_modules/near-api-js/lib/account.js:117:24)
    at async scheduleFunctionCall (/usr/local/lib/node_modules/near-cli/commands/call.js:57:38)
    at async Object.handler (/usr/local/lib/node_modules/near-cli/utils/exit-on-error.js:52:9) {
  type: 'KeyNotFound',
  context: undefined
}
[Philip@MacBook-Pro ~]$ echo $?
0
gagdiez commented 6 months ago

with the release of 4.0.1, near-cli now fails when the call fails