mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
gob: generate a better error message in one confusing place
(with maybe more to come) by printing a human-readable representation of a remote type. R=rsc CC=golang-dev https://golang.org/cl/3802045
This commit is contained in:
parent
e9c4f09985
commit
d84317ba58
2 changed files with 26 additions and 5 deletions
|
|
@ -861,12 +861,22 @@ func (dec *Decoder) compatibleType(fr reflect.Type, fw typeId) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
// typeString returns a human-readable description of the type identified by remoteId.
|
||||
func (dec *Decoder) typeString(remoteId typeId) string {
|
||||
if t := idToType[remoteId]; t != nil {
|
||||
// globally known type.
|
||||
return t.string()
|
||||
}
|
||||
return dec.wireType[remoteId].string()
|
||||
}
|
||||
|
||||
|
||||
func (dec *Decoder) compileSingle(remoteId typeId, rt reflect.Type) (engine *decEngine, err os.Error) {
|
||||
engine = new(decEngine)
|
||||
engine.instr = make([]decInstr, 1) // one item
|
||||
name := rt.String() // best we can do
|
||||
if !dec.compatibleType(rt, remoteId) {
|
||||
return nil, os.ErrorString("gob: wrong type received for local value " + name)
|
||||
return nil, os.ErrorString("gob: wrong type received for local value " + name + ": " + dec.typeString(remoteId))
|
||||
}
|
||||
op, indir := dec.decOpFor(remoteId, rt, name)
|
||||
ovfl := os.ErrorString(`value for "` + name + `" out of range`)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue