Merge PR #3604: Improve REST Error Messages & Allow Unicode
This commit is contained in:
committed by
Jack Zampolin
parent
8e6a0d166b
commit
9c23fe68ee
+12
-8
@@ -1,13 +1,14 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
cmn "github.com/tendermint/tendermint/libs/common"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
)
|
||||
|
||||
@@ -246,19 +247,22 @@ func (err *sdkError) Code() CodeType {
|
||||
|
||||
// Implements ABCIError.
|
||||
func (err *sdkError) ABCILog() string {
|
||||
cdc := codec.New()
|
||||
errMsg := err.cmnError.Error()
|
||||
jsonErr := humanReadableError{
|
||||
Codespace: err.codespace,
|
||||
Code: err.code,
|
||||
Message: errMsg,
|
||||
}
|
||||
bz, er := cdc.MarshalJSON(jsonErr)
|
||||
if er != nil {
|
||||
panic(er)
|
||||
|
||||
var buff bytes.Buffer
|
||||
enc := json.NewEncoder(&buff)
|
||||
enc.SetEscapeHTML(false)
|
||||
|
||||
if err := enc.Encode(jsonErr); err != nil {
|
||||
panic(errors.Wrap(err, "failed to encode ABCI error log"))
|
||||
}
|
||||
stringifiedJSON := string(bz)
|
||||
return stringifiedJSON
|
||||
|
||||
return strings.TrimSpace(buff.String())
|
||||
}
|
||||
|
||||
func (err *sdkError) Result() Result {
|
||||
|
||||
+12
-7
@@ -72,18 +72,23 @@ func TestAppendMsgToErr(t *testing.T) {
|
||||
|
||||
// plain msg error
|
||||
msg := AppendMsgToErr("something unexpected happened", errMsg)
|
||||
require.Equal(t, fmt.Sprintf("something unexpected happened; %s",
|
||||
errMsg),
|
||||
require.Equal(
|
||||
t,
|
||||
fmt.Sprintf("something unexpected happened; %s", errMsg),
|
||||
msg,
|
||||
fmt.Sprintf("Should have formatted the error message of ABCI Log. tc #%d", i))
|
||||
fmt.Sprintf("Should have formatted the error message of ABCI Log. tc #%d", i),
|
||||
)
|
||||
|
||||
// ABCI Log msg error
|
||||
msg = AppendMsgToErr("something unexpected happened", abciLog)
|
||||
msgIdx := mustGetMsgIndex(abciLog)
|
||||
require.Equal(t, fmt.Sprintf("%s%s; %s}",
|
||||
abciLog[:msgIdx],
|
||||
"something unexpected happened",
|
||||
abciLog[msgIdx:len(abciLog)-1]),
|
||||
require.Equal(
|
||||
t,
|
||||
fmt.Sprintf("%s%s; %s}",
|
||||
abciLog[:msgIdx],
|
||||
"something unexpected happened",
|
||||
abciLog[msgIdx:len(abciLog)-1],
|
||||
),
|
||||
msg,
|
||||
fmt.Sprintf("Should have formatted the error message of ABCI Log. tc #%d", i))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user