ugorji / go

idiomatic codec and rpc lib for msgpack, cbor, json, etc. msgpack.org[Go]
MIT License
1.87k stars 295 forks source link

Panic on encoding of incomparable struct #30

Closed tchap closed 10 years ago

tchap commented 10 years ago

Hi,

I am trying to encode a struct that contains a map[string]<comparable struct> (which is still making the whole struct incomparable). I am getting

panic: runtime error: comparing uncomparable type data.App

goroutine 13 [running]:
runtime.panic(0x40b540, 0xc21007aa50)
    /usr/local/go/src/pkg/runtime/panic.c:266 +0xb6
github.com/ugorji/go/codec.isEmptyValue(0x4596a0, 0xc210051750, 0x192, 0x0)
    /Users/tchap/Projects/Go/src/github.com/ugorji/go/codec/helper_internal.go:60 +0x34d
github.com/ugorji/go/codec.(*encFnInfo).kStruct(0xc2100b8450, 0x4133a0, 0xc210051750, 0x192)
    /Users/tchap/Projects/Go/src/github.com/ugorji/go/codec/encode.go:472 +0x27c
github.com/ugorji/go/codec.(*Encoder).encodeValue(0xc2100abcb0, 0x4133a0, 0xc210051750, 0x192)
    /Users/tchap/Projects/Go/src/github.com/ugorji/go/codec/encode.go:893 +0x45a
github.com/ugorji/go/codec.(*Encoder).encode(0xc2100abcb0, 0x4133a0, 0xc210051750)
    /Users/tchap/Projects/Go/src/github.com/ugorji/go/codec/encode.go:808 +0x1f1
github.com/ugorji/go/codec.(*Encoder).Encode(0xc2100abcb0, 0x4133a0, 0xc210051750, 0x0, 0x0)
    /Users/tchap/Projects/Go/src/github.com/ugorji/go/codec/encode.go:692 +0x69

where

type App struct {
    Id          bson.ObjectId `bson:"_id"            codec:"-"`
    Alias       string        `bson:"alias"          codec:"alias"`
    Name        string        `bson:"name"           codec:"name,omitempty"`
    Version     string        `bson:"version"        codec:"version,omitempty"`
    Description string        `bson:"description"    codec:"description,omitempty"`
    Repository  string        `bson:"repository"     codec:"repository,omitempty"`
    Vars        Variables     `bson:"vars,omitempty" codec:"vars,omitempty"        json:"variables"`
    Enabled     bool          `bson:"enabled"        codec:"enabled,omitempty"`
    Status      string        `bson:"-"              codec:"status,omitempty"`
}

type Variables map[string]Variable

type Variable struct {
    Usage    string `bson:"usage"              codec:"usage"`
    Type     string `bson:"type"               codec:"type"`
    Secret   bool   `bson:"secret,omitempty"   codec:"secret,omitempty"`
    Optional bool   `bson:"optional,omitempty" codec:"optional,omitempty"`
    Value    string `bson:"value"              codec:"value"`
}
tchap commented 10 years ago

Actually it looks like encoding works when I try to encode something like

type Reply struct {
    apps []App
}

but

type Reply struct {
    app App
}

panics.

ugorji commented 10 years ago

Shucks.

Do me a favor.

In helper_internal.go, comment out line 60, and uncomment the lines under it.

Since a map is not comparable, a struct containing a map is also not comparable. Consequently, I should have kept the other code that will recursively check each field directly.

Lemme know if that works.

Thanks.

tchap commented 10 years ago

Works.

tchap commented 10 years ago

So, are you going to revert the change to use the old code, @ugorji, or how shall this issue be resolved? Thanks.

ugorji commented 10 years ago

I will get to it this weekend. There are a few other changes I have on the docket, and will include fix with next update.

Thanks.

Ugorji An eagle, aspiring for greater heights ...

On Thu, Feb 13, 2014 at 12:44 PM, Ondrej Kupka notifications@github.comwrote:

So, are you going to revert the change to use the old code, @ugorjihttps://github.com/ugorji, or how shall this issue be resolved? Thanks.

— Reply to this email directly or view it on GitHubhttps://github.com/ugorji/go/issues/30#issuecomment-35004829 .

tchap commented 10 years ago

Ok, cool.

Cheers, Ondrej