77 "math"
88 "os"
99
10+ "github.com/oasisprotocol/oasis-sdk/client-sdk/go/modules/accounts"
11+ "github.com/oasisprotocol/oasis-sdk/client-sdk/go/modules/core"
1012 "github.com/spf13/cobra"
1113 flag "github.com/spf13/pflag"
1214
@@ -16,14 +18,14 @@ import (
1618 "github.com/oasisprotocol/oasis-core/go/common/quantity"
1719 consensus "github.com/oasisprotocol/oasis-core/go/consensus/api"
1820 consensusTx "github.com/oasisprotocol/oasis-core/go/consensus/api/transaction"
21+ staking "github.com/oasisprotocol/oasis-core/go/staking/api"
1922
2023 "github.com/oasisprotocol/oasis-sdk/client-sdk/go/callformat"
2124 "github.com/oasisprotocol/oasis-sdk/client-sdk/go/client"
2225 "github.com/oasisprotocol/oasis-sdk/client-sdk/go/config"
2326 "github.com/oasisprotocol/oasis-sdk/client-sdk/go/connection"
2427 "github.com/oasisprotocol/oasis-sdk/client-sdk/go/crypto/signature"
2528 "github.com/oasisprotocol/oasis-sdk/client-sdk/go/helpers"
26- "github.com/oasisprotocol/oasis-sdk/client-sdk/go/modules/accounts"
2729 "github.com/oasisprotocol/oasis-sdk/client-sdk/go/types"
2830
2931 "github.com/oasisprotocol/cli/wallet"
@@ -479,11 +481,12 @@ func BroadcastTransaction(
479481 cobra .CheckErr (err )
480482
481483 if rawMeta .CheckTxError != nil {
482- cobra .CheckErr (fmt .Sprintf ("Transaction check failed with error: module: %s code: %d message: %s" ,
483- rawMeta .CheckTxError .Module ,
484- rawMeta .CheckTxError .Code ,
485- rawMeta .CheckTxError .Message ,
486- ))
484+ cobra .CheckErr (fmt .Sprintf ("Transaction check failed with error: %s" ,
485+ PrettyErrorHints (ctx , npa , conn , tx , meta , & types.FailedCallResult {
486+ Module : rawMeta .CheckTxError .Module ,
487+ Code : rawMeta .CheckTxError .Code ,
488+ Message : rawMeta .CheckTxError .Message ,
489+ })))
487490 }
488491
489492 fmt .Printf ("Transaction included in block successfully.\n " )
@@ -509,7 +512,7 @@ func BroadcastTransaction(
509512 cobra .CheckErr (err )
510513 }
511514 default :
512- TriggerPrettyError ( ctx , npa , conn , tx , meta , decResult .Failed )
515+ cobra . CheckErr ( fmt . Sprintf ( "Execution failed with error: %s" , PrettyErrorHints ( ctx , npa , conn , tx , meta , decResult .Failed )) )
513516 }
514517 default :
515518 panic (fmt .Errorf ("unsupported transaction kind: %T" , tx ))
@@ -565,22 +568,30 @@ func WaitForEvent(
565568 return resultCh
566569}
567570
568- func TriggerPrettyError (
571+ // PrettyErrorHints adds any hints based on the error and the transaction context.
572+ func PrettyErrorHints (
569573 _ context.Context ,
570574 npa * NPASelection ,
571575 _ connection.Connection ,
572576 _ interface {},
573577 _ interface {},
574578 failedRes * types.FailedCallResult ,
575- ) {
576- errMsg := fmt .Sprintf ("Execution failed with error: %s" , failedRes .Error ())
577- if failedRes .Code == 2 && failedRes .Module == accounts .ModuleName &&
578- npa != nil && npa .ParaTime != nil &&
579+ ) string {
580+ errMsg := failedRes .Error ()
581+ if npa != nil && npa .ParaTime != nil &&
579582 npa .Network .ChainContext == config .DefaultNetworks .All ["testnet" ].ChainContext &&
580- npa .ParaTime .ID == config .DefaultNetworks .All ["testnet" ].ParaTimes .All ["sapphire" ].ID {
583+ npa .ParaTime .ID == config .DefaultNetworks .All ["testnet" ].ParaTimes .All ["sapphire" ].ID &&
584+ (failedRes .Module == accounts .ModuleName && failedRes .Code == 2 || failedRes .Module == core .ModuleName && failedRes .Code == 5 ) {
581585 errMsg += "\n Tip: You can get TEST tokens at https://faucet.testnet.oasis.io or #dev-central at https://oasis.io/discord."
582586 }
583- cobra .CheckErr (errMsg )
587+ if failedRes .Module == staking .ModuleName {
588+ if failedRes .Code == 5 {
589+ errMsg += "\n Tip: Did you forget to run `oasis account allow`?"
590+ } else if failedRes .Code == 9 {
591+ errMsg += "\n Tip: You can see minimum staking transfer amount by running `oasis network show parameters`"
592+ }
593+ }
594+ return errMsg
584595}
585596
586597func init () {
0 commit comments