JSON problem: interface conversion: string is not error: missing method Error

1,345 views
Skip to first unread message

Boris Solovyov

unread,
Dec 11, 2012, 8:42:16 PM12/11/12
to golang-nuts
I'm hitting a problem unmarshaling JSON. (Full details below.) I see two old bugs, #3614 and #977, which are both fixed. They look like the same problem, but the test cases for them don't cause problems in my Go installation. I can't tell if I have found a new bug, or if I'm doing something wrong. Before posting bug report I wanted to ask here. Tell me if this is wrong and I should post bug report.

Thanks,
Boris

2012/12/11 20:10:50 http: panic serving [::1]:53652: interface conversion: string is not error: missing method Error
/usr/local/go/src/pkg/net/http/server.go:589 (0x3da79)
_func_004: buf.Write(debug.Stack())
/usr/local/go/src/pkg/runtime/proc.c:1443 (0xf070)
panic: reflect·call(d->fn, d->args, d->siz);
/usr/local/go/src/pkg/runtime/iface.c:127 (0x6e85)
itab: runtime·panic(err);
/usr/local/go/src/pkg/runtime/iface.c:461 (0x772d)
ifaceE2I: ret->tab = itab(inter, t, 0);
/usr/local/go/src/pkg/runtime/iface.c:476 (0x77b7)
assertE2I: runtime·ifaceE2I(inter, e, &ret);
/usr/local/go/src/pkg/encoding/json/decode.go:123 (0x6c440)
_func_001: err = r.(error)
/usr/local/go/src/pkg/runtime/proc.c:1443 (0xf070)
panic: reflect·call(d->fn, d->args, d->siz);
/usr/local/go/src/pkg/reflect/value.go:1782 (0x5b4a5)
Value.assignTo: panic(context + ": value of type " + v.typ.String() + " is not assignable to type " + dst.String())
/usr/local/go/src/pkg/reflect/value.go:1197 (0x59497)
Value.Set: x = x.assignTo("reflect.Set", v.typ, target)
/usr/local/go/src/pkg/encoding/json/decode.go:426 (0x6382d)
(*decodeState).object: iv.Set(reflect.ValueOf(d.objectInterface()))
/usr/local/go/src/pkg/encoding/json/decode.go:249 (0x62a1d)
(*decodeState).value: d.object(v)
/usr/local/go/src/pkg/encoding/json/decode.go:375 (0x634aa)
(*decodeState).array: d.value(v.Index(i))
/usr/local/go/src/pkg/encoding/json/decode.go:246 (0x62a38)
(*decodeState).value: d.array(v)
/usr/local/go/src/pkg/encoding/json/decode.go:555 (0x63fb5)
(*decodeState).object: d.value(subv)
/usr/local/go/src/pkg/encoding/json/decode.go:249 (0x62a1d)
(*decodeState).value: d.object(v)
/usr/local/go/src/pkg/encoding/json/decode.go:136 (0x62580)
(*decodeState).unmarshal: d.value(rv)
/usr/local/go/src/pkg/encoding/json/decode.go:65 (0x621b2)
Unmarshal: return d.unmarshal(v)
/Users/boris/Documents/go/src/github.com/boris/go/nap/request.go:49 (0x261f2)
com/boris/go/nap.(*Request).ReadEntity: err = json.Unmarshal(buffer, &obj)
com/boris/go/servers/api-server/instance.updateInstances: err := req.ReadEntity(instances)
/Users/boris/Documents/go/src/github.com/boris/go/nap/service.go:122 (0x27df0)
com/boris/go/nap._func_001: handler(req, &res)
/usr/local/go/src/pkg/net/http/server.go:703 (0x328ea)
HandlerFunc.ServeHTTP: f(w, r)
/usr/local/go/src/pkg/net/http/server.go:941 (0x334ca)
(*ServeMux).ServeHTTP: mux.handler(r).ServeHTTP(w, r)
/usr/local/go/src/pkg/net/http/server.go:669 (0x3273c)
(*conn).serve: handler.ServeHTTP(w, w.req)
/usr/local/go/src/pkg/runtime/proc.c:271 (0xd562)
goexit: runtime·goexit(void)

Kyle Lemons

unread,
Dec 11, 2012, 10:48:47 PM12/11/12
to Boris Solovyov, golang-nuts
Can you provide an example of the JSON and the Go type into which you are unmarshaling?  I can see that it's something inside an object inside an array inside an object, but not a whole lot more :).

It looks like there are potentially 3 errors here... you may have an incompatibility in your JSON/Type which is not checked by the JSON library which then causes reflect to panic which then triggers a problem in the HTTP defers :).


--
 
 

Boris Solovyov

unread,
Dec 12, 2012, 7:14:05 AM12/12/12
to Kyle Lemons, golang-nuts
There is a lot of code. I will try to make a minimal test case. I think http is not really part of the problem, so maybe I can make something with just JSON.

Boris Solovyov

unread,
Dec 12, 2012, 7:40:21 AM12/12/12
to Kyle Lemons, golang-nuts
Here is sort-of-minimal testcase: http://play.golang.org/p/fFyr3j42oH

Dave Cheney

unread,
Dec 12, 2012, 8:13:41 AM12/12/12
to Boris Solovyov, golang-nuts, Kyle Lemons

I have a fix for the double panic , I'll try to post it tomorrow.

On 12 Dec 2012 23:40, "Boris Solovyov" <boris.s...@gmail.com> wrote:
Here is sort-of-minimal testcase: http://play.golang.org/p/fFyr3j42oH

--
 
 

Boris Solovyov

unread,
Dec 12, 2012, 8:26:46 AM12/12/12
to Dave Cheney, golang-nuts, Kyle Lemons
Can anyone think of a workaround or way to avoid the problem? I don't understand what is wrong, so I don't know how else I can do this without triggering the issue.

John Asmuth

unread,
Dec 12, 2012, 8:36:29 AM12/12/12
to golan...@googlegroups.com, Kyle Lemons
How can the JSON package know that you want to use SubType1 or SubType2 (or anything) for the items? There simply isn't enough information to do this, the way you have it. When JSON puts data into an interface of any kind, it uses a map[string]interface{}. Unfortunately the map has no methods, so you get the panic.
Reply all
Reply to author
Forward
0 new messages