network: specify error message

For better user experience.
This commit is contained in:
Anna Shaleva 2021-02-16 11:02:51 +03:00
parent 717591afe8
commit 9f6fba5926
3 changed files with 32 additions and 1 deletions

View file

@ -1,5 +1,7 @@
package network
//go:generate stringer -type=RelayReason -output=relay_reason_string.go
// RelayReason is the type which describes the different relay outcome.
type RelayReason uint8

View file

@ -0,0 +1,29 @@
// Code generated by "stringer -type=RelayReason -output=relay_reason_string.go"; DO NOT EDIT.
package network
import "strconv"
func _() {
// An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the stringer command to generate them again.
var x [1]struct{}
_ = x[RelaySucceed-0]
_ = x[RelayAlreadyExists-1]
_ = x[RelayOutOfMemory-2]
_ = x[RelayUnableToVerify-3]
_ = x[RelayInvalid-4]
_ = x[RelayPolicyFail-5]
_ = x[RelayUnknown-6]
}
const _RelayReason_name = "RelaySucceedRelayAlreadyExistsRelayOutOfMemoryRelayUnableToVerifyRelayInvalidRelayPolicyFailRelayUnknown"
var _RelayReason_index = [...]uint8{0, 12, 30, 46, 65, 77, 92, 104}
func (i RelayReason) String() string {
if i >= RelayReason(len(_RelayReason_index)-1) {
return "RelayReason(" + strconv.FormatInt(int64(i), 10) + ")"
}
return _RelayReason_name[_RelayReason_index[i]:_RelayReason_index[i+1]]
}

View file

@ -154,7 +154,7 @@ func newServerFromConstructors(config ServerConfig, chain blockchainer.Blockchai
n, err := notary.NewNotary(cfg, s.notaryRequestPool, func(tx *transaction.Transaction) error {
r := s.RelayTxn(tx)
if r != RelaySucceed {
return fmt.Errorf("can't pool notary tx: hash %s, reason: %d", tx.Hash().StringLE(), byte(r))
return fmt.Errorf("can't relay completed notary transaction: hash %s, reason: %s", tx.Hash().StringLE(), r.String())
}
return nil
})