Commit c4cc9c28 authored by Rob Pike's avatar Rob Pike

gob: have errorf always prefix the message with "gob: "

to regularize the errors.

R=rsc
CC=golang-dev
https://golang.org/cl/4446055
parent 6e928e41
......@@ -335,7 +335,7 @@ func (deb *debugger) string() string {
func (deb *debugger) delta(expect int) int {
delta := int(deb.uint64())
if delta < 0 || (expect >= 0 && delta != expect) {
errorf("gob decode: corrupted type: delta %d expected %d", delta, expect)
errorf("decode: corrupted type: delta %d expected %d", delta, expect)
}
return delta
}
......
......@@ -468,7 +468,7 @@ func (dec *Decoder) decodeSingle(engine *decEngine, ut *userTypeInfo, p uintptr)
basep := p
delta := int(state.decodeUint())
if delta != 0 {
errorf("gob decode: corrupted data: non-zero delta for singleton")
errorf("decode: corrupted data: non-zero delta for singleton")
}
instr := &engine.instr[singletonField]
ptr := unsafe.Pointer(basep) // offset will be zero
......@@ -493,7 +493,7 @@ func (dec *Decoder) decodeStruct(engine *decEngine, ut *userTypeInfo, p uintptr,
for state.b.Len() > 0 {
delta := int(state.decodeUint())
if delta < 0 {
errorf("gob decode: corrupted data: negative delta")
errorf("decode: corrupted data: negative delta")
}
if delta == 0 { // struct terminator is zero delta fieldnum
break
......@@ -521,7 +521,7 @@ func (dec *Decoder) ignoreStruct(engine *decEngine) {
for state.b.Len() > 0 {
delta := int(state.decodeUint())
if delta < 0 {
errorf("gob ignore decode: corrupted data: negative delta")
errorf("ignore decode: corrupted data: negative delta")
}
if delta == 0 { // struct terminator is zero delta fieldnum
break
......@@ -544,7 +544,7 @@ func (dec *Decoder) ignoreSingle(engine *decEngine) {
state.fieldnum = singletonField
delta := int(state.decodeUint())
if delta != 0 {
errorf("gob decode: corrupted data: non-zero delta for singleton")
errorf("decode: corrupted data: non-zero delta for singleton")
}
instr := &engine.instr[singletonField]
instr.op(instr, state, unsafe.Pointer(nil))
......@@ -572,7 +572,7 @@ func (dec *Decoder) decodeArray(atyp reflect.Type, state *decoderState, p uintpt
p = allocate(atyp, p, 1) // All but the last level has been allocated by dec.Indirect
}
if n := state.decodeUint(); n != uint64(length) {
errorf("gob: length mismatch in decodeArray")
errorf("length mismatch in decodeArray")
}
dec.decodeArrayHelper(state, p, elemOp, elemWid, length, elemIndir, ovfl)
}
......@@ -625,7 +625,7 @@ func (dec *Decoder) ignoreArrayHelper(state *decoderState, elemOp decOp, length
// ignoreArray discards the data for an array value with no destination.
func (dec *Decoder) ignoreArray(state *decoderState, elemOp decOp, length int) {
if n := state.decodeUint(); n != uint64(length) {
errorf("gob: length mismatch in ignoreArray")
errorf("length mismatch in ignoreArray")
}
dec.ignoreArrayHelper(state, elemOp, length)
}
......@@ -695,7 +695,7 @@ func (dec *Decoder) decodeInterface(ityp reflect.Type, state *decoderState, p ui
// The concrete type must be registered.
typ, ok := nameToConcreteType[name]
if !ok {
errorf("gob: name not registered for interface: %q", name)
errorf("name not registered for interface: %q", name)
}
// Read the type id of the concrete value.
concreteId := dec.decodeTypeSequence(true)
......@@ -874,7 +874,7 @@ func (dec *Decoder) decOpFor(wireId typeId, rt reflect.Type, name string, inProg
}
}
if op == nil {
errorf("gob: decode can't handle type %s", rt.String())
errorf("decode can't handle type %s", rt.String())
}
return &op, indir
}
......@@ -895,7 +895,7 @@ func (dec *Decoder) decIgnoreOpFor(wireId typeId) decOp {
wire := dec.wireType[wireId]
switch {
case wire == nil:
errorf("gob: bad data: undefined type %s", wireId.string())
errorf("bad data: undefined type %s", wireId.string())
case wire.ArrayT != nil:
elemId := wire.ArrayT.Elem
elemOp := dec.decIgnoreOpFor(elemId)
......@@ -937,7 +937,7 @@ func (dec *Decoder) decIgnoreOpFor(wireId typeId) decOp {
}
}
if op == nil {
errorf("gob: bad data: ignore can't handle type %s", wireId.string())
errorf("bad data: ignore can't handle type %s", wireId.string())
}
return op
}
......@@ -1106,7 +1106,7 @@ func (dec *Decoder) compileDec(remoteId typeId, ut *userTypeInfo) (engine *decEn
wireStruct = wire.StructT
}
if wireStruct == nil {
errorf("gob: type mismatch in decoder: want struct type %s; got non-struct", rt.String())
errorf("type mismatch in decoder: want struct type %s; got non-struct", rt.String())
}
engine = new(decEngine)
engine.instr = make([]decInstr, len(wireStruct.Field))
......@@ -1115,7 +1115,7 @@ func (dec *Decoder) compileDec(remoteId typeId, ut *userTypeInfo) (engine *decEn
for fieldnum := 0; fieldnum < len(wireStruct.Field); fieldnum++ {
wireField := wireStruct.Field[fieldnum]
if wireField.Name == "" {
errorf("gob: empty name for remote field of type %s", wireStruct.Name)
errorf("empty name for remote field of type %s", wireStruct.Name)
}
ovfl := overflow(wireField.Name)
// Find the field of the local type with the same name.
......@@ -1127,7 +1127,7 @@ func (dec *Decoder) compileDec(remoteId typeId, ut *userTypeInfo) (engine *decEn
continue
}
if !dec.compatibleType(localField.Type, wireField.Id, make(map[reflect.Type]typeId)) {
errorf("gob: wrong type (%s) for received field %s.%s", localField.Type, wireStruct.Name, wireField.Name)
errorf("wrong type (%s) for received field %s.%s", localField.Type, wireStruct.Name, wireField.Name)
}
op, indir := dec.decOpFor(wireField.Id, localField.Type, localField.Name, seen)
engine.instr[fieldnum] = decInstr{*op, fieldnum, indir, uintptr(localField.Offset), ovfl}
......@@ -1201,7 +1201,7 @@ func (dec *Decoder) decodeValue(wireId typeId, val reflect.Value) {
if st := base; st.Kind() == reflect.Struct && !ut.isGobDecoder {
if engine.numInstr == 0 && st.NumField() > 0 && len(dec.wireType[wireId].StructT.Field) > 0 {
name := base.Name()
errorf("gob: type mismatch: no fields matched compiling decoder for %s", name)
errorf("type mismatch: no fields matched compiling decoder for %s", name)
}
dec.decodeStruct(engine, ut, uintptr(unsafeAddr(val)), ut.indir)
} else {
......
......@@ -384,7 +384,7 @@ func (enc *Encoder) encodeArray(b *bytes.Buffer, p uintptr, op encOp, elemWid ui
up := unsafe.Pointer(elemp)
if elemIndir > 0 {
if up = encIndirect(up, elemIndir); up == nil {
errorf("gob: encodeArray: nil element")
errorf("encodeArray: nil element")
}
elemp = uintptr(up)
}
......@@ -400,7 +400,7 @@ func encodeReflectValue(state *encoderState, v reflect.Value, op encOp, indir in
v = reflect.Indirect(v)
}
if !v.IsValid() {
errorf("gob: encodeReflectValue: nil element")
errorf("encodeReflectValue: nil element")
}
op(nil, state, unsafe.Pointer(unsafeAddr(v)))
}
......@@ -438,7 +438,7 @@ func (enc *Encoder) encodeInterface(b *bytes.Buffer, iv reflect.Value) {
ut := userType(iv.Elem().Type())
name, ok := concreteTypeToName[ut.base]
if !ok {
errorf("gob: type not registered for interface: %s", ut.base)
errorf("type not registered for interface: %s", ut.base)
}
// Send the name.
state.encodeUint(uint64(len(name)))
......@@ -587,7 +587,7 @@ func (enc *Encoder) encOpFor(rt reflect.Type, inProgress map[reflect.Type]*encOp
}
}
if op == nil {
errorf("gob enc: can't happen: encode type %s", rt.String())
errorf("can't happen: encode type %s", rt.String())
}
return &op, indir
}
......@@ -599,7 +599,7 @@ func methodIndex(rt reflect.Type, method string) int {
return i
}
}
errorf("gob: internal error: can't find method %s", method)
errorf("internal error: can't find method %s", method)
return 0
}
......@@ -650,7 +650,7 @@ func (enc *Encoder) compileEnc(ut *userTypeInfo) *encEngine {
wireFieldNum++
}
if srt.NumField() > 0 && len(engine.instr) == 0 {
errorf("gob: type %s has no exported fields", rt)
errorf("type %s has no exported fields", rt)
}
engine.instr = append(engine.instr, encInstr{encStructTerminator, 0, 0, 0})
} else {
......
......@@ -22,8 +22,9 @@ type gobError struct {
}
// errorf is like error but takes Printf-style arguments to construct an os.Error.
// It always prefixes the message with "gob: ".
func errorf(format string, args ...interface{}) {
error(fmt.Errorf(format, args...))
error(fmt.Errorf("gob: "+format, args...))
}
// error wraps the argument error and uses it as the argument to panic.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment