goprotobuf: update to new errors.
Mostly gofix, but a few needed hand-work,
such as in the generator.
R=r, bradfitz, rsc
CC=golang-dev
http://codereview.appspot.com/5335045
diff --git a/compiler/descriptor/descriptor.pb.go b/compiler/descriptor/descriptor.pb.go
index 507126e..b5b402c 100644
--- a/compiler/descriptor/descriptor.pb.go
+++ b/compiler/descriptor/descriptor.pb.go
@@ -5,12 +5,10 @@
import proto "goprotobuf.googlecode.com/hg/proto"
import "math"
-import "os"
// Reference proto, math & os imports to suppress error if they are not otherwise used.
var _ = proto.GetString
var _ = math.Inf
-var _ os.Error
type FieldDescriptorProto_Type int32
diff --git a/compiler/generator/generator.go b/compiler/generator/generator.go
index ca1e576..095bfc3 100644
--- a/compiler/generator/generator.go
+++ b/compiler/generator/generator.go
@@ -274,9 +274,9 @@
g.P("func (this *", ms.sym, ") ExtensionMap() map[int32]", g.ProtoPkg, ".Extension ",
"{ return (*", remoteSym, ")(this).ExtensionMap() }")
if ms.isMessageSet {
- g.P("func (this *", ms.sym, ") Marshal() ([]byte, os.Error) ",
+ g.P("func (this *", ms.sym, ") Marshal() ([]byte, error) ",
"{ return (*", remoteSym, ")(this).Marshal() }")
- g.P("func (this *", ms.sym, ") Unmarshal(buf []byte) os.Error ",
+ g.P("func (this *", ms.sym, ") Unmarshal(buf []byte) error ",
"{ return (*", remoteSym, ")(this).Unmarshal(buf) }")
}
}
@@ -351,9 +351,9 @@
return g
}
-// Error reports a problem, including an os.Error, and exits the program.
-func (g *Generator) Error(err os.Error, msgs ...string) {
- s := strings.Join(msgs, " ") + ":" + err.String()
+// Error reports a problem, including an error, and exits the program.
+func (g *Generator) Error(err error, msgs ...string) {
+ s := strings.Join(msgs, " ") + ":" + err.Error()
log.Println("protoc-gen-go: error:", s)
g.Response.Error = proto.String(s)
os.Exit(1)
@@ -780,13 +780,13 @@
fset := token.NewFileSet()
ast, err := parser.ParseFile(fset, "", g, parser.ParseComments)
if err != nil {
- g.Fail("bad Go source code was generated:", err.String())
+ g.Fail("bad Go source code was generated:", err.Error())
return
}
g.Reset()
_, err = (&printer.Config{printer.TabIndent | printer.UseSpaces, 8}).Fprint(g, fset, ast)
if err != nil {
- g.Fail("generated Go source code could not be reformatted:", err.String())
+ g.Fail("generated Go source code could not be reformatted:", err.Error())
}
}
@@ -812,10 +812,10 @@
func (g *Generator) generateImports() {
// We almost always need a proto import. Rather than computing when we
// do, which is tricky when there's a plugin, just import it and
- // reference it later. The same argument applies to the os package.
+ // reference it later. The same argument applies to the math package,
+ // for handling bit patterns for floating-point numbers.
g.P("import " + g.ProtoPkg + " " + Quote(g.ImportPrefix+"goprotobuf.googlecode.com/hg/proto"))
g.P(`import "math"`)
- g.P(`import "os"`)
for _, s := range g.file.Dependency {
fd := g.fileByName(s)
// Do not import our own package.
@@ -846,10 +846,9 @@
p.GenerateImports(g.file)
g.P()
}
- g.P("// Reference proto, math & os imports to suppress error if they are not otherwise used.")
+ g.P("// Reference proto & math imports to suppress error if they are not otherwise used.")
g.P("var _ = ", g.ProtoPkg, ".GetString")
g.P("var _ = math.Inf")
- g.P("var _ os.Error")
g.P()
}
@@ -1147,12 +1146,12 @@
if opts := message.Options; opts != nil && proto.GetBool(opts.MessageSetWireFormat) {
isMessageSet = true
g.P()
- g.P("func (this *", ccTypeName, ") Marshal() ([]byte, os.Error) {")
+ g.P("func (this *", ccTypeName, ") Marshal() ([]byte, error) {")
g.In()
g.P("return ", g.ProtoPkg, ".MarshalMessageSet(this.ExtensionMap())")
g.Out()
g.P("}")
- g.P("func (this *", ccTypeName, ") Unmarshal(buf []byte) os.Error {")
+ g.P("func (this *", ccTypeName, ") Unmarshal(buf []byte) error {")
g.In()
g.P("return ", g.ProtoPkg, ".UnmarshalMessageSet(buf, this.ExtensionMap())")
g.Out()
diff --git a/compiler/plugin/plugin.pb.go b/compiler/plugin/plugin.pb.go
index ac80dc4..f85b5c6 100644
--- a/compiler/plugin/plugin.pb.go
+++ b/compiler/plugin/plugin.pb.go
@@ -5,43 +5,42 @@
import proto "goprotobuf.googlecode.com/hg/proto"
import "math"
-import "os"
+
import google_protobuf "goprotobuf.googlecode.com/hg/compiler/descriptor"
// Reference proto, math & os imports to suppress error if they are not otherwise used.
var _ = proto.GetString
var _ = math.Inf
-var _ os.Error
-
+var _ error
type CodeGeneratorRequest struct {
- FileToGenerate []string `protobuf:"bytes,1,rep,name=file_to_generate"`
- Parameter *string `protobuf:"bytes,2,opt,name=parameter"`
- ProtoFile []*google_protobuf.FileDescriptorProto `protobuf:"bytes,15,rep,name=proto_file"`
- XXX_unrecognized []byte
+ FileToGenerate []string `protobuf:"bytes,1,rep,name=file_to_generate"`
+ Parameter *string `protobuf:"bytes,2,opt,name=parameter"`
+ ProtoFile []*google_protobuf.FileDescriptorProto `protobuf:"bytes,15,rep,name=proto_file"`
+ XXX_unrecognized []byte
}
-func (this *CodeGeneratorRequest) Reset() { *this = CodeGeneratorRequest{} }
-func (this *CodeGeneratorRequest) String() string { return proto.CompactTextString(this) }
+func (this *CodeGeneratorRequest) Reset() { *this = CodeGeneratorRequest{} }
+func (this *CodeGeneratorRequest) String() string { return proto.CompactTextString(this) }
type CodeGeneratorResponse struct {
- Error *string `protobuf:"bytes,1,opt,name=error"`
- File []*CodeGeneratorResponse_File `protobuf:"bytes,15,rep,name=file"`
- XXX_unrecognized []byte
+ Error *string `protobuf:"bytes,1,opt,name=error"`
+ File []*CodeGeneratorResponse_File `protobuf:"bytes,15,rep,name=file"`
+ XXX_unrecognized []byte
}
-func (this *CodeGeneratorResponse) Reset() { *this = CodeGeneratorResponse{} }
-func (this *CodeGeneratorResponse) String() string { return proto.CompactTextString(this) }
+func (this *CodeGeneratorResponse) Reset() { *this = CodeGeneratorResponse{} }
+func (this *CodeGeneratorResponse) String() string { return proto.CompactTextString(this) }
type CodeGeneratorResponse_File struct {
- Name *string `protobuf:"bytes,1,opt,name=name"`
- InsertionPoint *string `protobuf:"bytes,2,opt,name=insertion_point"`
- Content *string `protobuf:"bytes,15,opt,name=content"`
- XXX_unrecognized []byte
+ Name *string `protobuf:"bytes,1,opt,name=name"`
+ InsertionPoint *string `protobuf:"bytes,2,opt,name=insertion_point"`
+ Content *string `protobuf:"bytes,15,opt,name=content"`
+ XXX_unrecognized []byte
}
-func (this *CodeGeneratorResponse_File) Reset() { *this = CodeGeneratorResponse_File{} }
-func (this *CodeGeneratorResponse_File) String() string { return proto.CompactTextString(this) }
+func (this *CodeGeneratorResponse_File) Reset() { *this = CodeGeneratorResponse_File{} }
+func (this *CodeGeneratorResponse_File) String() string { return proto.CompactTextString(this) }
func init() {
}
diff --git a/compiler/testdata/imp.pb.go.golden b/compiler/testdata/imp.pb.go.golden
index c038c74..bd6b59b 100644
--- a/compiler/testdata/imp.pb.go.golden
+++ b/compiler/testdata/imp.pb.go.golden
@@ -8,10 +8,9 @@
import "os"
import imp1 "imp2.pb"
-// Reference proto, math & os imports to suppress error if they are not otherwise used.
+// Reference proto & math imports to suppress error if they are not otherwise used.
var _ = proto.GetString
var _ = math.Inf
-var _ os.Error
// Types from public import imp2.proto
type PubliclyImportedMessage imp1.PubliclyImportedMessage
@@ -78,10 +77,10 @@
func (this *ImportedExtendable) Reset() { *this = ImportedExtendable{} }
func (this *ImportedExtendable) String() string { return proto.CompactTextString(this) }
-func (this *ImportedExtendable) Marshal() ([]byte, os.Error) {
+func (this *ImportedExtendable) Marshal() ([]byte, error) {
return proto.MarshalMessageSet(this.ExtensionMap())
}
-func (this *ImportedExtendable) Unmarshal(buf []byte) os.Error {
+func (this *ImportedExtendable) Unmarshal(buf []byte) error {
return proto.UnmarshalMessageSet(buf, this.ExtensionMap())
}
// ensure ImportedExtendable satisfies proto.Marshaler and proto.Unmarshaler
diff --git a/compiler/testdata/test.pb.go.golden b/compiler/testdata/test.pb.go.golden
index 233d1f9..631cd5d 100644
--- a/compiler/testdata/test.pb.go.golden
+++ b/compiler/testdata/test.pb.go.golden
@@ -5,14 +5,12 @@
import proto "goprotobuf.googlecode.com/hg/proto"
import "math"
-import "os"
import imp1 "imp.pb"
// discarding unused import multitest2 "multi1.pb"
-// Reference proto, math & os imports to suppress error if they are not otherwise used.
+// Reference proto & math imports to suppress error if they are not otherwise used.
var _ = proto.GetString
var _ = math.Inf
-var _ os.Error
type HatType int32
@@ -201,10 +199,10 @@
func (this *OldReply) Reset() { *this = OldReply{} }
func (this *OldReply) String() string { return proto.CompactTextString(this) }
-func (this *OldReply) Marshal() ([]byte, os.Error) {
+func (this *OldReply) Marshal() ([]byte, error) {
return proto.MarshalMessageSet(this.ExtensionMap())
}
-func (this *OldReply) Unmarshal(buf []byte) os.Error {
+func (this *OldReply) Unmarshal(buf []byte) error {
return proto.UnmarshalMessageSet(buf, this.ExtensionMap())
}
// ensure OldReply satisfies proto.Marshaler and proto.Unmarshaler
diff --git a/proto/all_test.go b/proto/all_test.go
index 78181fd..4b29b27 100644
--- a/proto/all_test.go
+++ b/proto/all_test.go
@@ -37,7 +37,6 @@
"fmt"
"json"
"math"
- "os"
"reflect"
"strings"
"testing"
@@ -430,7 +429,7 @@
err := o.Marshal(pb)
if err == nil {
t.Error("did not catch missing required fields")
- } else if strings.Index(err.String(), "GoTest") < 0 {
+ } else if strings.Index(err.Error(), "GoTest") < 0 {
t.Error("wrong error type:", err)
}
}
@@ -845,22 +844,22 @@
d, err := Marshal(pb)
if err != nil {
- t.Errorf(err.String())
+ t.Error(err)
}
pbd := new(GoTest)
if err := Unmarshal(d, pbd); err != nil {
- t.Errorf(err.String())
+ t.Error(err)
}
if pbd.F_BytesRequired == nil || len(pbd.F_BytesRequired) != 0 {
- t.Errorf("required empty bytes field is incorrect")
+ t.Error("required empty bytes field is incorrect")
}
if pbd.F_BytesRepeated == nil || len(pbd.F_BytesRepeated) == 1 && pbd.F_BytesRepeated[0] == nil {
- t.Errorf("repeated empty bytes field is incorrect")
+ t.Error("repeated empty bytes field is incorrect")
}
if pbd.F_BytesOptional == nil || len(pbd.F_BytesOptional) != 0 {
- t.Errorf("optional empty bytes field is incorrect")
+ t.Error("optional empty bytes field is incorrect")
}
}
@@ -874,16 +873,16 @@
d, err := Marshal(pb)
if err != nil {
- t.Errorf(err.String())
+ t.Error(err)
}
pbd := new(GoTest)
if err := Unmarshal(d, pbd); err != nil {
- t.Errorf(err.String())
+ t.Error(err)
}
if len(pbd.F_BytesRepeated) != 1 || pbd.F_BytesRepeated[0] == nil {
- t.Errorf("Unexpected value for repeated bytes field")
+ t.Error("Unexpected value for repeated bytes field")
}
}
@@ -1155,7 +1154,7 @@
_, err := Marshal(pb)
if err == nil {
t.Error("marshal: expected error, got nil")
- } else if strings.Index(err.String(), "GoTestField") < 0 {
+ } else if strings.Index(err.Error(), "GoTestField") < 0 {
t.Errorf("marshal: bad error type: %v", err)
}
@@ -1166,7 +1165,7 @@
err = Unmarshal(buf, pb)
if err == nil {
t.Error("unmarshal: expected error, got nil")
- } else if strings.Index(err.String(), "GoTestField") < 0 {
+ } else if strings.Index(err.Error(), "GoTestField") < 0 {
t.Errorf("unmarshal: bad error type: %v", err)
}
}
@@ -1174,7 +1173,7 @@
// A type that implements the Marshaler interface, but is not nillable.
type nonNillableInt uint64
-func (nni nonNillableInt) Marshal() ([]byte, os.Error) {
+func (nni nonNillableInt) Marshal() ([]byte, error) {
return EncodeVarint(uint64(nni)), nil
}
@@ -1187,7 +1186,7 @@
x uint64
}
-func (nm *nillableMessage) Marshal() ([]byte, os.Error) {
+func (nm *nillableMessage) Marshal() ([]byte, error) {
return EncodeVarint(nm.x), nil
}
diff --git a/proto/decode.go b/proto/decode.go
index 815e825..f84d571 100644
--- a/proto/decode.go
+++ b/proto/decode.go
@@ -36,6 +36,7 @@
*/
import (
+ "errors"
"fmt"
"io"
"os"
@@ -47,7 +48,7 @@
// ErrWrongType occurs when the wire encoding for the field disagrees with
// that specified in the type being decoded. This is usually caused by attempting
// to convert an encoded protocol buffer into a struct of the wrong type.
-var ErrWrongType = os.NewError("field/encoding mismatch: wrong type for field")
+var ErrWrongType = errors.New("field/encoding mismatch: wrong type for field")
// The fundamental decoders that interpret bytes on the wire.
// Those that take integer types all return uint64 and are
@@ -79,7 +80,7 @@
// This is the format for the
// int32, int64, uint32, uint64, bool, and enum
// protocol buffer types.
-func (p *Buffer) DecodeVarint() (x uint64, err os.Error) {
+func (p *Buffer) DecodeVarint() (x uint64, err error) {
// x, err already 0
i := p.index
@@ -104,7 +105,7 @@
// DecodeFixed64 reads a 64-bit integer from the Buffer.
// This is the format for the
// fixed64, sfixed64, and double protocol buffer types.
-func (p *Buffer) DecodeFixed64() (x uint64, err os.Error) {
+func (p *Buffer) DecodeFixed64() (x uint64, err error) {
// x, err already 0
i := p.index + 8
if i > len(p.buf) {
@@ -127,7 +128,7 @@
// DecodeFixed32 reads a 32-bit integer from the Buffer.
// This is the format for the
// fixed32, sfixed32, and float protocol buffer types.
-func (p *Buffer) DecodeFixed32() (x uint64, err os.Error) {
+func (p *Buffer) DecodeFixed32() (x uint64, err error) {
// x, err already 0
i := p.index + 4
if i > len(p.buf) {
@@ -146,7 +147,7 @@
// DecodeZigzag64 reads a zigzag-encoded 64-bit integer
// from the Buffer.
// This is the format used for the sint64 protocol buffer type.
-func (p *Buffer) DecodeZigzag64() (x uint64, err os.Error) {
+func (p *Buffer) DecodeZigzag64() (x uint64, err error) {
x, err = p.DecodeVarint()
if err != nil {
return
@@ -158,7 +159,7 @@
// DecodeZigzag32 reads a zigzag-encoded 32-bit integer
// from the Buffer.
// This is the format used for the sint32 protocol buffer type.
-func (p *Buffer) DecodeZigzag32() (x uint64, err os.Error) {
+func (p *Buffer) DecodeZigzag32() (x uint64, err error) {
x, err = p.DecodeVarint()
if err != nil {
return
@@ -173,7 +174,7 @@
// DecodeRawBytes reads a count-delimited byte buffer from the Buffer.
// This is the format used for the bytes protocol buffer
// type and for embedded messages.
-func (p *Buffer) DecodeRawBytes(alloc bool) (buf []byte, err os.Error) {
+func (p *Buffer) DecodeRawBytes(alloc bool) (buf []byte, err error) {
n, err := p.DecodeVarint()
if err != nil {
return
@@ -200,7 +201,7 @@
// DecodeStringBytes reads an encoded string from the Buffer.
// This is the format used for the proto2 string type.
-func (p *Buffer) DecodeStringBytes() (s string, err os.Error) {
+func (p *Buffer) DecodeStringBytes() (s string, err error) {
buf, err := p.DecodeRawBytes(false)
if err != nil {
return
@@ -211,7 +212,7 @@
// Skip the next item in the buffer. Its wire type is decoded and presented as an argument.
// If the protocol buffer has extensions, and the field matches, add it as an extension.
// Otherwise, if the XXX_unrecognized field exists, append the skipped data there.
-func (o *Buffer) skipAndSave(t reflect.Type, tag, wire int, base uintptr) os.Error {
+func (o *Buffer) skipAndSave(t reflect.Type, tag, wire int, base uintptr) error {
oi := o.index
@@ -247,10 +248,10 @@
}
// Skip the next item in the buffer. Its wire type is decoded and presented as an argument.
-func (o *Buffer) skip(t reflect.Type, tag, wire int) os.Error {
+func (o *Buffer) skip(t reflect.Type, tag, wire int) error {
var u uint64
- var err os.Error
+ var err error
switch wire {
case WireVarint:
@@ -285,13 +286,13 @@
// Unmarshaler is the interface representing objects that can unmarshal themselves.
type Unmarshaler interface {
- Unmarshal([]byte) os.Error
+ Unmarshal([]byte) error
}
// Unmarshal parses the protocol buffer representation in buf and places the
// decoded result in pb. If the struct underlying pb does not match
// the data in buf, the results can be unpredictable.
-func Unmarshal(buf []byte, pb interface{}) os.Error {
+func Unmarshal(buf []byte, pb interface{}) error {
// If the object can unmarshal itself, let it.
if u, ok := pb.(Unmarshaler); ok {
return u.Unmarshal(buf)
@@ -304,7 +305,7 @@
// Buffer and places the decoded result in pb. If the struct
// underlying pb does not match the data in the buffer, the results can be
// unpredictable.
-func (p *Buffer) Unmarshal(pb interface{}) os.Error {
+func (p *Buffer) Unmarshal(pb interface{}) error {
// If the object can unmarshal itself, let it.
if u, ok := pb.(Unmarshaler); ok {
err := u.Unmarshal(p.buf[p.index:])
@@ -329,12 +330,12 @@
}
// unmarshalType does the work of unmarshaling a structure.
-func (o *Buffer) unmarshalType(t reflect.Type, is_group bool, base uintptr) os.Error {
+func (o *Buffer) unmarshalType(t reflect.Type, is_group bool, base uintptr) error {
st := t.Elem()
prop := GetProperties(st)
required, reqFields := prop.reqCount, uint64(0)
- var err os.Error
+ var err error
for err == nil && o.index < len(o.buf) {
oi := o.index
var u uint64
@@ -426,7 +427,7 @@
)
// Decode a bool.
-func (o *Buffer) dec_bool(p *Properties, base uintptr) os.Error {
+func (o *Buffer) dec_bool(p *Properties, base uintptr) error {
u, err := p.valDec(o)
if err != nil {
return err
@@ -442,7 +443,7 @@
}
// Decode an int32.
-func (o *Buffer) dec_int32(p *Properties, base uintptr) os.Error {
+func (o *Buffer) dec_int32(p *Properties, base uintptr) error {
u, err := p.valDec(o)
if err != nil {
return err
@@ -458,7 +459,7 @@
}
// Decode an int64.
-func (o *Buffer) dec_int64(p *Properties, base uintptr) os.Error {
+func (o *Buffer) dec_int64(p *Properties, base uintptr) error {
u, err := p.valDec(o)
if err != nil {
return err
@@ -474,7 +475,7 @@
}
// Decode a string.
-func (o *Buffer) dec_string(p *Properties, base uintptr) os.Error {
+func (o *Buffer) dec_string(p *Properties, base uintptr) error {
s, err := o.DecodeStringBytes()
if err != nil {
return err
@@ -487,7 +488,7 @@
}
// Decode a slice of bytes ([]byte).
-func (o *Buffer) dec_slice_byte(p *Properties, base uintptr) os.Error {
+func (o *Buffer) dec_slice_byte(p *Properties, base uintptr) error {
b, err := o.DecodeRawBytes(true)
if err != nil {
return err
@@ -498,7 +499,7 @@
}
// Decode a slice of bools ([]bool).
-func (o *Buffer) dec_slice_bool(p *Properties, base uintptr) os.Error {
+func (o *Buffer) dec_slice_bool(p *Properties, base uintptr) error {
u, err := p.valDec(o)
if err != nil {
return err
@@ -509,7 +510,7 @@
}
// Decode a slice of bools ([]bool) in packed format.
-func (o *Buffer) dec_slice_packed_bool(p *Properties, base uintptr) os.Error {
+func (o *Buffer) dec_slice_packed_bool(p *Properties, base uintptr) error {
v := (*[]bool)(unsafe.Pointer(base + p.offset))
nn, err := o.DecodeVarint()
@@ -532,7 +533,7 @@
}
// Decode a slice of int32s ([]int32).
-func (o *Buffer) dec_slice_int32(p *Properties, base uintptr) os.Error {
+func (o *Buffer) dec_slice_int32(p *Properties, base uintptr) error {
u, err := p.valDec(o)
if err != nil {
return err
@@ -543,7 +544,7 @@
}
// Decode a slice of int32s ([]int32) in packed format.
-func (o *Buffer) dec_slice_packed_int32(p *Properties, base uintptr) os.Error {
+func (o *Buffer) dec_slice_packed_int32(p *Properties, base uintptr) error {
v := (*[]int32)(unsafe.Pointer(base + p.offset))
nn, err := o.DecodeVarint()
@@ -568,7 +569,7 @@
}
// Decode a slice of int64s ([]int64).
-func (o *Buffer) dec_slice_int64(p *Properties, base uintptr) os.Error {
+func (o *Buffer) dec_slice_int64(p *Properties, base uintptr) error {
u, err := p.valDec(o)
if err != nil {
return err
@@ -581,7 +582,7 @@
}
// Decode a slice of int64s ([]int64) in packed format.
-func (o *Buffer) dec_slice_packed_int64(p *Properties, base uintptr) os.Error {
+func (o *Buffer) dec_slice_packed_int64(p *Properties, base uintptr) error {
v := (*[]int64)(unsafe.Pointer(base + p.offset))
nn, err := o.DecodeVarint()
@@ -605,7 +606,7 @@
}
// Decode a slice of strings ([]string).
-func (o *Buffer) dec_slice_string(p *Properties, base uintptr) os.Error {
+func (o *Buffer) dec_slice_string(p *Properties, base uintptr) error {
s, err := o.DecodeStringBytes()
if err != nil {
return err
@@ -618,7 +619,7 @@
}
// Decode a slice of slice of bytes ([][]byte).
-func (o *Buffer) dec_slice_slice_byte(p *Properties, base uintptr) os.Error {
+func (o *Buffer) dec_slice_slice_byte(p *Properties, base uintptr) error {
b, err := o.DecodeRawBytes(true)
if err != nil {
return err
@@ -631,7 +632,7 @@
}
// Decode a group.
-func (o *Buffer) dec_struct_group(p *Properties, base uintptr) os.Error {
+func (o *Buffer) dec_struct_group(p *Properties, base uintptr) error {
ptr := (**struct{})(unsafe.Pointer(base + p.offset))
typ := p.stype.Elem()
structv := unsafe.New(typ)
@@ -644,7 +645,7 @@
}
// Decode an embedded message.
-func (o *Buffer) dec_struct_message(p *Properties, base uintptr) (err os.Error) {
+func (o *Buffer) dec_struct_message(p *Properties, base uintptr) (err error) {
raw, e := o.DecodeRawBytes(false)
if e != nil {
return e
@@ -675,17 +676,17 @@
}
// Decode a slice of embedded messages.
-func (o *Buffer) dec_slice_struct_message(p *Properties, base uintptr) os.Error {
+func (o *Buffer) dec_slice_struct_message(p *Properties, base uintptr) error {
return o.dec_slice_struct(p, false, base)
}
// Decode a slice of embedded groups.
-func (o *Buffer) dec_slice_struct_group(p *Properties, base uintptr) os.Error {
+func (o *Buffer) dec_slice_struct_group(p *Properties, base uintptr) error {
return o.dec_slice_struct(p, true, base)
}
// Decode a slice of structs ([]*struct).
-func (o *Buffer) dec_slice_struct(p *Properties, is_group bool, base uintptr) os.Error {
+func (o *Buffer) dec_slice_struct(p *Properties, is_group bool, base uintptr) error {
v := (*[]*struct{})(unsafe.Pointer(base + p.offset))
y := *v
diff --git a/proto/encode.go b/proto/encode.go
index ae3820b..0b49e79 100644
--- a/proto/encode.go
+++ b/proto/encode.go
@@ -36,7 +36,7 @@
*/
import (
- "os"
+ "errors"
"reflect"
"runtime"
"unsafe"
@@ -51,20 +51,20 @@
t reflect.Type
}
-func (e *ErrRequiredNotSet) String() string {
+func (e *ErrRequiredNotSet) Error() string {
return "proto: required fields not set in " + e.t.String()
}
var (
// ErrRepeatedHasNil is the error returned if Marshal is called with
// a struct with a repeated field containing a nil element.
- ErrRepeatedHasNil = os.NewError("proto: repeated field has nil")
+ ErrRepeatedHasNil = errors.New("proto: repeated field has nil")
// ErrNil is the error returned if Marshal is called with nil.
- ErrNil = os.NewError("proto: Marshal called with nil")
+ ErrNil = errors.New("proto: Marshal called with nil")
// ErrNotPtr is the error returned if Marshal is called with a non-pointer.
- ErrNotPtr = os.NewError("proto: Marshal called with a non-pointer")
+ ErrNotPtr = errors.New("proto: Marshal called with a non-pointer")
)
// The fundamental encoders that put bytes on the wire.
@@ -95,7 +95,7 @@
// This is the format for the
// int32, int64, uint32, uint64, bool, and enum
// protocol buffer types.
-func (p *Buffer) EncodeVarint(x uint64) os.Error {
+func (p *Buffer) EncodeVarint(x uint64) error {
for x >= 1<<7 {
p.buf = append(p.buf, uint8(x&0x7f|0x80))
x >>= 7
@@ -107,7 +107,7 @@
// EncodeFixed64 writes a 64-bit integer to the Buffer.
// This is the format for the
// fixed64, sfixed64, and double protocol buffer types.
-func (p *Buffer) EncodeFixed64(x uint64) os.Error {
+func (p *Buffer) EncodeFixed64(x uint64) error {
p.buf = append(p.buf,
uint8(x),
uint8(x>>8),
@@ -123,7 +123,7 @@
// EncodeFixed32 writes a 32-bit integer to the Buffer.
// This is the format for the
// fixed32, sfixed32, and float protocol buffer types.
-func (p *Buffer) EncodeFixed32(x uint64) os.Error {
+func (p *Buffer) EncodeFixed32(x uint64) error {
p.buf = append(p.buf,
uint8(x),
uint8(x>>8),
@@ -135,7 +135,7 @@
// EncodeZigzag64 writes a zigzag-encoded 64-bit integer
// to the Buffer.
// This is the format used for the sint64 protocol buffer type.
-func (p *Buffer) EncodeZigzag64(x uint64) os.Error {
+func (p *Buffer) EncodeZigzag64(x uint64) error {
// use signed number to get arithmetic right shift.
return p.EncodeVarint(uint64((x << 1) ^ uint64((int64(x) >> 63))))
}
@@ -143,7 +143,7 @@
// EncodeZigzag32 writes a zigzag-encoded 32-bit integer
// to the Buffer.
// This is the format used for the sint32 protocol buffer type.
-func (p *Buffer) EncodeZigzag32(x uint64) os.Error {
+func (p *Buffer) EncodeZigzag32(x uint64) error {
// use signed number to get arithmetic right shift.
return p.EncodeVarint(uint64((uint32(x) << 1) ^ uint32((int32(x) >> 31))))
}
@@ -151,7 +151,7 @@
// EncodeRawBytes writes a count-delimited byte buffer to the Buffer.
// This is the format used for the bytes protocol buffer
// type and for embedded messages.
-func (p *Buffer) EncodeRawBytes(b []byte) os.Error {
+func (p *Buffer) EncodeRawBytes(b []byte) error {
p.EncodeVarint(uint64(len(b)))
p.buf = append(p.buf, b...)
return nil
@@ -159,7 +159,7 @@
// EncodeStringBytes writes an encoded string to the Buffer.
// This is the format used for the proto2 string type.
-func (p *Buffer) EncodeStringBytes(s string) os.Error {
+func (p *Buffer) EncodeStringBytes(s string) error {
p.EncodeVarint(uint64(len(s)))
p.buf = append(p.buf, s...)
return nil
@@ -167,12 +167,12 @@
// Marshaler is the interface representing objects that can marshal themselves.
type Marshaler interface {
- Marshal() ([]byte, os.Error)
+ Marshal() ([]byte, error)
}
// Marshal takes the protocol buffer struct represented by pb
// and encodes it into the wire format, returning the data.
-func Marshal(pb interface{}) ([]byte, os.Error) {
+func Marshal(pb interface{}) ([]byte, error) {
// Can the object marshal itself?
if m, ok := pb.(Marshaler); ok {
return m.Marshal()
@@ -188,7 +188,7 @@
// Marshal takes the protocol buffer struct represented by pb
// and encodes it into the wire format, writing the result to the
// Buffer.
-func (p *Buffer) Marshal(pb interface{}) os.Error {
+func (p *Buffer) Marshal(pb interface{}) error {
// Can the object marshal itself?
if m, ok := pb.(Marshaler); ok {
data, err := m.Marshal()
@@ -216,7 +216,7 @@
// Individual type encoders.
// Encode a bool.
-func (o *Buffer) enc_bool(p *Properties, base uintptr) os.Error {
+func (o *Buffer) enc_bool(p *Properties, base uintptr) error {
v := *(**bool)(unsafe.Pointer(base + p.offset))
if v == nil {
return ErrNil
@@ -231,7 +231,7 @@
}
// Encode an int32.
-func (o *Buffer) enc_int32(p *Properties, base uintptr) os.Error {
+func (o *Buffer) enc_int32(p *Properties, base uintptr) error {
v := *(**int32)(unsafe.Pointer(base + p.offset))
if v == nil {
return ErrNil
@@ -243,7 +243,7 @@
}
// Encode an int64.
-func (o *Buffer) enc_int64(p *Properties, base uintptr) os.Error {
+func (o *Buffer) enc_int64(p *Properties, base uintptr) error {
v := *(**int64)(unsafe.Pointer(base + p.offset))
if v == nil {
return ErrNil
@@ -255,7 +255,7 @@
}
// Encode a string.
-func (o *Buffer) enc_string(p *Properties, base uintptr) os.Error {
+func (o *Buffer) enc_string(p *Properties, base uintptr) error {
v := *(**string)(unsafe.Pointer(base + p.offset))
if v == nil {
return ErrNil
@@ -276,7 +276,7 @@
}
// Encode a message struct.
-func (o *Buffer) enc_struct_message(p *Properties, base uintptr) os.Error {
+func (o *Buffer) enc_struct_message(p *Properties, base uintptr) error {
// Can the object marshal itself?
iv := unsafe.Unreflect(p.stype, unsafe.Pointer(base+p.offset))
if m, ok := iv.(Marshaler); ok {
@@ -318,7 +318,7 @@
}
// Encode a group struct.
-func (o *Buffer) enc_struct_group(p *Properties, base uintptr) os.Error {
+func (o *Buffer) enc_struct_group(p *Properties, base uintptr) error {
v := *(**struct{})(unsafe.Pointer(base + p.offset))
if v == nil {
return ErrNil
@@ -336,7 +336,7 @@
}
// Encode a slice of bools ([]bool).
-func (o *Buffer) enc_slice_bool(p *Properties, base uintptr) os.Error {
+func (o *Buffer) enc_slice_bool(p *Properties, base uintptr) error {
s := *(*[]uint8)(unsafe.Pointer(base + p.offset))
l := len(s)
if l == 0 {
@@ -353,7 +353,7 @@
}
// Encode a slice of bools ([]bool) in packed format.
-func (o *Buffer) enc_slice_packed_bool(p *Properties, base uintptr) os.Error {
+func (o *Buffer) enc_slice_packed_bool(p *Properties, base uintptr) error {
s := *(*[]uint8)(unsafe.Pointer(base + p.offset))
l := len(s)
if l == 0 {
@@ -371,7 +371,7 @@
}
// Encode a slice of bytes ([]byte).
-func (o *Buffer) enc_slice_byte(p *Properties, base uintptr) os.Error {
+func (o *Buffer) enc_slice_byte(p *Properties, base uintptr) error {
s := *(*[]uint8)(unsafe.Pointer(base + p.offset))
if s == nil {
return ErrNil
@@ -382,7 +382,7 @@
}
// Encode a slice of int32s ([]int32).
-func (o *Buffer) enc_slice_int32(p *Properties, base uintptr) os.Error {
+func (o *Buffer) enc_slice_int32(p *Properties, base uintptr) error {
s := *(*[]uint32)(unsafe.Pointer(base + p.offset))
l := len(s)
if l == 0 {
@@ -397,7 +397,7 @@
}
// Encode a slice of int32s ([]int32) in packed format.
-func (o *Buffer) enc_slice_packed_int32(p *Properties, base uintptr) os.Error {
+func (o *Buffer) enc_slice_packed_int32(p *Properties, base uintptr) error {
s := *(*[]uint32)(unsafe.Pointer(base + p.offset))
l := len(s)
if l == 0 {
@@ -416,7 +416,7 @@
}
// Encode a slice of int64s ([]int64).
-func (o *Buffer) enc_slice_int64(p *Properties, base uintptr) os.Error {
+func (o *Buffer) enc_slice_int64(p *Properties, base uintptr) error {
s := *(*[]uint64)(unsafe.Pointer(base + p.offset))
l := len(s)
if l == 0 {
@@ -431,7 +431,7 @@
}
// Encode a slice of int64s ([]int64) in packed format.
-func (o *Buffer) enc_slice_packed_int64(p *Properties, base uintptr) os.Error {
+func (o *Buffer) enc_slice_packed_int64(p *Properties, base uintptr) error {
s := *(*[]uint64)(unsafe.Pointer(base + p.offset))
l := len(s)
if l == 0 {
@@ -450,7 +450,7 @@
}
// Encode a slice of slice of bytes ([][]byte).
-func (o *Buffer) enc_slice_slice_byte(p *Properties, base uintptr) os.Error {
+func (o *Buffer) enc_slice_slice_byte(p *Properties, base uintptr) error {
ss := *(*[][]uint8)(unsafe.Pointer(base + p.offset))
l := len(ss)
if l == 0 {
@@ -465,7 +465,7 @@
}
// Encode a slice of strings ([]string).
-func (o *Buffer) enc_slice_string(p *Properties, base uintptr) os.Error {
+func (o *Buffer) enc_slice_string(p *Properties, base uintptr) error {
ss := *(*[]string)(unsafe.Pointer(base + p.offset))
l := len(ss)
for i := 0; i < l; i++ {
@@ -477,7 +477,7 @@
}
// Encode a slice of message structs ([]*struct).
-func (o *Buffer) enc_slice_struct_message(p *Properties, base uintptr) os.Error {
+func (o *Buffer) enc_slice_struct_message(p *Properties, base uintptr) error {
s := *(*[]*struct{})(unsafe.Pointer(base + p.offset))
l := len(s)
typ := p.stype.Elem()
@@ -527,7 +527,7 @@
}
// Encode a slice of group structs ([]*struct).
-func (o *Buffer) enc_slice_struct_group(p *Properties, base uintptr) os.Error {
+func (o *Buffer) enc_slice_struct_group(p *Properties, base uintptr) error {
s := *(*[]*struct{})(unsafe.Pointer(base + p.offset))
l := len(s)
typ := p.stype.Elem()
@@ -556,7 +556,7 @@
}
// Encode an extension map.
-func (o *Buffer) enc_map(p *Properties, base uintptr) os.Error {
+func (o *Buffer) enc_map(p *Properties, base uintptr) error {
v := *(*map[int32]Extension)(unsafe.Pointer(base + p.offset))
if err := encodeExtensionMap(v); err != nil {
return err
@@ -568,7 +568,7 @@
}
// Encode a struct.
-func (o *Buffer) enc_struct(t reflect.Type, base uintptr) os.Error {
+func (o *Buffer) enc_struct(t reflect.Type, base uintptr) error {
prop := GetProperties(t)
required := prop.reqCount
// Encode fields in tag order so that decoders may use optimizations
diff --git a/proto/equal.go b/proto/equal.go
index 405d99a..be235a6 100644
--- a/proto/equal.go
+++ b/proto/equal.go
@@ -37,7 +37,6 @@
import (
"bytes"
"log"
- "os"
"reflect"
"strings"
)
@@ -190,7 +189,7 @@
log.Printf("proto: don't know how to compare extension %d of %v", extNum, base)
continue
}
- var err os.Error
+ var err error
if m1 == nil {
m1, err = decodeExtension(e1.enc, desc)
}
diff --git a/proto/extensions.go b/proto/extensions.go
index e6b7b55..d02cadc 100644
--- a/proto/extensions.go
+++ b/proto/extensions.go
@@ -36,7 +36,7 @@
*/
import (
- "os"
+ "errors"
"reflect"
"strconv"
)
@@ -97,20 +97,20 @@
}
// checkExtensionTypes checks that the given extension is valid for pb.
-func checkExtensionTypes(pb extendableProto, extension *ExtensionDesc) os.Error {
+func checkExtensionTypes(pb extendableProto, extension *ExtensionDesc) error {
// Check the extended type.
if a, b := reflect.TypeOf(pb), reflect.TypeOf(extension.ExtendedType); a != b {
- return os.NewError("bad extended type; " + b.String() + " does not extend " + a.String())
+ return errors.New("bad extended type; " + b.String() + " does not extend " + a.String())
}
// Check the range.
if !isExtensionField(pb, extension.Field) {
- return os.NewError("bad extension number; not in declared ranges")
+ return errors.New("bad extension number; not in declared ranges")
}
return nil
}
// encodeExtensionMap encodes any unmarshaled (unencoded) extensions in m.
-func encodeExtensionMap(m map[int32]Extension) os.Error {
+func encodeExtensionMap(m map[int32]Extension) error {
for k, e := range m {
if e.value == nil || e.desc == nil {
// Extension is only in its encoded form.
@@ -154,7 +154,7 @@
// GetExtension parses and returns the given extension of pb.
// If the extension is not present it returns (nil, nil).
-func GetExtension(pb extendableProto, extension *ExtensionDesc) (interface{}, os.Error) {
+func GetExtension(pb extendableProto, extension *ExtensionDesc) (interface{}, error) {
if err := checkExtensionTypes(pb, extension); err != nil {
return nil, err
}
@@ -169,7 +169,7 @@
// This shouldn't happen. If it does, it means that
// GetExtension was called twice with two different
// descriptors with the same field number.
- return nil, os.NewError("proto: descriptor conflict")
+ return nil, errors.New("proto: descriptor conflict")
}
return e.value, nil
}
@@ -188,7 +188,7 @@
}
// decodeExtension decodes an extension encoded in b.
-func decodeExtension(b []byte, extension *ExtensionDesc) (interface{}, os.Error) {
+func decodeExtension(b []byte, extension *ExtensionDesc) (interface{}, error) {
// Discard wire type and field number varint. It isn't needed.
_, n := DecodeVarint(b)
o := NewBuffer(b[n:])
@@ -210,10 +210,10 @@
// GetExtensions returns a slice of the extensions present in pb that are also listed in es.
// The returned slice has the same length as es; missing extensions will appear as nil elements.
-func GetExtensions(pb interface{}, es []*ExtensionDesc) (extensions []interface{}, err os.Error) {
+func GetExtensions(pb interface{}, es []*ExtensionDesc) (extensions []interface{}, err error) {
epb, ok := pb.(extendableProto)
if !ok {
- err = os.NewError("not an extendable proto")
+ err = errors.New("not an extendable proto")
return
}
extensions = make([]interface{}, len(es))
@@ -231,13 +231,13 @@
// - AddExtension
// SetExtension sets the specified extension of pb to the specified value.
-func SetExtension(pb extendableProto, extension *ExtensionDesc, value interface{}) os.Error {
+func SetExtension(pb extendableProto, extension *ExtensionDesc, value interface{}) error {
if err := checkExtensionTypes(pb, extension); err != nil {
return err
}
typ := reflect.TypeOf(extension.ExtensionType)
if typ != reflect.TypeOf(value) {
- return os.NewError("bad extension value type")
+ return errors.New("bad extension value type")
}
pb.ExtensionMap()[extension.Field] = Extension{desc: extension, value: value}
diff --git a/proto/message_set.go b/proto/message_set.go
index 05e18a8..b32ae06 100644
--- a/proto/message_set.go
+++ b/proto/message_set.go
@@ -37,13 +37,13 @@
import (
"bytes"
- "os"
+ "errors"
"reflect"
)
// ErrNoMessageTypeId occurs when a protocol buffer does not have a message type ID.
// A message type ID is required for storing a protocol buffer in a message set.
-var ErrNoMessageTypeId = os.NewError("proto does not have a message type ID")
+var ErrNoMessageTypeId = errors.New("proto does not have a message type ID")
// The first two types (_MessageSet_Item and MessageSet)
// model what the protocol compiler produces for the following protocol message:
@@ -101,7 +101,7 @@
return false
}
-func (ms *MessageSet) Unmarshal(pb interface{}) os.Error {
+func (ms *MessageSet) Unmarshal(pb interface{}) error {
if item := ms.find(pb); item != nil {
return Unmarshal(item.Message, pb)
}
@@ -111,7 +111,7 @@
return nil // TODO: return error instead?
}
-func (ms *MessageSet) Marshal(pb interface{}) os.Error {
+func (ms *MessageSet) Marshal(pb interface{}) error {
msg, err := Marshal(pb)
if err != nil {
return err
@@ -146,7 +146,7 @@
// MarshalMessageSet encodes the extension map represented by m in the message set wire format.
// It is called by generated Marshal methods on protocol buffer messages with the message_set_wire_format option.
-func MarshalMessageSet(m map[int32]Extension) ([]byte, os.Error) {
+func MarshalMessageSet(m map[int32]Extension) ([]byte, error) {
if err := encodeExtensionMap(m); err != nil {
return nil, err
}
@@ -168,7 +168,7 @@
// UnmarshalMessageSet decodes the extension map encoded in buf in the message set wire format.
// It is called by generated Unmarshal methods on protocol buffer messages with the message_set_wire_format option.
-func UnmarshalMessageSet(buf []byte, m map[int32]Extension) os.Error {
+func UnmarshalMessageSet(buf []byte, m map[int32]Extension) error {
ms := new(MessageSet)
if err := Unmarshal(buf, ms); err != nil {
return err
diff --git a/proto/properties.go b/proto/properties.go
index cec84ba..206bf1d 100644
--- a/proto/properties.go
+++ b/proto/properties.go
@@ -62,18 +62,18 @@
// Encoders are defined in encoder.go
// An encoder outputs the full representation of a field, including its
// tag and encoder type.
-type encoder func(p *Buffer, prop *Properties, base uintptr) os.Error
+type encoder func(p *Buffer, prop *Properties, base uintptr) error
// A valueEncoder encodes a single integer in a particular encoding.
-type valueEncoder func(o *Buffer, x uint64) os.Error
+type valueEncoder func(o *Buffer, x uint64) error
// Decoders are defined in decode.go
// A decoder creates a value from its wire representation.
// Unrecognized subelements are saved in unrec.
-type decoder func(p *Buffer, prop *Properties, base uintptr) os.Error
+type decoder func(p *Buffer, prop *Properties, base uintptr) error
// A valueDecoder decodes a single integer in a particular encoding.
-type valueDecoder func(o *Buffer) (x uint64, err os.Error)
+type valueDecoder func(o *Buffer) (x uint64, err error)
// StructProperties represents properties for all the fields of a struct.
type StructProperties struct {
@@ -190,7 +190,7 @@
return
}
- var err os.Error
+ var err error
p.Tag, err = strconv.Atoi(fields[1])
if err != nil {
return
@@ -476,7 +476,7 @@
}
// Get the address and type of a pointer to a struct from an interface.
-func getbase(pb interface{}) (t reflect.Type, b uintptr, err os.Error) {
+func getbase(pb interface{}) (t reflect.Type, b uintptr, err error) {
if pb == nil {
err = ErrNil
return
diff --git a/proto/text.go b/proto/text.go
index 0e2b874..9848858 100644
--- a/proto/text.go
+++ b/proto/text.go
@@ -54,7 +54,7 @@
c [1]byte // scratch
}
-func (w *textWriter) Write(p []byte) (n int, err os.Error) {
+func (w *textWriter) Write(p []byte) (n int, err error) {
n, err = len(p), nil
frags := strings.Split(string(p), "\n")
@@ -81,7 +81,7 @@
return
}
-func (w *textWriter) WriteByte(c byte) os.Error {
+func (w *textWriter) WriteByte(c byte) error {
w.c[0] = c
_, err := w.Write(w.c[:])
return err
@@ -341,7 +341,7 @@
}
}
-func writeUnknownInt(w *textWriter, x uint64, err os.Error) {
+func writeUnknownInt(w *textWriter, x uint64, err error) {
if err == nil {
fmt.Fprint(w, x)
} else {
diff --git a/proto/text_parser.go b/proto/text_parser.go
index 714c803..358764b 100644
--- a/proto/text_parser.go
+++ b/proto/text_parser.go
@@ -36,19 +36,18 @@
import (
"fmt"
- "os"
"reflect"
"strconv"
)
-// ParseError satisfies the os.Error interface.
+// ParseError satisfies the error interface.
type ParseError struct {
Message string
Line int // 1-based line number
Offset int // 0-based byte offset from start of input
}
-func (p *ParseError) String() string {
+func (p *ParseError) Error() string {
if p.Line == 1 {
// show offset only for first line
return fmt.Sprintf("line 1.%d: %v", p.Offset, p.Message)
@@ -443,10 +442,10 @@
return p.errorf("invalid %v: %v", v.Type(), tok.value)
}
-var notPtrStruct os.Error = &ParseError{"destination is not a pointer to a struct", 0, 0}
+var notPtrStruct error = &ParseError{"destination is not a pointer to a struct", 0, 0}
// UnmarshalText reads a protobuffer in Text format.
-func UnmarshalText(s string, pb interface{}) os.Error {
+func UnmarshalText(s string, pb interface{}) error {
v := reflect.ValueOf(pb)
if v.Kind() != reflect.Ptr || v.Elem().Kind() != reflect.Struct {
return notPtrStruct
diff --git a/proto/text_parser_test.go b/proto/text_parser_test.go
index 2383828..cf9d70c 100644
--- a/proto/text_parser_test.go
+++ b/proto/text_parser_test.go
@@ -259,9 +259,9 @@
// We do expect failure.
if err == nil {
t.Errorf("Test %d: Didn't get expected error: %v", i, test.error)
- } else if err.String() != test.error {
+ } else if err.Error() != test.error {
t.Errorf("Test %d: Incorrect error.\nHave: %v\nWant: %v",
- i, err.String(), test.error)
+ i, err, test.error)
}
}
}
@@ -293,7 +293,7 @@
pb := new(MyMessage)
err := UnmarshalText(benchInput, pb)
if err != nil {
- panic("Bad benchmark input: " + err.String())
+ panic("Bad benchmark input: " + err.Error())
}
}