diff --git a/client/context/errors_query.go b/client/context/errors_query.go new file mode 100644 index 0000000000..c6bb45db98 --- /dev/null +++ b/client/context/errors_query.go @@ -0,0 +1,31 @@ +package context + +import ( + "bytes" + "encoding/json" + "strings" + + "github.com/pkg/errors" +) + +type Error struct { + Codespace string `json:"codespace"` + Code uint32 `json:"code"` + Message string `json:"message"` +} + +func NewQueryError(codespace string, code uint32, desc string) *Error { + return &Error{Codespace: codespace, Code: code, Message: desc} +} + +func (err Error) Error() string { + var buff bytes.Buffer + enc := json.NewEncoder(&buff) + enc.SetEscapeHTML(false) + + if err := enc.Encode(err); err != nil { + panic(errors.Wrap(err, "failed to encode Query error log")) + } + + return strings.TrimSpace(buff.String()) +} diff --git a/client/context/query.go b/client/context/query.go index d55799d4c3..a759f88c04 100644 --- a/client/context/query.go +++ b/client/context/query.go @@ -95,7 +95,7 @@ func (ctx CLIContext) queryABCI(req abci.RequestQuery) (abci.ResponseQuery, erro } if !result.Response.IsOK() { - return abci.ResponseQuery{}, errors.New(result.Response.Log) + return abci.ResponseQuery{}, NewQueryError(result.Response.Codespace, result.Response.Code, result.Response.Log) } // data from trusted node or subspace query doesn't need verification