state/result: save/return real JSONization errors

Don't hide/obfuscate real problems.
This commit is contained in:
Roman Khimov 2021-07-07 00:42:36 +03:00
parent e62a766058
commit 0cd9cd0c80
2 changed files with 4 additions and 5 deletions

View file

@ -101,7 +101,7 @@ type notificationEventAux struct {
func (ne NotificationEvent) MarshalJSON() ([]byte, error) {
item, err := stackitem.ToJSONWithTypes(ne.Item)
if err != nil {
item = []byte(`"error: recursive reference"`)
item = []byte(fmt.Sprintf(`"error: %v"`, err))
}
return json.Marshal(&notificationEventAux{
ScriptHash: ne.ScriptHash,
@ -191,12 +191,11 @@ type executionAux struct {
// MarshalJSON implements implements json.Marshaler interface.
func (e Execution) MarshalJSON() ([]byte, error) {
var errRecursive = []byte(`"error: recursive reference"`)
arr := make([]json.RawMessage, len(e.Stack))
for i := range arr {
data, err := stackitem.ToJSONWithTypes(e.Stack[i])
if err != nil {
data = errRecursive
data = []byte(fmt.Sprintf(`"error: %v"`, err))
}
arr[i] = data
}

View file

@ -70,7 +70,7 @@ func (r Invoke) MarshalJSON() ([]byte, error) {
for j := range iteratorValues {
value[j], err = stackitem.ToJSONWithTypes(iteratorValues[j])
if err != nil {
st = []byte(`"error: recursive reference"`)
st = []byte(fmt.Sprintf(`"error: %v"`, err))
break
}
}
@ -85,7 +85,7 @@ func (r Invoke) MarshalJSON() ([]byte, error) {
} else {
data, err = stackitem.ToJSONWithTypes(r.Stack[i])
if err != nil {
st = []byte(`"error: recursive reference"`)
st = []byte(fmt.Sprintf(`"error: %v"`, err))
break
}
}