state: move nil check down to stackitem JSON processing
We want to return real errors, not some generic thing for any kind of thing happening.
This commit is contained in:
parent
5a9efcc654
commit
e62a766058
3 changed files with 12 additions and 9 deletions
|
@ -232,10 +232,6 @@ func toJSONWithTypes(item Item, seen map[Item]bool) (interface{}, error) {
|
|||
if len(seen) > MaxJSONDepth {
|
||||
return "", ErrTooDeep
|
||||
}
|
||||
typ := item.Type()
|
||||
result := map[string]interface{}{
|
||||
"type": typ.String(),
|
||||
}
|
||||
var value interface{}
|
||||
switch it := item.(type) {
|
||||
case *Array, *Struct:
|
||||
|
@ -281,6 +277,11 @@ func toJSONWithTypes(item Item, seen map[Item]bool) (interface{}, error) {
|
|||
delete(seen, item)
|
||||
case *Pointer:
|
||||
value = it.pos
|
||||
case nil:
|
||||
return "", fmt.Errorf("%w: nil", ErrUnserializable)
|
||||
}
|
||||
result := map[string]interface{}{
|
||||
"type": item.Type().String(),
|
||||
}
|
||||
if value != nil {
|
||||
result["value"] = value
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue