]> Cypherpunks repositories - gostls13.git/commitdiff
os.Error API: don't export os.ErrorString, use os.NewError consistently
authorRobert Griesemer <gri@golang.org>
Wed, 22 Jun 2011 17:52:47 +0000 (10:52 -0700)
committerRobert Griesemer <gri@golang.org>
Wed, 22 Jun 2011 17:52:47 +0000 (10:52 -0700)
This is a core API change.

1) gofix misc src
2) Manual adjustments to the following files under src/pkg:
   gob/decode.go
   rpc/client.go
   os/error.go
   io/io.go
   bufio/bufio.go
   http/request.go
   websocket/client.go
as well as:
   src/cmd/gofix/testdata/*.go.in (reverted)
   test/fixedbugs/bug243.go
3) Implemented gofix patch (oserrorstring.go) and test case (oserrorstring_test.go)

Compiles and runs all tests.

R=r, rsc, gri
CC=golang-dev
https://golang.org/cl/4607052

80 files changed:
src/cmd/cgo/gcc.go
src/cmd/gofix/Makefile
src/cmd/gofix/oserrorstring.go [new file with mode: 0644]
src/cmd/gofix/oserrorstring_test.go [new file with mode: 0644]
src/cmd/gofix/testdata/reflect.decoder.go.out
src/cmd/gofix/testdata/reflect.encoder.go.out
src/cmd/gofix/testdata/reflect.export.go.out
src/cmd/gofix/testdata/reflect.print.go.out
src/cmd/gofix/testdata/reflect.read.go.out
src/cmd/gofix/testdata/reflect.scan.go.out
src/cmd/gofix/testdata/reflect.type.go.out
src/cmd/goinstall/download.go
src/cmd/goinstall/main.go
src/cmd/gotype/gotype.go
src/pkg/archive/tar/reader.go
src/pkg/big/int.go
src/pkg/big/nat.go
src/pkg/big/rat.go
src/pkg/bufio/bufio.go
src/pkg/bytes/buffer.go
src/pkg/compress/gzip/gunzip.go
src/pkg/compress/zlib/reader.go
src/pkg/crypto/cast5/cast5.go
src/pkg/crypto/dsa/dsa.go
src/pkg/crypto/openpgp/elgamal/elgamal.go
src/pkg/crypto/rsa/pkcs1v15.go
src/pkg/crypto/rsa/rsa.go
src/pkg/crypto/tls/conn.go
src/pkg/crypto/tls/handshake_client.go
src/pkg/crypto/tls/handshake_server.go
src/pkg/crypto/tls/key_agreement.go
src/pkg/crypto/tls/tls.go
src/pkg/crypto/x509/verify_test.go
src/pkg/crypto/x509/x509.go
src/pkg/debug/elf/file.go
src/pkg/exec/lp_plan9.go
src/pkg/exec/lp_unix.go
src/pkg/exec/lp_windows.go
src/pkg/fmt/print.go
src/pkg/fmt/scan.go
src/pkg/fmt/scan_test.go
src/pkg/go/build/dir.go
src/pkg/go/parser/interface.go
src/pkg/go/types/exportdata.go
src/pkg/go/types/gcimporter.go
src/pkg/gob/codec_test.go
src/pkg/gob/decode.go
src/pkg/gob/decoder.go
src/pkg/gob/encoder.go
src/pkg/gob/gobencdec_test.go
src/pkg/gob/type.go
src/pkg/http/client.go
src/pkg/http/fs.go
src/pkg/http/request.go
src/pkg/http/transport.go
src/pkg/http/url.go
src/pkg/image/gif/reader.go
src/pkg/io/io.go
src/pkg/mail/message.go
src/pkg/net/fd_darwin.go
src/pkg/net/iprawsock.go
src/pkg/net/net.go
src/pkg/net/udpsock.go
src/pkg/netchan/common.go
src/pkg/netchan/export.go
src/pkg/netchan/import.go
src/pkg/os/error.go
src/pkg/rand/rand_test.go
src/pkg/rpc/client.go
src/pkg/rpc/jsonrpc/all_test.go
src/pkg/rpc/server.go
src/pkg/rpc/server_test.go
src/pkg/strconv/atoi.go
src/pkg/strings/reader.go
src/pkg/syslog/syslog_unix.go
src/pkg/time/format.go
src/pkg/time/tick.go
src/pkg/websocket/client.go
src/pkg/xml/read.go
test/fixedbugs/bug243.go

index e7e99bc56b689e7d21ad7e361d8309e41c539311..6b930f151efbfc729a27c93a5bbf3a348b94521a 100644 (file)
@@ -230,9 +230,9 @@ func splitQuoted(s string) (r []string, err os.Error) {
                args = append(args, string(arg[:i]))
        }
        if quote != 0 {
-               err = os.ErrorString("unclosed quote")
+               err = os.NewError("unclosed quote")
        } else if escaped {
-               err = os.ErrorString("unfinished escaping")
+               err = os.NewError("unfinished escaping")
        }
        return args, err
 }
index 7504ddcbdf7441581afe4e72e488faaf05009ff1..b157649e873eb6f59391e1969bbdc4bed5c389f3 100644 (file)
@@ -9,6 +9,7 @@ GOFILES=\
        fix.go\
        netdial.go\
        main.go\
+       oserrorstring.go\
        osopen.go\
        httpfinalurl.go\
        httpheaders.go\
diff --git a/src/cmd/gofix/oserrorstring.go b/src/cmd/gofix/oserrorstring.go
new file mode 100644 (file)
index 0000000..5e61ab9
--- /dev/null
@@ -0,0 +1,75 @@
+// Copyright 2011 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+import (
+       "go/ast"
+)
+
+var oserrorstringFix = fix{
+       "oserrorstring",
+       oserrorstring,
+       `Replace os.ErrorString() conversions with calls to os.NewError().
+
+http://codereview.appspot.com/4607052
+`,
+}
+
+func init() {
+       register(oserrorstringFix)
+}
+
+func oserrorstring(f *ast.File) bool {
+       if !imports(f, "os") {
+               return false
+       }
+
+       fixed := false
+       walk(f, func(n interface{}) {
+               // The conversion os.ErrorString(x) looks like a call
+               // of os.ErrorString with one argument.
+               if call := callExpr(n, "os", "ErrorString"); call != nil {
+                       // os.ErrorString(args) -> os.NewError(args)
+                       call.Fun.(*ast.SelectorExpr).Sel.Name = "NewError"
+                       // os.ErrorString(args) -> os.NewError(args)
+                       call.Fun.(*ast.SelectorExpr).Sel.Name = "NewError"
+                       fixed = true
+                       return
+               }
+
+               // Remove os.Error type from variable declarations initialized
+               // with an os.NewError.
+               // (An *ast.ValueSpec may also be used in a const declaration
+               // but those won't be initialized with a call to os.NewError.)
+               if spec, ok := n.(*ast.ValueSpec); ok &&
+                       len(spec.Names) == 1 &&
+                       isPkgDot(spec.Type, "os", "Error") &&
+                       len(spec.Values) == 1 &&
+                       callExpr(spec.Values[0], "os", "NewError") != nil {
+                       // var name os.Error = os.NewError(x) ->
+                       // var name          = os.NewError(x)
+                       spec.Type = nil
+                       fixed = true
+                       return
+               }
+
+               // Other occurrences of os.ErrorString are not fixed
+               // but they are rare.
+
+       })
+       return fixed
+}
+
+
+// callExpr returns the call expression if x is a call to pkg.name with one argument;
+// otherwise it returns nil.
+func callExpr(x interface{}, pkg, name string) *ast.CallExpr {
+       if call, ok := x.(*ast.CallExpr); ok &&
+               len(call.Args) == 1 &&
+               isPkgDot(call.Fun, pkg, name) {
+               return call
+       }
+       return nil
+}
diff --git a/src/cmd/gofix/oserrorstring_test.go b/src/cmd/gofix/oserrorstring_test.go
new file mode 100644 (file)
index 0000000..070d922
--- /dev/null
@@ -0,0 +1,57 @@
+// Copyright 2011 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+func init() {
+       addTestCases(oserrorstringTests)
+}
+
+var oserrorstringTests = []testCase{
+       {
+               Name: "oserrorstring.0",
+               In: `package main
+
+import "os"
+
+var _ = os.ErrorString("foo")
+var _ os.Error = os.ErrorString("bar1")
+var _ os.Error = os.NewError("bar2")
+var _ os.Error = MyError("bal") // don't rewrite this one
+
+var (
+       _          = os.ErrorString("foo")
+       _ os.Error = os.ErrorString("bar1")
+       _ os.Error = os.NewError("bar2")
+       _ os.Error = MyError("bal") // don't rewrite this one
+)
+
+func _() (err os.Error) {
+       err = os.ErrorString("foo")
+       return os.ErrorString("foo")
+}
+`,
+               Out: `package main
+
+import "os"
+
+var _ = os.NewError("foo")
+var _ = os.NewError("bar1")
+var _ = os.NewError("bar2")
+var _ os.Error = MyError("bal") // don't rewrite this one
+
+var (
+       _          = os.NewError("foo")
+       _          = os.NewError("bar1")
+       _          = os.NewError("bar2")
+       _ os.Error = MyError("bal") // don't rewrite this one
+)
+
+func _() (err os.Error) {
+       err = os.NewError("foo")
+       return os.NewError("foo")
+}
+`,
+       },
+}
index 170eedb05f784fbe8c1a2ed6e38a3b1237086880..ece88ecbed0031ba533c3738999accf234af685e 100644 (file)
@@ -44,7 +44,7 @@ func NewDecoder(r io.Reader) *Decoder {
 func (dec *Decoder) recvType(id typeId) {
        // Have we already seen this type?  That's an error
        if id < firstUserId || dec.wireType[id] != nil {
-               dec.err = os.ErrorString("gob: duplicate type received")
+               dec.err = os.NewError("gob: duplicate type received")
                return
        }
 
@@ -143,7 +143,7 @@ func (dec *Decoder) decodeTypeSequence(isInterface bool) typeId {
                // will be absorbed by recvMessage.)
                if dec.buf.Len() > 0 {
                        if !isInterface {
-                               dec.err = os.ErrorString("extra data in buffer")
+                               dec.err = os.NewError("extra data in buffer")
                                break
                        }
                        dec.nextUint()
@@ -165,7 +165,7 @@ func (dec *Decoder) Decode(e interface{}) os.Error {
        // If e represents a value as opposed to a pointer, the answer won't
        // get back to the caller.  Make sure it's a pointer.
        if value.Type().Kind() != reflect.Ptr {
-               dec.err = os.ErrorString("gob: attempt to decode into a non-pointer")
+               dec.err = os.NewError("gob: attempt to decode into a non-pointer")
                return dec.err
        }
        return dec.DecodeValue(value)
index 781ef6504c0189ca103225e25d4a0cf4632f72e6..925d39301e6e1d3089a97c65e4058f4f7250b05c 100644 (file)
@@ -50,7 +50,7 @@ func (enc *Encoder) popWriter() {
 }
 
 func (enc *Encoder) badType(rt reflect.Type) {
-       enc.setError(os.ErrorString("gob: can't encode type " + rt.String()))
+       enc.setError(os.NewError("gob: can't encode type " + rt.String()))
 }
 
 func (enc *Encoder) setError(err os.Error) {
index 486a812e2b77cbab640eede5e307d171f6680f61..460edb40bfe45f2e5cc8748706cb59fc5d13a36b 100644 (file)
@@ -343,20 +343,20 @@ func (exp *Exporter) Sync(timeout int64) os.Error {
 func checkChan(chT interface{}, dir Dir) (reflect.Value, os.Error) {
        chanType := reflect.TypeOf(chT)
        if chanType.Kind() != reflect.Chan {
-               return reflect.Value{}, os.ErrorString("not a channel")
+               return reflect.Value{}, os.NewError("not a channel")
        }
        if dir != Send && dir != Recv {
-               return reflect.Value{}, os.ErrorString("unknown channel direction")
+               return reflect.Value{}, os.NewError("unknown channel direction")
        }
        switch chanType.ChanDir() {
        case reflect.BothDir:
        case reflect.SendDir:
                if dir != Recv {
-                       return reflect.Value{}, os.ErrorString("to import/export with Send, must provide <-chan")
+                       return reflect.Value{}, os.NewError("to import/export with Send, must provide <-chan")
                }
        case reflect.RecvDir:
                if dir != Send {
-                       return reflect.Value{}, os.ErrorString("to import/export with Recv, must provide chan<-")
+                       return reflect.Value{}, os.NewError("to import/export with Recv, must provide chan<-")
                }
        }
        return reflect.ValueOf(chT), nil
@@ -376,7 +376,7 @@ func (exp *Exporter) Export(name string, chT interface{}, dir Dir) os.Error {
        defer exp.mu.Unlock()
        _, present := exp.names[name]
        if present {
-               return os.ErrorString("channel name already being exported:" + name)
+               return os.NewError("channel name already being exported:" + name)
        }
        exp.names[name] = &chanDir{ch, dir}
        return nil
@@ -393,7 +393,7 @@ func (exp *Exporter) Hangup(name string) os.Error {
        // TODO drop all instances of channel from client sets
        exp.mu.Unlock()
        if !ok {
-               return os.ErrorString("netchan export: hangup: no such channel: " + name)
+               return os.NewError("netchan export: hangup: no such channel: " + name)
        }
        chDir.ch.Close()
        return nil
index 079948ccae004863ad80d5c7f50f165f378dcba0..10379bd2048dbebc4bd82ad5a1197926bc853927 100644 (file)
@@ -185,7 +185,7 @@ func Sprintf(format string, a ...interface{}) string {
 // Errorf formats according to a format specifier and returns the string 
 // converted to an os.ErrorString, which satisfies the os.Error interface.
 func Errorf(format string, a ...interface{}) os.Error {
-       return os.ErrorString(Sprintf(format, a...))
+       return os.NewError(Sprintf(format, a...))
 }
 
 // These routines do not take a format string
index 554b2a61b79cbb7b4f37921adf6e252cfccdbe8a..a6b126744c4423a0bcaafa77767ee3203287fae9 100644 (file)
@@ -244,7 +244,7 @@ func (p *Parser) unmarshal(val reflect.Value, start *StartElement) os.Error {
 
        switch v := val; v.Kind() {
        default:
-               return os.ErrorString("unknown type " + v.Type().String())
+               return os.NewError("unknown type " + v.Type().String())
 
        case reflect.Slice:
                typ := v.Type()
@@ -483,7 +483,7 @@ Loop:
        case reflect.Invalid:
                // Probably a comment, handled below
        default:
-               return os.ErrorString("cannot happen: unknown type " + t.Type().String())
+               return os.NewError("cannot happen: unknown type " + t.Type().String())
        case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
                if !getInt64() {
                        return err
index 42bc52c92bcca480857039c4db146ccf61e1aae5..2b07115e99b9630da65b2b3801ea7859d34f9d41 100644 (file)
@@ -167,7 +167,7 @@ type ssave struct {
 // satisfies io.Reader. It will never be called when used as
 // intended, so there is no need to make it actually work.
 func (s *ss) Read(buf []byte) (n int, err os.Error) {
-       return 0, os.ErrorString("ScanState's Read should not be called. Use ReadRune")
+       return 0, os.NewError("ScanState's Read should not be called. Use ReadRune")
 }
 
 func (s *ss) ReadRune() (rune int, size int, err os.Error) {
@@ -240,7 +240,7 @@ func (s *ss) error(err os.Error) {
 }
 
 func (s *ss) errorString(err string) {
-       panic(scanError{os.ErrorString(err)})
+       panic(scanError{os.NewError(err)})
 }
 
 func (s *ss) Token(skipSpace bool, f func(int) bool) (tok []byte, err os.Error) {
@@ -426,8 +426,8 @@ func (s *ss) typeError(field interface{}, expected string) {
        s.errorString("expected field of type pointer to " + expected + "; found " + reflect.TypeOf(field).String())
 }
 
-var complexError = os.ErrorString("syntax error scanning complex number")
-var boolError = os.ErrorString("syntax error scanning boolean")
+var complexError = os.NewError("syntax error scanning complex number")
+var boolError = os.NewError("syntax error scanning boolean")
 
 // consume reads the next rune in the input and reports whether it is in the ok string.
 // If accept is true, it puts the character into the input token.
index a39b074fed2f6c3ab8745addcdabba9a414872a7..9cd78296ddf3c71992d35ef19557e9821559789c 100644 (file)
@@ -67,7 +67,7 @@ func validUserType(rt reflect.Type) (ut *userTypeInfo, err os.Error) {
                ut.base = pt.Elem()
                if ut.base == slowpoke { // ut.base lapped slowpoke
                        // recursive pointer type.
-                       return nil, os.ErrorString("can't represent recursive pointer type " + ut.base.String())
+                       return nil, os.NewError("can't represent recursive pointer type " + ut.base.String())
                }
                if ut.indir%2 == 0 {
                        slowpoke = slowpoke.Elem()
@@ -524,7 +524,7 @@ func newTypeObject(name string, ut *userTypeInfo, rt reflect.Type) (gobType, os.
                return st, nil
 
        default:
-               return nil, os.ErrorString("gob NewTypeObject can't handle type: " + rt.String())
+               return nil, os.NewError("gob NewTypeObject can't handle type: " + rt.String())
        }
        return nil, nil
 }
index 0f127d134bfce7c5e36bfaf879fd1dad245cbc4d..d209fa82bf37c094d68593111f6fd35bacc68ef0 100644 (file)
@@ -160,14 +160,14 @@ func isRemote(pkg string) bool {
 // download checks out or updates pkg from the remote server.
 func download(pkg, srcDir string) os.Error {
        if strings.Contains(pkg, "..") {
-               return os.ErrorString("invalid path (contains ..)")
+               return os.NewError("invalid path (contains ..)")
        }
        var m *vcsMatch
        for _, v := range vcsList {
                for _, host := range v.defaultHosts {
                        if hm := host.pattern.FindStringSubmatch(pkg); hm != nil {
                                if v.suffix != "" && strings.HasSuffix(hm[1], v.suffix) {
-                                       return os.ErrorString("repository " + pkg + " should not have " + v.suffix + " suffix")
+                                       return os.NewError("repository " + pkg + " should not have " + v.suffix + " suffix")
                                }
                                repo := host.protocol + "://" + hm[1] + v.suffix
                                m = &vcsMatch{v, hm[1], repo}
@@ -175,7 +175,7 @@ func download(pkg, srcDir string) os.Error {
                }
        }
        if m == nil {
-               return os.ErrorString("cannot download: " + pkg)
+               return os.NewError("cannot download: " + pkg)
        }
        return vcsCheckout(m.vcs, srcDir, m.prefix, m.repo, pkg)
 }
@@ -205,7 +205,7 @@ func vcsCheckout(vcs *vcs, srcDir, pkgprefix, repo, dashpath string) os.Error {
        dst := filepath.Join(srcDir, filepath.FromSlash(pkgprefix))
        dir, err := os.Stat(filepath.Join(dst, vcs.metadir))
        if err == nil && !dir.IsDirectory() {
-               return os.ErrorString("not a directory: " + dst)
+               return os.NewError("not a directory: " + dst)
        }
        if err != nil {
                parent, _ := filepath.Split(dst)
index 64fae08688f7646d3326e7c27d623a9973de3e53..c4383aa077fefca1619acbce4250efe4dab58074 100644 (file)
@@ -279,7 +279,7 @@ func genRun(dir string, stdin []byte, arg []string, quiet bool) os.Error {
                        os.Stderr.Write(out)
                        fmt.Fprintf(os.Stderr, "--- %s\n", err)
                }
-               return os.ErrorString("running " + arg[0] + ": " + err.String())
+               return os.NewError("running " + arg[0] + ": " + err.String())
        }
        return nil
 }
index b6a23ae5fa83af22418216cc015295a22f5dad97..501ead443c0ef23b4dd005c2636b5b649f8ce817 100644 (file)
@@ -114,7 +114,7 @@ func parseFiles(fset *token.FileSet, filenames []string) (files map[string]*ast.
                }
                if file := parse(fset, filename, src); file != nil {
                        if files[filename] != nil {
-                               report(os.ErrorString(fmt.Sprintf("%q: duplicate file", filename)))
+                               report(os.NewError(fmt.Sprintf("%q: duplicate file", filename)))
                                continue
                        }
                        files[filename] = file
index ad06b6dac548bd97928ee597406557c3db178c88..45d95c3df299feacdd74b2b4cad9ed8609e80aed 100644 (file)
@@ -16,7 +16,7 @@ import (
 )
 
 var (
-       HeaderError os.Error = os.ErrorString("invalid tar header")
+       HeaderError = os.NewError("invalid tar header")
 )
 
 // A Reader provides sequential access to the contents of a tar archive.
index 22bdf8d2f8f34983559dfefe0011897e5ff5169d..4d47a82d5fcd749d564d599a01c8ad8344451c8c 100755 (executable)
@@ -430,7 +430,7 @@ func (z *Int) Scan(s fmt.ScanState, ch int) os.Error {
        case 's', 'v':
                // let scan determine the base
        default:
-               return os.ErrorString("Int.Scan: invalid verb")
+               return os.NewError("Int.Scan: invalid verb")
        }
        _, _, err := z.scan(s, base)
        return err
@@ -834,11 +834,11 @@ func (z *Int) GobEncode() ([]byte, os.Error) {
 // GobDecode implements the gob.GobDecoder interface.
 func (z *Int) GobDecode(buf []byte) os.Error {
        if len(buf) == 0 {
-               return os.ErrorString("Int.GobDecode: no data")
+               return os.NewError("Int.GobDecode: no data")
        }
        b := buf[0]
        if b>>1 != intGobVersion {
-               return os.ErrorString(fmt.Sprintf("Int.GobDecode: encoding version %d not supported", b>>1))
+               return os.NewError(fmt.Sprintf("Int.GobDecode: encoding version %d not supported", b>>1))
        }
        z.neg = b&1 != 0
        z.abs = z.abs.setBytes(buf[1:])
index 734568e068cdaabe08312c0fdf43d36fc4516bf7..6755832bec4ff4f9fcae0103d6714540c291bd2f 100755 (executable)
@@ -644,7 +644,7 @@ func hexValue(ch int) Word {
 func (z nat) scan(r io.RuneScanner, base int) (nat, int, os.Error) {
        // reject illegal bases
        if base < 0 || base == 1 || MaxBase < base {
-               return z, 0, os.ErrorString("illegal number base")
+               return z, 0, os.NewError("illegal number base")
        }
 
        // one char look-ahead
@@ -721,7 +721,7 @@ func (z nat) scan(r io.RuneScanner, base int) (nat, int, os.Error) {
                return z, 10, nil
        case base != 0 || b != 8:
                // there was neither a mantissa digit nor the octal prefix 0
-               return z, int(b), os.ErrorString("syntax error scanning number")
+               return z, int(b), os.NewError("syntax error scanning number")
        }
 
        return z.norm(), int(b), nil
index 1fbf8c4596c1d2f5454286552a6233e37d043f27..b61cbb966b64bb94ad087abc03115b75cadc8a77 100644 (file)
@@ -227,10 +227,10 @@ func (z *Rat) Scan(s fmt.ScanState, ch int) os.Error {
                return err
        }
        if strings.IndexRune("efgEFGv", ch) < 0 {
-               return os.ErrorString("Rat.Scan: invalid verb")
+               return os.NewError("Rat.Scan: invalid verb")
        }
        if _, ok := z.SetString(string(tok)); !ok {
-               return os.ErrorString("Rat.Scan: invalid syntax")
+               return os.NewError("Rat.Scan: invalid syntax")
        }
        return nil
 }
@@ -368,7 +368,7 @@ func (z *Rat) GobEncode() ([]byte, os.Error) {
        n := i - j
        if int(uint32(n)) != n {
                // this should never happen
-               return nil, os.ErrorString("Rat.GobEncode: numerator too large")
+               return nil, os.NewError("Rat.GobEncode: numerator too large")
        }
        binary.BigEndian.PutUint32(buf[j-4:j], uint32(n))
        j -= 1 + 4
@@ -384,11 +384,11 @@ func (z *Rat) GobEncode() ([]byte, os.Error) {
 // GobDecode implements the gob.GobDecoder interface.
 func (z *Rat) GobDecode(buf []byte) os.Error {
        if len(buf) == 0 {
-               return os.ErrorString("Rat.GobDecode: no data")
+               return os.NewError("Rat.GobDecode: no data")
        }
        b := buf[0]
        if b>>1 != ratGobVersion {
-               return os.ErrorString(fmt.Sprintf("Rat.GobDecode: encoding version %d not supported", b>>1))
+               return os.NewError(fmt.Sprintf("Rat.GobDecode: encoding version %d not supported", b>>1))
        }
        const j = 1 + 4
        i := j + binary.BigEndian.Uint32(buf[j-4:j])
index eaae8bb42c35bd8a75e4dd618073b9fa9b91b825..497e770fb15e1c68f8062024e16fabb0a99f522a 100644 (file)
@@ -22,9 +22,11 @@ const (
 
 // Errors introduced by this package.
 type Error struct {
-       os.ErrorString
+       ErrorString string
 }
 
+func (err *Error) String() string { return err.ErrorString }
+
 var (
        ErrInvalidUnreadByte os.Error = &Error{"bufio: invalid use of UnreadByte"}
        ErrInvalidUnreadRune os.Error = &Error{"bufio: invalid use of UnreadRune"}
index 1acd4e05cae3a8c1ec238cda8a3ac881117877bd..5de86105d058fa68eba3909877655703ba941ea2 100644 (file)
@@ -280,7 +280,7 @@ func (b *Buffer) ReadRune() (r int, size int, err os.Error) {
 // from any read operation.)
 func (b *Buffer) UnreadRune() os.Error {
        if b.lastRead != opReadRune {
-               return os.ErrorString("bytes.Buffer: UnreadRune: previous operation was not ReadRune")
+               return os.NewError("bytes.Buffer: UnreadRune: previous operation was not ReadRune")
        }
        b.lastRead = opInvalid
        if b.off > 0 {
@@ -295,7 +295,7 @@ func (b *Buffer) UnreadRune() os.Error {
 // returns an error.
 func (b *Buffer) UnreadByte() os.Error {
        if b.lastRead != opReadRune && b.lastRead != opRead {
-               return os.ErrorString("bytes.Buffer: UnreadByte: previous operation was not a read")
+               return os.NewError("bytes.Buffer: UnreadByte: previous operation was not a read")
        }
        b.lastRead = opInvalid
        if b.off > 0 {
index b0ddc81d2529ada6fbdbcdc27954066fc1c576fa..6ac9293d771b96aa9013f7a1cb7b2b1d39197b33 100644 (file)
@@ -36,8 +36,8 @@ func makeReader(r io.Reader) flate.Reader {
        return bufio.NewReader(r)
 }
 
-var HeaderError os.Error = os.ErrorString("invalid gzip header")
-var ChecksumError os.Error = os.ErrorString("gzip checksum error")
+var HeaderError = os.NewError("invalid gzip header")
+var ChecksumError = os.NewError("gzip checksum error")
 
 // The gzip file stores a header giving metadata about the compressed file.
 // That header is exposed as the fields of the Compressor and Decompressor structs.
index 8a3ef1580aaeb74b5afb305bb5e5ef8c21b7358a..78dabdf4d8c9df25918c554a284dbae343d3b8a5 100644 (file)
@@ -34,9 +34,9 @@ import (
 
 const zlibDeflate = 8
 
-var ChecksumError os.Error = os.ErrorString("zlib checksum error")
-var HeaderError os.Error = os.ErrorString("invalid zlib header")
-var DictionaryError os.Error = os.ErrorString("invalid zlib dictionary")
+var ChecksumError = os.NewError("zlib checksum error")
+var HeaderError = os.NewError("invalid zlib header")
+var DictionaryError = os.NewError("invalid zlib dictionary")
 
 type reader struct {
        r            flate.Reader
index cb62e3132e8d17886f68ed2b7d6cf17bdd717026..e9d4a24e26b776305061fd44a379bf9119c7dca7 100644 (file)
@@ -20,7 +20,7 @@ type Cipher struct {
 
 func NewCipher(key []byte) (c *Cipher, err os.Error) {
        if len(key) != KeySize {
-               return nil, os.ErrorString("CAST5: keys must be 16 bytes")
+               return nil, os.NewError("CAST5: keys must be 16 bytes")
        }
 
        c = new(Cipher)
index f0af8bb427ed2f6a0cf6cf289c25093952cfc0e3..a5f96fe942c335528cca108d1d307187f9cfcf8d 100644 (file)
@@ -79,7 +79,7 @@ func GenerateParameters(params *Parameters, rand io.Reader, sizes ParameterSizes
                L = 3072
                N = 256
        default:
-               return os.ErrorString("crypto/dsa: invalid ParameterSizes")
+               return os.NewError("crypto/dsa: invalid ParameterSizes")
        }
 
        qBytes := make([]byte, N/8)
@@ -158,7 +158,7 @@ GeneratePrimes:
 // PrivateKey must already be valid (see GenerateParameters).
 func GenerateKey(priv *PrivateKey, rand io.Reader) os.Error {
        if priv.P == nil || priv.Q == nil || priv.G == nil {
-               return os.ErrorString("crypto/dsa: parameters not set up before generating key")
+               return os.NewError("crypto/dsa: parameters not set up before generating key")
        }
 
        x := new(big.Int)
index 3dc4178748b22e3090e0a2d25579426d87e43f63..99a6e3e1f2d7074f0024afb7f083e1858602f63f 100644 (file)
@@ -37,7 +37,7 @@ type PrivateKey struct {
 func Encrypt(random io.Reader, pub *PublicKey, msg []byte) (c1, c2 *big.Int, err os.Error) {
        pLen := (pub.P.BitLen() + 7) / 8
        if len(msg) > pLen-11 {
-               err = os.ErrorString("elgamal: message too long")
+               err = os.NewError("elgamal: message too long")
                return
        }
 
@@ -97,7 +97,7 @@ func Decrypt(priv *PrivateKey, c1, c2 *big.Int) (msg []byte, err os.Error) {
        }
 
        if firstByteIsTwo != 1 || lookingForIndex != 0 || index < 9 {
-               return nil, os.ErrorString("elgamal: decryption error")
+               return nil, os.NewError("elgamal: decryption error")
        }
        return em[index+1:], nil
 }
index 3defa62ea6d36263846482808dcb1997b93e049a..6006231145ac487a99462786d031d5cbc14c2ad2 100644 (file)
@@ -232,11 +232,11 @@ func VerifyPKCS1v15(pub *PublicKey, hash crypto.Hash, hashed []byte, sig []byte)
 func pkcs1v15HashInfo(hash crypto.Hash, inLen int) (hashLen int, prefix []byte, err os.Error) {
        hashLen = hash.Size()
        if inLen != hashLen {
-               return 0, nil, os.ErrorString("input must be hashed message")
+               return 0, nil, os.NewError("input must be hashed message")
        }
        prefix, ok := hashPrefixes[hash]
        if !ok {
-               return 0, nil, os.ErrorString("unsupported hash function")
+               return 0, nil, os.NewError("unsupported hash function")
        }
        return
 }
index 380f715701a06dc01ec2509cb7027709a143a3a0..6957659f2843052fd3511f3d0847b2d597760ec3 100644 (file)
@@ -64,7 +64,7 @@ func (priv *PrivateKey) Validate() os.Error {
        // easy for an attack to generate composites that pass this test.
        for _, prime := range priv.Primes {
                if !big.ProbablyPrime(prime, 20) {
-                       return os.ErrorString("prime factor is composite")
+                       return os.NewError("prime factor is composite")
                }
        }
 
@@ -74,7 +74,7 @@ func (priv *PrivateKey) Validate() os.Error {
                modulus.Mul(modulus, prime)
        }
        if modulus.Cmp(priv.N) != 0 {
-               return os.ErrorString("invalid modulus")
+               return os.NewError("invalid modulus")
        }
        // Check that e and totient(Πprimes) are coprime.
        totient := new(big.Int).Set(bigOne)
@@ -88,13 +88,13 @@ func (priv *PrivateKey) Validate() os.Error {
        y := new(big.Int)
        big.GcdInt(gcd, x, y, totient, e)
        if gcd.Cmp(bigOne) != 0 {
-               return os.ErrorString("invalid public exponent E")
+               return os.NewError("invalid public exponent E")
        }
        // Check that de â‰¡ 1 (mod totient(Πprimes))
        de := new(big.Int).Mul(priv.D, e)
        de.Mod(de, totient)
        if de.Cmp(bigOne) != 0 {
-               return os.ErrorString("invalid private exponent D")
+               return os.NewError("invalid private exponent D")
        }
        return nil
 }
@@ -127,7 +127,7 @@ func GenerateMultiPrimeKey(random io.Reader, nprimes int, bits int) (priv *Priva
        priv.E = 3
 
        if nprimes < 2 {
-               return nil, os.ErrorString("rsa.GenerateMultiPrimeKey: nprimes must be >= 2")
+               return nil, os.NewError("rsa.GenerateMultiPrimeKey: nprimes must be >= 2")
        }
 
        primes := make([]*big.Int, nprimes)
index 097e182bda3f3875dcfdc0215055a3f8486eb35c..fac65afd9cfb84807d79abdfcb99f19bd76898a3 100644 (file)
@@ -790,10 +790,10 @@ func (c *Conn) VerifyHostname(host string) os.Error {
        c.handshakeMutex.Lock()
        defer c.handshakeMutex.Unlock()
        if !c.isClient {
-               return os.ErrorString("VerifyHostname called on TLS server connection")
+               return os.NewError("VerifyHostname called on TLS server connection")
        }
        if !c.handshakeComplete {
-               return os.ErrorString("TLS handshake has not yet been performed")
+               return os.NewError("TLS handshake has not yet been performed")
        }
        return c.peerCertificates[0].VerifyHostname(host)
 }
index c758c96d4ef7a4b8cb05198c985bee2ac1fbb391..15604cea7ea6bff9258d95c7ce46628ed0a19327 100644 (file)
@@ -40,7 +40,7 @@ func (c *Conn) clientHandshake() os.Error {
        _, err := io.ReadFull(c.config.rand(), hello.random[4:])
        if err != nil {
                c.sendAlert(alertInternalError)
-               return os.ErrorString("short read from Rand")
+               return os.NewError("short read from Rand")
        }
 
        finishedHash.Write(hello.marshal())
@@ -69,7 +69,7 @@ func (c *Conn) clientHandshake() os.Error {
 
        if !hello.nextProtoNeg && serverHello.nextProtoNeg {
                c.sendAlert(alertHandshakeFailure)
-               return os.ErrorString("server advertised unrequested NPN")
+               return os.NewError("server advertised unrequested NPN")
        }
 
        suite, suiteId := mutualCipherSuite(c.config.cipherSuites(), serverHello.cipherSuite)
@@ -92,7 +92,7 @@ func (c *Conn) clientHandshake() os.Error {
                cert, err := x509.ParseCertificate(asn1Data)
                if err != nil {
                        c.sendAlert(alertBadCertificate)
-                       return os.ErrorString("failed to parse certificate from server: " + err.String())
+                       return os.NewError("failed to parse certificate from server: " + err.String())
                }
                certs[i] = cert
        }
index e9431c6fad841550f40fefe3e434f928ae6e5756..44a32404148cbdafb642499e7c434725b062dbeb 100644 (file)
@@ -173,7 +173,7 @@ FindCipherSuite:
                        cert, err := x509.ParseCertificate(asn1Data)
                        if err != nil {
                                c.sendAlert(alertBadCertificate)
-                               return os.ErrorString("could not parse client's certificate: " + err.String())
+                               return os.NewError("could not parse client's certificate: " + err.String())
                        }
                        certs[i] = cert
                }
@@ -182,7 +182,7 @@ FindCipherSuite:
                for i := 1; i < len(certs); i++ {
                        if err := certs[i-1].CheckSignatureFrom(certs[i]); err != nil {
                                c.sendAlert(alertBadCertificate)
-                               return os.ErrorString("could not validate certificate signature: " + err.String())
+                               return os.NewError("could not validate certificate signature: " + err.String())
                        }
                }
 
@@ -229,7 +229,7 @@ FindCipherSuite:
                err = rsa.VerifyPKCS1v15(pub, crypto.MD5SHA1, digest, certVerify.signature)
                if err != nil {
                        c.sendAlert(alertBadCertificate)
-                       return os.ErrorString("could not validate signature of connection nonces: " + err.String())
+                       return os.NewError("could not validate signature of connection nonces: " + err.String())
                }
 
                finishedHash.Write(certVerify.marshal())
index c83ef3f09d229d5bd37459d555aa884fd97ec928..48472fb6a952c14432ba0c5c3b50282e1292ee61 100644 (file)
@@ -32,11 +32,11 @@ func (ka rsaKeyAgreement) processClientKeyExchange(config *Config, ckx *clientKe
        }
 
        if len(ckx.ciphertext) < 2 {
-               return nil, os.ErrorString("bad ClientKeyExchange")
+               return nil, os.NewError("bad ClientKeyExchange")
        }
        ciphertextLen := int(ckx.ciphertext[0])<<8 | int(ckx.ciphertext[1])
        if ciphertextLen != len(ckx.ciphertext)-2 {
-               return nil, os.ErrorString("bad ClientKeyExchange")
+               return nil, os.NewError("bad ClientKeyExchange")
        }
        ciphertext := ckx.ciphertext[2:]
 
@@ -54,7 +54,7 @@ func (ka rsaKeyAgreement) processClientKeyExchange(config *Config, ckx *clientKe
 }
 
 func (ka rsaKeyAgreement) processServerKeyExchange(config *Config, clientHello *clientHelloMsg, serverHello *serverHelloMsg, cert *x509.Certificate, skx *serverKeyExchangeMsg) os.Error {
-       return os.ErrorString("unexpected ServerKeyExchange")
+       return os.NewError("unexpected ServerKeyExchange")
 }
 
 func (ka rsaKeyAgreement) generateClientKeyExchange(config *Config, clientHello *clientHelloMsg, cert *x509.Certificate) ([]byte, *clientKeyExchangeMsg, os.Error) {
@@ -146,7 +146,7 @@ Curve:
        md5sha1 := md5SHA1Hash(clientHello.random, hello.random, serverECDHParams)
        sig, err := rsa.SignPKCS1v15(config.rand(), config.Certificates[0].PrivateKey, crypto.MD5SHA1, md5sha1)
        if err != nil {
-               return nil, os.ErrorString("failed to sign ECDHE parameters: " + err.String())
+               return nil, os.NewError("failed to sign ECDHE parameters: " + err.String())
        }
 
        skx := new(serverKeyExchangeMsg)
@@ -162,11 +162,11 @@ Curve:
 
 func (ka *ecdheRSAKeyAgreement) processClientKeyExchange(config *Config, ckx *clientKeyExchangeMsg) ([]byte, os.Error) {
        if len(ckx.ciphertext) == 0 || int(ckx.ciphertext[0]) != len(ckx.ciphertext)-1 {
-               return nil, os.ErrorString("bad ClientKeyExchange")
+               return nil, os.NewError("bad ClientKeyExchange")
        }
        x, y := ka.curve.Unmarshal(ckx.ciphertext[1:])
        if x == nil {
-               return nil, os.ErrorString("bad ClientKeyExchange")
+               return nil, os.NewError("bad ClientKeyExchange")
        }
        x, _ = ka.curve.ScalarMult(x, y, ka.privateKey)
        preMasterSecret := make([]byte, (ka.curve.BitSize+7)>>3)
@@ -176,14 +176,14 @@ func (ka *ecdheRSAKeyAgreement) processClientKeyExchange(config *Config, ckx *cl
        return preMasterSecret, nil
 }
 
-var errServerKeyExchange = os.ErrorString("invalid ServerKeyExchange")
+var errServerKeyExchange = os.NewError("invalid ServerKeyExchange")
 
 func (ka *ecdheRSAKeyAgreement) processServerKeyExchange(config *Config, clientHello *clientHelloMsg, serverHello *serverHelloMsg, cert *x509.Certificate, skx *serverKeyExchangeMsg) os.Error {
        if len(skx.key) < 4 {
                return errServerKeyExchange
        }
        if skx.key[0] != 3 { // named curve
-               return os.ErrorString("server selected unsupported curve")
+               return os.NewError("server selected unsupported curve")
        }
        curveid := uint16(skx.key[1])<<8 | uint16(skx.key[2])
 
@@ -195,7 +195,7 @@ func (ka *ecdheRSAKeyAgreement) processServerKeyExchange(config *Config, clientH
        case curveP521:
                ka.curve = elliptic.P521()
        default:
-               return os.ErrorString("server selected unsupported curve")
+               return os.NewError("server selected unsupported curve")
        }
 
        publicLen := int(skx.key[3])
@@ -224,7 +224,7 @@ func (ka *ecdheRSAKeyAgreement) processServerKeyExchange(config *Config, clientH
 
 func (ka *ecdheRSAKeyAgreement) generateClientKeyExchange(config *Config, clientHello *clientHelloMsg, cert *x509.Certificate) ([]byte, *clientKeyExchangeMsg, os.Error) {
        if ka.curve == nil {
-               return nil, nil, os.ErrorString("missing ServerKeyExchange message")
+               return nil, nil, os.NewError("missing ServerKeyExchange message")
        }
        priv, mx, my, err := ka.curve.GenerateKey(config.rand())
        if err != nil {
index 9e5c9270a7f785a89956d627eb6c3af1ccfe1af7..4f0859fee64ab564240607a8d2f3cbc74f214692 100644 (file)
@@ -147,19 +147,19 @@ func X509KeyPair(certPEMBlock, keyPEMBlock []byte) (cert Certificate, err os.Err
        }
 
        if len(cert.Certificate) == 0 {
-               err = os.ErrorString("crypto/tls: failed to parse certificate PEM data")
+               err = os.NewError("crypto/tls: failed to parse certificate PEM data")
                return
        }
 
        keyDERBlock, _ := pem.Decode(keyPEMBlock)
        if keyDERBlock == nil {
-               err = os.ErrorString("crypto/tls: failed to parse key PEM data")
+               err = os.NewError("crypto/tls: failed to parse key PEM data")
                return
        }
 
        key, err := x509.ParsePKCS1PrivateKey(keyDERBlock.Bytes)
        if err != nil {
-               err = os.ErrorString("crypto/tls: failed to parse key: " + err.String())
+               err = os.NewError("crypto/tls: failed to parse key: " + err.String())
                return
        }
 
@@ -173,7 +173,7 @@ func X509KeyPair(certPEMBlock, keyPEMBlock []byte) (cert Certificate, err os.Err
        }
 
        if x509Cert.PublicKeyAlgorithm != x509.RSA || x509Cert.PublicKey.(*rsa.PublicKey).N.Cmp(key.PublicKey.N) != 0 {
-               err = os.ErrorString("crypto/tls: private key does not match public key")
+               err = os.NewError("crypto/tls: private key does not match public key")
                return
        }
 
index 6a103dcfba7da6d60bb47cb7230e0140b6add73e..7a631186a22cfb1609a769fd794f2e244ddced2d 100644 (file)
@@ -120,7 +120,7 @@ func expectAuthorityUnknown(t *testing.T, i int, err os.Error) (ok bool) {
 func certificateFromPEM(pemBytes string) (*Certificate, os.Error) {
        block, _ := pem.Decode([]byte(pemBytes))
        if block == nil {
-               return nil, os.ErrorString("failed to decode PEM")
+               return nil, os.NewError("failed to decode PEM")
        }
        return ParseCertificate(block.Bytes)
 }
index b10ffb0a2e466ee7201ede6bc633d7e8d4e4670e..8bafeda5c9c026ad11bef1ed7f46a44804549ff3 100644 (file)
@@ -58,11 +58,11 @@ func ParsePKCS1PrivateKey(der []byte) (key *rsa.PrivateKey, err os.Error) {
        }
 
        if priv.Version > 1 {
-               return nil, os.ErrorString("x509: unsupported private key version")
+               return nil, os.NewError("x509: unsupported private key version")
        }
 
        if priv.N.Sign() <= 0 || priv.D.Sign() <= 0 || priv.P.Sign() <= 0 || priv.Q.Sign() <= 0 {
-               return nil, os.ErrorString("private key contains zero or negative value")
+               return nil, os.NewError("private key contains zero or negative value")
        }
 
        key = new(rsa.PrivateKey)
@@ -77,7 +77,7 @@ func ParsePKCS1PrivateKey(der []byte) (key *rsa.PrivateKey, err os.Error) {
        key.Primes[1] = priv.Q
        for i, a := range priv.AdditionalPrimes {
                if a.Prime.Sign() <= 0 {
-                       return nil, os.ErrorString("private key contains zero or negative prime")
+                       return nil, os.NewError("private key contains zero or negative prime")
                }
                key.Primes[i+2] = a.Prime
                // We ignore the other two values because rsa will calculate
@@ -457,10 +457,10 @@ func (c *Certificate) CheckSignature(algo SignatureAlgorithm, signed, signature
                        return err
                }
                if dsaSig.R.Sign() <= 0 || dsaSig.S.Sign() <= 0 {
-                       return os.ErrorString("DSA signature contained zero or negative values")
+                       return os.NewError("DSA signature contained zero or negative values")
                }
                if !dsa.Verify(pub, digest, dsaSig.R, dsaSig.S) {
-                       return os.ErrorString("DSA verification failure")
+                       return os.NewError("DSA verification failure")
                }
                return
        }
@@ -535,7 +535,7 @@ func parsePublicKey(algo PublicKeyAlgorithm, keyData *publicKeyInfo) (interface{
                        return nil, err
                }
                if p.Sign() <= 0 || params.P.Sign() <= 0 || params.Q.Sign() <= 0 || params.G.Sign() <= 0 {
-                       return nil, os.ErrorString("zero or negative DSA parameter")
+                       return nil, os.NewError("zero or negative DSA parameter")
                }
                pub := &dsa.PublicKey{
                        Parameters: dsa.Parameters{
@@ -571,7 +571,7 @@ func parseCertificate(in *certificate) (*Certificate, os.Error) {
        }
 
        if in.TBSCertificate.SerialNumber.Sign() < 0 {
-               return nil, os.ErrorString("negative serial number")
+               return nil, os.NewError("negative serial number")
        }
 
        out.Version = in.TBSCertificate.Version + 1
index 220ab940834e6387a106e43ce6f5371909f6e8fd..346fe2a783d85a4fd83f483c969e98a7bca6781e 100644 (file)
@@ -81,7 +81,7 @@ func (s *Section) Data() ([]byte, os.Error) {
 // specified link value.
 func (f *File) stringTable(link uint32) ([]byte, os.Error) {
        if link <= 0 || link >= uint32(len(f.Sections)) {
-               return nil, os.ErrorString("section has invalid string table link")
+               return nil, os.NewError("section has invalid string table link")
        }
        return f.Sections[link].Data()
 }
@@ -341,27 +341,27 @@ func (f *File) getSymbols(typ SectionType) ([]Symbol, []byte, os.Error) {
                return f.getSymbols32(typ)
        }
 
-       return nil, nil, os.ErrorString("not implemented")
+       return nil, nil, os.NewError("not implemented")
 }
 
 func (f *File) getSymbols32(typ SectionType) ([]Symbol, []byte, os.Error) {
        symtabSection := f.SectionByType(typ)
        if symtabSection == nil {
-               return nil, nil, os.ErrorString("no symbol section")
+               return nil, nil, os.NewError("no symbol section")
        }
 
        data, err := symtabSection.Data()
        if err != nil {
-               return nil, nil, os.ErrorString("cannot load symbol section")
+               return nil, nil, os.NewError("cannot load symbol section")
        }
        symtab := bytes.NewBuffer(data)
        if symtab.Len()%Sym32Size != 0 {
-               return nil, nil, os.ErrorString("length of symbol section is not a multiple of SymSize")
+               return nil, nil, os.NewError("length of symbol section is not a multiple of SymSize")
        }
 
        strdata, err := f.stringTable(symtabSection.Link)
        if err != nil {
-               return nil, nil, os.ErrorString("cannot load string table section")
+               return nil, nil, os.NewError("cannot load string table section")
        }
 
        // The first entry is all zeros.
@@ -390,21 +390,21 @@ func (f *File) getSymbols32(typ SectionType) ([]Symbol, []byte, os.Error) {
 func (f *File) getSymbols64(typ SectionType) ([]Symbol, []byte, os.Error) {
        symtabSection := f.SectionByType(typ)
        if symtabSection == nil {
-               return nil, nil, os.ErrorString("no symbol section")
+               return nil, nil, os.NewError("no symbol section")
        }
 
        data, err := symtabSection.Data()
        if err != nil {
-               return nil, nil, os.ErrorString("cannot load symbol section")
+               return nil, nil, os.NewError("cannot load symbol section")
        }
        symtab := bytes.NewBuffer(data)
        if symtab.Len()%Sym64Size != 0 {
-               return nil, nil, os.ErrorString("length of symbol section is not a multiple of Sym64Size")
+               return nil, nil, os.NewError("length of symbol section is not a multiple of Sym64Size")
        }
 
        strdata, err := f.stringTable(symtabSection.Link)
        if err != nil {
-               return nil, nil, os.ErrorString("cannot load string table section")
+               return nil, nil, os.NewError("cannot load string table section")
        }
 
        // The first entry is all zeros.
@@ -462,12 +462,12 @@ func (f *File) applyRelocations(dst []byte, rels []byte) os.Error {
                return f.applyRelocationsAMD64(dst, rels)
        }
 
-       return os.ErrorString("not implemented")
+       return os.NewError("not implemented")
 }
 
 func (f *File) applyRelocationsAMD64(dst []byte, rels []byte) os.Error {
        if len(rels)%Sym64Size != 0 {
-               return os.ErrorString("length of relocation section is not a multiple of Sym64Size")
+               return os.NewError("length of relocation section is not a multiple of Sym64Size")
        }
 
        symbols, _, err := f.getSymbols(SHT_SYMTAB)
index d0912f9e9e69ae1f522539c08323b830e7c66a61..c4e2a7a0f93280aec2ad46ec2609a6201b385af9 100644 (file)
@@ -10,7 +10,7 @@ import (
 )
 
 // ErrNotFound is the error resulting if a path search failed to find an executable file.
-var ErrNotFound = os.ErrorString("executable file not found in $path")
+var ErrNotFound = os.NewError("executable file not found in $path")
 
 func findExecutable(file string) os.Error {
        d, err := os.Stat(file)
index 3fc3be8324fdbe20e232093cc43e0c323c755569..cdf7207688cb1059e6e726c6c896e6e1ad3442de 100644 (file)
@@ -10,7 +10,7 @@ import (
 )
 
 // ErrNotFound is the error resulting if a path search failed to find an executable file.
-var ErrNotFound = os.ErrorString("executable file not found in $PATH")
+var ErrNotFound = os.NewError("executable file not found in $PATH")
 
 func findExecutable(file string) os.Error {
        d, err := os.Stat(file)
index 1b3acc42bfa32b1e3b82e32b243d2a9ebb4d82af..401c693b418ea2c3dada37a520ae0c0fbc0e6b24 100644 (file)
@@ -10,7 +10,7 @@ import (
 )
 
 // ErrNotFound is the error resulting if a path search failed to find an executable file.
-var ErrNotFound = os.ErrorString("executable file not found in %PATH%")
+var ErrNotFound = os.NewError("executable file not found in %PATH%")
 
 func chkStat(file string) os.Error {
        d, err := os.Stat(file)
index 20a507a3a933a0fb3e5950d04ea38427912a38da..438e0ae265313192cd6dc5a10ed7f685996cdce3 100644 (file)
@@ -189,7 +189,7 @@ func Sprintf(format string, a ...interface{}) string {
 // Errorf formats according to a format specifier and returns the string 
 // converted to an os.ErrorString, which satisfies the os.Error interface.
 func Errorf(format string, a ...interface{}) os.Error {
-       return os.ErrorString(Sprintf(format, a...))
+       return os.NewError(Sprintf(format, a...))
 }
 
 // These routines do not take a format string
index b1112882351d5baaa8eb9436de8a159b9a3bae6c..f48fcbb4488b034d7d2edf2da4db27408496140a 100644 (file)
@@ -167,7 +167,7 @@ type ssave struct {
 // satisfies io.Reader. It will never be called when used as
 // intended, so there is no need to make it actually work.
 func (s *ss) Read(buf []byte) (n int, err os.Error) {
-       return 0, os.ErrorString("ScanState's Read should not be called. Use ReadRune")
+       return 0, os.NewError("ScanState's Read should not be called. Use ReadRune")
 }
 
 func (s *ss) ReadRune() (rune int, size int, err os.Error) {
@@ -241,7 +241,7 @@ func (s *ss) error(err os.Error) {
 }
 
 func (s *ss) errorString(err string) {
-       panic(scanError{os.ErrorString(err)})
+       panic(scanError{os.NewError(err)})
 }
 
 func (s *ss) Token(skipSpace bool, f func(int) bool) (tok []byte, err os.Error) {
@@ -427,8 +427,8 @@ func (s *ss) typeError(field interface{}, expected string) {
        s.errorString("expected field of type pointer to " + expected + "; found " + reflect.TypeOf(field).String())
 }
 
-var complexError = os.ErrorString("syntax error scanning complex number")
-var boolError = os.ErrorString("syntax error scanning boolean")
+var complexError = os.NewError("syntax error scanning complex number")
+var boolError = os.NewError("syntax error scanning boolean")
 
 // consume reads the next rune in the input and reports whether it is in the ok string.
 // If accept is true, it puts the character into the input token.
index a4de8adb15602a36e0fc9188ccfca22899fcc5f2..98b3b5493cc10cad3705fe55c3cf1c75040c5f8f 100644 (file)
@@ -94,7 +94,7 @@ func (x *Xs) Scan(state ScanState, verb int) os.Error {
        }
        s := string(tok)
        if !regexp.MustCompile("^" + string(verb) + "+$").MatchString(s) {
-               return os.ErrorString("syntax error for xs")
+               return os.NewError("syntax error for xs")
        }
        *x = Xs(s)
        return nil
@@ -818,7 +818,7 @@ func (r *RecursiveInt) Scan(state ScanState, verb int) (err os.Error) {
        next := new(RecursiveInt)
        _, err = Fscanf(state, ".%v", next)
        if err != nil {
-               if err == os.ErrorString("input does not match format") || err == io.ErrUnexpectedEOF {
+               if err == os.NewError("input does not match format") || err == io.ErrUnexpectedEOF {
                        err = nil
                }
                return
index dda33bb6b646f0000ecba1a0ad579bde5c45630f..20f8f2913f86ea5b07398c36f337f81569ffc5fd 100644 (file)
@@ -98,7 +98,7 @@ func ScanDir(dir string, allowMain bool) (info *DirInfo, err os.Error) {
                        if s == "main" || di.PkgName == "main" {
                                return ScanDir(dir, false)
                        }
-                       return nil, os.ErrorString("multiple package names in " + dir)
+                       return nil, os.NewError("multiple package names in " + dir)
                }
                isCgo := false
                for _, spec := range pf.Imports {
index b4780e05784f7cd992a2260e2f1152d2dd1e99ee..1764c38e4f4024a164697ca192f3fcfaf9a89de5 100644 (file)
@@ -42,7 +42,7 @@ func readSource(filename string, src interface{}) ([]byte, os.Error) {
                        }
                        return buf.Bytes(), nil
                default:
-                       return nil, os.ErrorString("invalid source")
+                       return nil, os.NewError("invalid source")
                }
        }
 
index cb08ffe18a2ffd269ef594728e78fe65c63438ef..f68133761a167570551375e7c1332ae775af4d9e 100644 (file)
@@ -29,7 +29,7 @@ func readGopackHeader(buf *bufio.Reader) (name string, size int, err os.Error) {
        s := strings.TrimSpace(string(hdr[64+12+6+6+8:][:10]))
        size, err = strconv.Atoi(s)
        if err != nil || hdr[len(hdr)-2] != '`' || hdr[len(hdr)-1] != '\n' {
-               err = os.ErrorString("invalid archive header")
+               err = os.NewError("invalid archive header")
                return
        }
        name = strings.TrimSpace(string(hdr[:64]))
@@ -80,7 +80,7 @@ func ExportData(filename string) (rc io.ReadCloser, err os.Error) {
                        return
                }
                if name != "__.SYMDEF" {
-                       err = os.ErrorString("go archive does not begin with __.SYMDEF")
+                       err = os.NewError("go archive does not begin with __.SYMDEF")
                        return
                }
                const block = 4096
@@ -102,7 +102,7 @@ func ExportData(filename string) (rc io.ReadCloser, err os.Error) {
                        return
                }
                if name != "__.PKGDEF" {
-                       err = os.ErrorString("go archive is missing __.PKGDEF")
+                       err = os.NewError("go archive is missing __.PKGDEF")
                        return
                }
 
@@ -117,7 +117,7 @@ func ExportData(filename string) (rc io.ReadCloser, err os.Error) {
        // Now at __.PKGDEF in archive or still at beginning of file.
        // Either way, line should begin with "go object ".
        if !strings.HasPrefix(string(line), "go object ") {
-               err = os.ErrorString("not a go object file")
+               err = os.NewError("not a go object file")
                return
        }
 
index 2cfed7726ae4cfb9ecd0495daa5a6387444950ea..aa0bb9160515c608201cdc09046d640e22a15eba 100644 (file)
@@ -124,7 +124,7 @@ func GcImporter(imports map[string]*ast.Object, path string) (pkg *ast.Object, e
 
        filename, id := findPkg(path)
        if filename == "" {
-               err = os.ErrorString("can't find import: " + id)
+               err = os.NewError("can't find import: " + id)
                return
        }
 
@@ -166,7 +166,7 @@ func (e importError) String() string {
 
 func (p *gcParser) error(err interface{}) {
        if s, ok := err.(string); ok {
-               err = os.ErrorString(s)
+               err = os.NewError(s)
        }
        // panic with a runtime.Error if err is not an os.Error
        panic(importError{p.scanner.Pos(), err.(os.Error)})
index 8961336cd342c7ae45dffccfd45dcbd8bdd4e0b2..da8e59c74274925661f676bfc45a9a732969f8ba 100644 (file)
@@ -330,7 +330,7 @@ func newDecodeStateFromData(data []byte) *decoderState {
 // Test instruction execution for decoding.
 // Do not run the machine yet; instead do individual instructions crafted by hand.
 func TestScalarDecInstructions(t *testing.T) {
-       ovfl := os.ErrorString("overflow")
+       ovfl := os.NewError("overflow")
 
        // bool
        {
index f56d72a6a6e302cd1e1b0c846e84ac94f48b20da..415b30825091e6fe298969faf8217c5b2b6a1afd 100644 (file)
@@ -17,9 +17,9 @@ import (
 )
 
 var (
-       errBadUint = os.ErrorString("gob: encoded unsigned integer out of range")
-       errBadType = os.ErrorString("gob: unknown type id or corrupted data")
-       errRange   = os.ErrorString("gob: bad data: field numbers out of bounds")
+       errBadUint = os.NewError("gob: encoded unsigned integer out of range")
+       errBadType = os.NewError("gob: unknown type id or corrupted data")
+       errRange   = os.NewError("gob: bad data: field numbers out of bounds")
 )
 
 // decoderState is the execution state of an instance of the decoder. A new state
@@ -54,8 +54,8 @@ func (dec *Decoder) freeDecoderState(d *decoderState) {
        dec.freeList = d
 }
 
-func overflow(name string) os.ErrorString {
-       return os.ErrorString(`value for "` + name + `" out of range`)
+func overflow(name string) os.Error {
+       return os.NewError(`value for "` + name + `" out of range`)
 }
 
 // decodeUintReader reads an encoded unsigned integer from an io.Reader.
@@ -135,10 +135,10 @@ type decOp func(i *decInstr, state *decoderState, p unsafe.Pointer)
 // The 'instructions' of the decoding machine
 type decInstr struct {
        op     decOp
-       field  int            // field number of the wire type
-       indir  int            // how many pointer indirections to reach the value in the struct
-       offset uintptr        // offset in the structure of the field to encode
-       ovfl   os.ErrorString // error message for overflow/underflow (for arrays, of the elements)
+       field  int      // field number of the wire type
+       indir  int      // how many pointer indirections to reach the value in the struct
+       offset uintptr  // offset in the structure of the field to encode
+       ovfl   os.Error // error message for overflow/underflow (for arrays, of the elements)
 }
 
 // Since the encoder writes no zeros, if we arrive at a decoder we have
@@ -552,7 +552,7 @@ func (dec *Decoder) ignoreSingle(engine *decEngine) {
 }
 
 // decodeArrayHelper does the work for decoding arrays and slices.
-func (dec *Decoder) decodeArrayHelper(state *decoderState, p uintptr, elemOp decOp, elemWid uintptr, length, elemIndir int, ovfl os.ErrorString) {
+func (dec *Decoder) decodeArrayHelper(state *decoderState, p uintptr, elemOp decOp, elemWid uintptr, length, elemIndir int, ovfl os.Error) {
        instr := &decInstr{elemOp, 0, elemIndir, 0, ovfl}
        for i := 0; i < length; i++ {
                up := unsafe.Pointer(p)
@@ -567,7 +567,7 @@ func (dec *Decoder) decodeArrayHelper(state *decoderState, p uintptr, elemOp dec
 // decodeArray decodes an array and stores it through p, that is, p points to the zeroth element.
 // The length is an unsigned integer preceding the elements.  Even though the length is redundant
 // (it's part of the type), it's a useful check and is included in the encoding.
-func (dec *Decoder) decodeArray(atyp reflect.Type, state *decoderState, p uintptr, elemOp decOp, elemWid uintptr, length, indir, elemIndir int, ovfl os.ErrorString) {
+func (dec *Decoder) decodeArray(atyp reflect.Type, state *decoderState, p uintptr, elemOp decOp, elemWid uintptr, length, indir, elemIndir int, ovfl os.Error) {
        if indir > 0 {
                p = allocate(atyp, p, 1) // All but the last level has been allocated by dec.Indirect
        }
@@ -579,7 +579,7 @@ func (dec *Decoder) decodeArray(atyp reflect.Type, state *decoderState, p uintpt
 
 // decodeIntoValue is a helper for map decoding.  Since maps are decoded using reflection,
 // unlike the other items we can't use a pointer directly.
-func decodeIntoValue(state *decoderState, op decOp, indir int, v reflect.Value, ovfl os.ErrorString) reflect.Value {
+func decodeIntoValue(state *decoderState, op decOp, indir int, v reflect.Value, ovfl os.Error) reflect.Value {
        instr := &decInstr{op, 0, indir, 0, ovfl}
        up := unsafe.Pointer(unsafeAddr(v))
        if indir > 1 {
@@ -593,7 +593,7 @@ func decodeIntoValue(state *decoderState, op decOp, indir int, v reflect.Value,
 // Maps are encoded as a length followed by key:value pairs.
 // Because the internals of maps are not visible to us, we must
 // use reflection rather than pointer magic.
-func (dec *Decoder) decodeMap(mtyp reflect.Type, state *decoderState, p uintptr, keyOp, elemOp decOp, indir, keyIndir, elemIndir int, ovfl os.ErrorString) {
+func (dec *Decoder) decodeMap(mtyp reflect.Type, state *decoderState, p uintptr, keyOp, elemOp decOp, indir, keyIndir, elemIndir int, ovfl os.Error) {
        if indir > 0 {
                p = allocate(mtyp, p, 1) // All but the last level has been allocated by dec.Indirect
        }
@@ -616,7 +616,7 @@ func (dec *Decoder) decodeMap(mtyp reflect.Type, state *decoderState, p uintptr,
 
 // ignoreArrayHelper does the work for discarding arrays and slices.
 func (dec *Decoder) ignoreArrayHelper(state *decoderState, elemOp decOp, length int) {
-       instr := &decInstr{elemOp, 0, 0, 0, os.ErrorString("no error")}
+       instr := &decInstr{elemOp, 0, 0, 0, os.NewError("no error")}
        for i := 0; i < length; i++ {
                elemOp(instr, state, nil)
        }
@@ -633,8 +633,8 @@ func (dec *Decoder) ignoreArray(state *decoderState, elemOp decOp, length int) {
 // ignoreMap discards the data for a map value with no destination.
 func (dec *Decoder) ignoreMap(state *decoderState, keyOp, elemOp decOp) {
        n := int(state.decodeUint())
-       keyInstr := &decInstr{keyOp, 0, 0, 0, os.ErrorString("no error")}
-       elemInstr := &decInstr{elemOp, 0, 0, 0, os.ErrorString("no error")}
+       keyInstr := &decInstr{keyOp, 0, 0, 0, os.NewError("no error")}
+       elemInstr := &decInstr{elemOp, 0, 0, 0, os.NewError("no error")}
        for i := 0; i < n; i++ {
                keyOp(keyInstr, state, nil)
                elemOp(elemInstr, state, nil)
@@ -643,7 +643,7 @@ func (dec *Decoder) ignoreMap(state *decoderState, keyOp, elemOp decOp) {
 
 // decodeSlice decodes a slice and stores the slice header through p.
 // Slices are encoded as an unsigned length followed by the elements.
-func (dec *Decoder) decodeSlice(atyp reflect.Type, state *decoderState, p uintptr, elemOp decOp, elemWid uintptr, indir, elemIndir int, ovfl os.ErrorString) {
+func (dec *Decoder) decodeSlice(atyp reflect.Type, state *decoderState, p uintptr, elemOp decOp, elemWid uintptr, indir, elemIndir int, ovfl os.Error) {
        n := int(uintptr(state.decodeUint()))
        if indir > 0 {
                up := unsafe.Pointer(p)
@@ -1064,10 +1064,10 @@ func (dec *Decoder) compileSingle(remoteId typeId, ut *userTypeInfo) (engine *de
        engine.instr = make([]decInstr, 1) // one item
        name := rt.String()                // best we can do
        if !dec.compatibleType(rt, remoteId, make(map[reflect.Type]typeId)) {
-               return nil, os.ErrorString("gob: wrong type received for local value " + name + ": " + dec.typeString(remoteId))
+               return nil, os.NewError("gob: wrong type received for local value " + name + ": " + dec.typeString(remoteId))
        }
        op, indir := dec.decOpFor(remoteId, rt, name, make(map[reflect.Type]*decOp))
-       ovfl := os.ErrorString(`value for "` + name + `" out of range`)
+       ovfl := os.NewError(`value for "` + name + `" out of range`)
        engine.instr[singletonField] = decInstr{*op, singletonField, indir, 0, ovfl}
        engine.numInstr = 1
        return
index b83904a710a06b1bd0a5e38129d6816342ca99c3..2819471322542f45bd3cc58c40403eaa4b41bfd5 100644 (file)
@@ -44,7 +44,7 @@ func NewDecoder(r io.Reader) *Decoder {
 func (dec *Decoder) recvType(id typeId) {
        // Have we already seen this type?  That's an error
        if id < firstUserId || dec.wireType[id] != nil {
-               dec.err = os.ErrorString("gob: duplicate type received")
+               dec.err = os.NewError("gob: duplicate type received")
                return
        }
 
@@ -143,7 +143,7 @@ func (dec *Decoder) decodeTypeSequence(isInterface bool) typeId {
                // will be absorbed by recvMessage.)
                if dec.buf.Len() > 0 {
                        if !isInterface {
-                               dec.err = os.ErrorString("extra data in buffer")
+                               dec.err = os.NewError("extra data in buffer")
                                break
                        }
                        dec.nextUint()
@@ -165,7 +165,7 @@ func (dec *Decoder) Decode(e interface{}) os.Error {
        // If e represents a value as opposed to a pointer, the answer won't
        // get back to the caller.  Make sure it's a pointer.
        if value.Type().Kind() != reflect.Ptr {
-               dec.err = os.ErrorString("gob: attempt to decode into a non-pointer")
+               dec.err = os.NewError("gob: attempt to decode into a non-pointer")
                return dec.err
        }
        return dec.DecodeValue(value)
@@ -180,7 +180,7 @@ func (dec *Decoder) DecodeValue(v reflect.Value) os.Error {
                if v.Kind() == reflect.Ptr && !v.IsNil() {
                        // That's okay, we'll store through the pointer.
                } else if !v.CanSet() {
-                       return os.ErrorString("gob: DecodeValue of unassignable value")
+                       return os.NewError("gob: DecodeValue of unassignable value")
                }
        }
        // Make sure we're single-threaded through here.
index 65ee5bf67c8a05b05ebf2d799dc1dfd607f40645..96101d92babee84c1f372d0339ca72265b3a273c 100644 (file)
@@ -50,7 +50,7 @@ func (enc *Encoder) popWriter() {
 }
 
 func (enc *Encoder) badType(rt reflect.Type) {
-       enc.setError(os.ErrorString("gob: can't encode type " + rt.String()))
+       enc.setError(os.NewError("gob: can't encode type " + rt.String()))
 }
 
 func (enc *Encoder) setError(err os.Error) {
index 3e1906020f00148362c82a860af470bdc54b2fa2..25cb5d11b8e48b52e53b95fa8360043e18f7aea4 100644 (file)
@@ -44,7 +44,7 @@ func (g *ByteStruct) GobEncode() ([]byte, os.Error) {
 
 func (g *ByteStruct) GobDecode(data []byte) os.Error {
        if g == nil {
-               return os.ErrorString("NIL RECEIVER")
+               return os.NewError("NIL RECEIVER")
        }
        // Expect N sequential-valued bytes.
        if len(data) == 0 {
@@ -53,7 +53,7 @@ func (g *ByteStruct) GobDecode(data []byte) os.Error {
        g.a = data[0]
        for i, c := range data {
                if c != g.a+byte(i) {
-                       return os.ErrorString("invalid data sequence")
+                       return os.NewError("invalid data sequence")
                }
        }
        return nil
@@ -71,7 +71,7 @@ func (g *StringStruct) GobDecode(data []byte) os.Error {
        a := data[0]
        for i, c := range data {
                if c != a+byte(i) {
-                       return os.ErrorString("invalid data sequence")
+                       return os.NewError("invalid data sequence")
                }
        }
        g.s = string(data)
@@ -84,7 +84,7 @@ func (a *ArrayStruct) GobEncode() ([]byte, os.Error) {
 
 func (a *ArrayStruct) GobDecode(data []byte) os.Error {
        if len(data) != len(a.a) {
-               return os.ErrorString("wrong length in array decode")
+               return os.NewError("wrong length in array decode")
        }
        copy(a.a[:], data)
        return nil
index c6542633a6cc94c0075513bf20319476e975956c..f8e3843a776c1a0a93ebccd9cf40e633c09142bd 100644 (file)
@@ -67,7 +67,7 @@ func validUserType(rt reflect.Type) (ut *userTypeInfo, err os.Error) {
                ut.base = pt.Elem()
                if ut.base == slowpoke { // ut.base lapped slowpoke
                        // recursive pointer type.
-                       return nil, os.ErrorString("can't represent recursive pointer type " + ut.base.String())
+                       return nil, os.NewError("can't represent recursive pointer type " + ut.base.String())
                }
                if ut.indir%2 == 0 {
                        slowpoke = slowpoke.Elem()
@@ -508,7 +508,7 @@ func newTypeObject(name string, ut *userTypeInfo, rt reflect.Type) (gobType, os.
                return st, nil
 
        default:
-               return nil, os.ErrorString("gob NewTypeObject can't handle type: " + rt.String())
+               return nil, os.NewError("gob NewTypeObject can't handle type: " + rt.String())
        }
        return nil, nil
 }
index 2883b0493d7700998427eb5416857c6e9b4dba2d..4f63b44f26173803b5a6b5d55621a4acccdd42c4 100644 (file)
@@ -198,7 +198,7 @@ func (c *Client) doFollowingRedirects(ireq *Request) (r *Response, err os.Error)
                if shouldRedirect(r.StatusCode) {
                        r.Body.Close()
                        if url = r.Header.Get("Location"); url == "" {
-                               err = os.ErrorString(fmt.Sprintf("%d response missing Location header", r.StatusCode))
+                               err = os.NewError(fmt.Sprintf("%d response missing Location header", r.StatusCode))
                                break
                        }
                        base = req.URL
@@ -215,7 +215,7 @@ func (c *Client) doFollowingRedirects(ireq *Request) (r *Response, err os.Error)
 
 func defaultCheckRedirect(req *Request, via []*Request) os.Error {
        if len(via) >= 10 {
-               return os.ErrorString("stopped after 10 redirects")
+               return os.NewError("stopped after 10 redirects")
        }
        return nil
 }
index 28a0c51ef5b9c6d1fcd6bda042c7188df9e7d557..56512980c8d114bec861a42654d39dec357d428b 100644 (file)
@@ -157,7 +157,7 @@ func serveFile(w ResponseWriter, r *Request, name string, redirect bool) {
        // TODO(adg): handle multiple ranges
        ranges, err := parseRange(r.Header.Get("Range"), size)
        if err == nil && len(ranges) > 1 {
-               err = os.ErrorString("multiple ranges not supported")
+               err = os.NewError("multiple ranges not supported")
        }
        if err != nil {
                Error(w, err.String(), StatusRequestedRangeNotSatisfiable)
index 2845f17799e716e99da22ab673df9a724af25806..40ed5b2b6025e3b291a808ef3e8bc95c7ce91f90 100644 (file)
@@ -35,13 +35,15 @@ const (
 
 // ErrMissingFile is returned by FormFile when the provided file field name
 // is either not present in the request or not a file field.
-var ErrMissingFile = os.ErrorString("http: no such file")
+var ErrMissingFile = os.NewError("http: no such file")
 
 // HTTP request parsing errors.
 type ProtocolError struct {
-       os.ErrorString
+       ErrorString string
 }
 
+func (err *ProtocolError) String() string { return err.ErrorString }
+
 var (
        ErrLineTooLong          = &ProtocolError{"header line too long"}
        ErrHeaderTooLong        = &ProtocolError{"header too long"}
@@ -704,7 +706,7 @@ func (r *Request) ParseForm() (err os.Error) {
        }
        if r.Method == "POST" {
                if r.Body == nil {
-                       return os.ErrorString("missing form body")
+                       return os.NewError("missing form body")
                }
                ct := r.Header.Get("Content-Type")
                switch strings.Split(ct, ";", 2)[0] {
index c907d85fd2a5f9dbc490d17fe79d1ef72bd56a47..9ad159010be43355bd7857f06f4dc3dfee59f3ba 100644 (file)
@@ -76,12 +76,12 @@ func ProxyFromEnvironment(req *Request) (*URL, os.Error) {
        }
        proxyURL, err := ParseRequestURL(proxy)
        if err != nil {
-               return nil, os.ErrorString("invalid proxy address")
+               return nil, os.NewError("invalid proxy address")
        }
        if proxyURL.Host == "" {
                proxyURL, err = ParseRequestURL("http://" + proxy)
                if err != nil {
-                       return nil, os.ErrorString("invalid proxy address")
+                       return nil, os.NewError("invalid proxy address")
                }
        }
        return proxyURL, nil
@@ -331,7 +331,7 @@ func (t *Transport) getConn(cm *connectMethod) (*persistConn, os.Error) {
                if resp.StatusCode != 200 {
                        f := strings.Split(resp.Status, " ", 2)
                        conn.Close()
-                       return nil, os.ErrorString(f[1])
+                       return nil, os.NewError(f[1])
                }
        }
 
index 394c87d0835bee6200920e26d55cd8a7bb79349e..beb0b8200d022a8e1d95685b58ee6a46aa21c70a 100644 (file)
@@ -299,7 +299,7 @@ func getscheme(rawurl string) (scheme, path string, err os.Error) {
                        }
                case c == ':':
                        if i == 0 {
-                               return "", "", os.ErrorString("missing protocol scheme")
+                               return "", "", os.NewError("missing protocol scheme")
                        }
                        return rawurl[0:i], rawurl[i+1:], nil
                default:
@@ -354,7 +354,7 @@ func parseURL(rawurl string, viaRequest bool) (url *URL, err os.Error) {
        )
 
        if rawurl == "" {
-               err = os.ErrorString("empty url")
+               err = os.NewError("empty url")
                goto Error
        }
        url = new(URL)
@@ -380,7 +380,7 @@ func parseURL(rawurl string, viaRequest bool) (url *URL, err os.Error) {
                url.OpaquePath = true
        } else {
                if viaRequest && !leadingSlash {
-                       err = os.ErrorString("invalid URI for request")
+                       err = os.NewError("invalid URI for request")
                        goto Error
                }
 
@@ -414,7 +414,7 @@ func parseURL(rawurl string, viaRequest bool) (url *URL, err os.Error) {
 
                if strings.Contains(rawHost, "%") {
                        // Host cannot contain escaped characters.
-                       err = os.ErrorString("hexadecimal escape in host")
+                       err = os.NewError("hexadecimal escape in host")
                        goto Error
                }
                url.Host = rawHost
index 26c013b9abde25b6a937bf9cd244fe53666affc9..98ac01cca2c2cf125195ea55c268577ea7b5243b 100644 (file)
@@ -186,7 +186,7 @@ Loop:
                                return err
                        }
                        if c != 0 {
-                               return os.ErrorString("gif: extra data after image")
+                               return os.NewError("gif: extra data after image")
                        }
 
                        // Undo the interlacing if necessary.
index 846dcacb5aa439522eebad8db6210a193bcfa565..5080da2ea01ed19e38ab711a69730b6620e9ad6c 100644 (file)
@@ -12,9 +12,11 @@ import "os"
 
 // Error represents an unexpected I/O behavior.
 type Error struct {
-       os.ErrorString
+       ErrorString string
 }
 
+func (err *Error) String() string { return err.ErrorString }
+
 // ErrShortWrite means that a write accepted fewer bytes than requested
 // but failed to return an explicit error.
 var ErrShortWrite os.Error = &Error{"short write"}
index 342e35f18c521505609814836522171bac17f935..fce287bd8e6815db4bda635923ee6ca246551f9b 100644 (file)
@@ -96,7 +96,7 @@ func parseDate(date string) (*time.Time, os.Error) {
                        return t, nil
                }
        }
-       return nil, os.ErrorString("mail: header could not be parsed")
+       return nil, os.NewError("mail: header could not be parsed")
 }
 
 // A Header represents the key-value pairs in a mail message header.
@@ -108,7 +108,7 @@ func (h Header) Get(key string) string {
        return textproto.MIMEHeader(h).Get(key)
 }
 
-var ErrHeaderNotPresent = os.ErrorString("mail: header not in message")
+var ErrHeaderNotPresent = os.NewError("mail: header not in message")
 
 // Date parses the Date header field.
 func (h Header) Date() (*time.Time, os.Error) {
@@ -204,7 +204,7 @@ func (p *addrParser) parseAddressList() ([]*Address, os.Error) {
                        break
                }
                if !p.consume(',') {
-                       return nil, os.ErrorString("mail: expected comma")
+                       return nil, os.NewError("mail: expected comma")
                }
        }
        return list, nil
@@ -215,7 +215,7 @@ func (p *addrParser) parseAddress() (addr *Address, err os.Error) {
        debug.Printf("parseAddress: %q", *p)
        p.skipSpace()
        if p.empty() {
-               return nil, os.ErrorString("mail: no address")
+               return nil, os.NewError("mail: no address")
        }
 
        // address = name-addr / addr-spec
@@ -246,14 +246,14 @@ func (p *addrParser) parseAddress() (addr *Address, err os.Error) {
        // angle-addr = "<" addr-spec ">"
        p.skipSpace()
        if !p.consume('<') {
-               return nil, os.ErrorString("mail: no angle-addr")
+               return nil, os.NewError("mail: no angle-addr")
        }
        spec, err = p.consumeAddrSpec()
        if err != nil {
                return nil, err
        }
        if !p.consume('>') {
-               return nil, os.ErrorString("mail: unclosed angle-addr")
+               return nil, os.NewError("mail: unclosed angle-addr")
        }
        debug.Printf("parseAddress: spec=%q", spec)
 
@@ -278,7 +278,7 @@ func (p *addrParser) consumeAddrSpec() (spec string, err os.Error) {
        var localPart string
        p.skipSpace()
        if p.empty() {
-               return "", os.ErrorString("mail: no addr-spec")
+               return "", os.NewError("mail: no addr-spec")
        }
        if p.peek() == '"' {
                // quoted-string
@@ -295,14 +295,14 @@ func (p *addrParser) consumeAddrSpec() (spec string, err os.Error) {
        }
 
        if !p.consume('@') {
-               return "", os.ErrorString("mail: missing @ in addr-spec")
+               return "", os.NewError("mail: missing @ in addr-spec")
        }
 
        // domain = dot-atom / domain-literal
        var domain string
        p.skipSpace()
        if p.empty() {
-               return "", os.ErrorString("mail: no domain in addr-spec")
+               return "", os.NewError("mail: no domain in addr-spec")
        }
        // TODO(dsymonds): Handle domain-literal
        domain, err = p.consumeAtom(true)
@@ -323,7 +323,7 @@ func (p *addrParser) consumePhrase() (phrase string, err os.Error) {
                var word string
                p.skipSpace()
                if p.empty() {
-                       return "", os.ErrorString("mail: missing phrase")
+                       return "", os.NewError("mail: missing phrase")
                }
                if p.peek() == '"' {
                        // quoted-string
@@ -347,7 +347,7 @@ func (p *addrParser) consumePhrase() (phrase string, err os.Error) {
        // Ignore any error if we got at least one word.
        if err != nil && len(words) == 0 {
                debug.Printf("consumePhrase: hit err: %v", err)
-               return "", os.ErrorString("mail: missing word in phrase")
+               return "", os.NewError("mail: missing word in phrase")
        }
        phrase = strings.Join(words, " ")
        return phrase, nil
@@ -361,14 +361,14 @@ func (p *addrParser) consumeQuotedString() (qs string, err os.Error) {
 Loop:
        for {
                if i >= p.len() {
-                       return "", os.ErrorString("mail: unclosed quoted-string")
+                       return "", os.NewError("mail: unclosed quoted-string")
                }
                switch c := (*p)[i]; {
                case c == '"':
                        break Loop
                case c == '\\':
                        if i+1 == p.len() {
-                               return "", os.ErrorString("mail: unclosed quoted-string")
+                               return "", os.NewError("mail: unclosed quoted-string")
                        }
                        qsb = append(qsb, (*p)[i+1])
                        i += 2
@@ -389,7 +389,7 @@ Loop:
 // If dot is true, consumeAtom parses an RFC 5322 dot-atom instead.
 func (p *addrParser) consumeAtom(dot bool) (atom string, err os.Error) {
        if !isAtext(p.peek(), false) {
-               return "", os.ErrorString("mail: invalid string")
+               return "", os.NewError("mail: invalid string")
        }
        i := 1
        for ; i < p.len() && isAtext((*p)[i], dot); i++ {
@@ -427,7 +427,7 @@ func (p *addrParser) len() int {
 func decodeRFC2047Word(s string) (string, os.Error) {
        fields := strings.Split(s, "?", -1)
        if len(fields) != 5 || fields[0] != "=" || fields[4] != "=" {
-               return "", os.ErrorString("mail: address not RFC 2047 encoded")
+               return "", os.NewError("mail: address not RFC 2047 encoded")
        }
        charset, enc := strings.ToLower(fields[1]), strings.ToLower(fields[2])
        if charset != "iso-8859-1" && charset != "utf-8" {
index 00a049bfd18daa24a18ecd48d631bf9dbea0d36c..7e3d549ebc71fbac6da7b2cb1c9fe8120a253f40 100644 (file)
@@ -56,7 +56,7 @@ func (p *pollster) AddFD(fd int, mode int, repeat bool) (bool, os.Error) {
                return false, os.NewSyscallError("kevent", e)
        }
        if n != 1 || (ev.Flags&syscall.EV_ERROR) == 0 || int(ev.Ident) != fd || int(ev.Filter) != kmode {
-               return false, os.ErrorString("kqueue phase error")
+               return false, os.NewError("kqueue phase error")
        }
        if ev.Data != 0 {
                return false, os.Errno(int(ev.Data))
index a811027b1c72263a3210459f90a225ccf4fa89f3..43047a78e64ef879d2da44061fb5817ab56437b3 100644 (file)
@@ -294,7 +294,7 @@ func splitNetProto(netProto string) (net string, proto int, err os.Error) {
        onceReadProtocols.Do(readProtocols)
        i := last(netProto, ':')
        if i < 0 { // no colon
-               return "", 0, os.ErrorString("no IP protocol specified")
+               return "", 0, os.NewError("no IP protocol specified")
        }
        net = netProto[0:i]
        protostr := netProto[i+1:]
index 51db107395401b9a77bfb7aaad9e4bff33a03661..5c84d34348aac95c9987339fb16add78ad5b0d0d 100644 (file)
@@ -115,7 +115,7 @@ type Listener interface {
        Addr() Addr
 }
 
-var errMissingAddress = os.ErrorString("missing address")
+var errMissingAddress = os.NewError("missing address")
 
 type OpError struct {
        Op    string
index 5469acffad8ce3c8d1a78daebdc3f8908349baa7..94e249d62f6e27f363a345dae3c3a24f768b3ce0 100644 (file)
@@ -281,7 +281,7 @@ func (c *UDPConn) BindToDevice(device string) os.Error {
 // Closing c does not affect f, and closing f does not affect c.
 func (c *UDPConn) File() (f *os.File, err os.Error) { return c.fd.dup() }
 
-var errInvalidMulticast = os.ErrorString("invalid IPv4 multicast address")
+var errInvalidMulticast = os.NewError("invalid IPv4 multicast address")
 
 // JoinGroup joins the IPv4 multicast group named by addr.
 // The UDPConn must use the "udp4" network.
index a319391bf168b41416fd7a92bf8615f8273c3d92..ac1ca12f5ff59eba8343683809e6782a4c478248 100644 (file)
@@ -153,7 +153,7 @@ func (cs *clientSet) drain(timeout int64) os.Error {
                        break
                }
                if timeout > 0 && time.Nanoseconds()-startTime >= timeout {
-                       return os.ErrorString("timeout")
+                       return os.NewError("timeout")
                }
                time.Sleep(100 * 1e6) // 100 milliseconds
        }
@@ -186,7 +186,7 @@ func (cs *clientSet) sync(timeout int64) os.Error {
                        break
                }
                if timeout > 0 && time.Nanoseconds()-startTime >= timeout {
-                       return os.ErrorString("timeout")
+                       return os.NewError("timeout")
                }
                time.Sleep(100 * 1e6) // 100 milliseconds
        }
index 1e5ccdb5cba8d529e1e9eabaa4d11a179f022508..7df736515360be7fadf4b55b9e287bd8074a08a9 100644 (file)
@@ -343,20 +343,20 @@ func (exp *Exporter) Sync(timeout int64) os.Error {
 func checkChan(chT interface{}, dir Dir) (reflect.Value, os.Error) {
        chanType := reflect.TypeOf(chT)
        if chanType.Kind() != reflect.Chan {
-               return reflect.Value{}, os.ErrorString("not a channel")
+               return reflect.Value{}, os.NewError("not a channel")
        }
        if dir != Send && dir != Recv {
-               return reflect.Value{}, os.ErrorString("unknown channel direction")
+               return reflect.Value{}, os.NewError("unknown channel direction")
        }
        switch chanType.ChanDir() {
        case reflect.BothDir:
        case reflect.SendDir:
                if dir != Recv {
-                       return reflect.Value{}, os.ErrorString("to import/export with Send, must provide <-chan")
+                       return reflect.Value{}, os.NewError("to import/export with Send, must provide <-chan")
                }
        case reflect.RecvDir:
                if dir != Send {
-                       return reflect.Value{}, os.ErrorString("to import/export with Recv, must provide chan<-")
+                       return reflect.Value{}, os.NewError("to import/export with Recv, must provide chan<-")
                }
        }
        return reflect.ValueOf(chT), nil
@@ -376,7 +376,7 @@ func (exp *Exporter) Export(name string, chT interface{}, dir Dir) os.Error {
        defer exp.mu.Unlock()
        _, present := exp.names[name]
        if present {
-               return os.ErrorString("channel name already being exported:" + name)
+               return os.NewError("channel name already being exported:" + name)
        }
        exp.names[name] = &chanDir{ch, dir}
        return nil
@@ -393,7 +393,7 @@ func (exp *Exporter) Hangup(name string) os.Error {
        // TODO drop all instances of channel from client sets
        exp.mu.Unlock()
        if !ok {
-               return os.ErrorString("netchan export: hangup: no such channel: " + name)
+               return os.NewError("netchan export: hangup: no such channel: " + name)
        }
        chDir.ch.Close()
        return nil
index 7d96228c407d2358981aa298cd4c4e104c806660..ec17d97774ba37201e7d6587fc14d87ed85aa2fb 100644 (file)
@@ -102,7 +102,7 @@ func (imp *Importer) run() {
                        if err.Error != "" {
                                impLog("response error:", err.Error)
                                select {
-                               case imp.errors <- os.ErrorString(err.Error):
+                               case imp.errors <- os.NewError(err.Error):
                                        continue // errors are not acknowledged
                                default:
                                        imp.shutdown()
@@ -203,7 +203,7 @@ func (imp *Importer) ImportNValues(name string, chT interface{}, dir Dir, size,
        defer imp.chanLock.Unlock()
        _, present := imp.names[name]
        if present {
-               return os.ErrorString("channel name already being imported:" + name)
+               return os.NewError("channel name already being imported:" + name)
        }
        if size < 1 {
                size = 1
@@ -254,7 +254,7 @@ func (imp *Importer) Hangup(name string) os.Error {
        defer imp.chanLock.Unlock()
        nc := imp.names[name]
        if nc == nil {
-               return os.ErrorString("netchan import: hangup: no such channel: " + name)
+               return os.NewError("netchan import: hangup: no such channel: " + name)
        }
        imp.names[name] = nil, false
        imp.chans[nc.id] = nil, false
@@ -279,7 +279,7 @@ func (imp *Importer) Drain(timeout int64) os.Error {
        startTime := time.Nanoseconds()
        for imp.unackedCount() > 0 {
                if timeout > 0 && time.Nanoseconds()-startTime >= timeout {
-                       return os.ErrorString("timeout")
+                       return os.NewError("timeout")
                }
                time.Sleep(100 * 1e6)
        }
index 2c4516ca7dae79c5743820918e5b369b6b4d1ca8..b4511dd2f4d7e859b76cc95bea6190859a145a66 100644 (file)
@@ -9,20 +9,17 @@ type Error interface {
        String() string
 }
 
-// A helper type that can be embedded or wrapped to simplify satisfying
-// Error.
-type ErrorString string
+// // errorString is a helper type used by NewError.
+type errorString string
 
-func (e ErrorString) String() string  { return string(e) }
-func (e ErrorString) Temporary() bool { return false }
-func (e ErrorString) Timeout() bool   { return false }
+func (e errorString) String() string { return string(e) }
 
 // Note: If the name of the function NewError changes,
 // pkg/go/doc/doc.go should be adjusted since it hardwires
 // this name in a heuristic.
 
-// NewError converts s to an ErrorString, which satisfies the Error interface.
-func NewError(s string) Error { return ErrorString(s) }
+// // NewError returns a new error with error.String() == s.
+func NewError(s string) Error { return errorString(s) }
 
 // PathError records an error and the operation and file path that caused it.
 type PathError struct {
index a689da8487513f8331babcd88ecfe6fb2cc5a884..3ebc1141d1a74038c7c15ef650bbe913805c6652 100644 (file)
@@ -45,12 +45,12 @@ func (this *statsResults) checkSimilarDistribution(expected *statsResults) os.Er
        if !nearEqual(this.mean, expected.mean, expected.closeEnough, expected.maxError) {
                s := fmt.Sprintf("mean %v != %v (allowed error %v, %v)", this.mean, expected.mean, expected.closeEnough, expected.maxError)
                fmt.Println(s)
-               return os.ErrorString(s)
+               return os.NewError(s)
        }
        if !nearEqual(this.stddev, expected.stddev, 0, expected.maxError) {
                s := fmt.Sprintf("stddev %v != %v (allowed error %v, %v)", this.stddev, expected.stddev, expected.closeEnough, expected.maxError)
                fmt.Println(s)
-               return os.ErrorString(s)
+               return os.NewError(s)
        }
        return nil
 }
index a8e560cbe5cfe0dadbf41e4e606689c8ec8b520e..b1828614fc48e4e3e58cf0644a2c78989948e00e 100644 (file)
@@ -23,7 +23,7 @@ func (e ServerError) String() string {
        return string(e)
 }
 
-const ErrShutdown = os.ErrorString("connection is shut down")
+var ErrShutdown = os.NewError("connection is shut down")
 
 // Call represents an active RPC.
 type Call struct {
@@ -110,7 +110,7 @@ func (client *Client) input() {
                if response.Error == "" {
                        err = client.codec.ReadResponseBody(c.Reply)
                        if err != nil {
-                               c.Error = os.ErrorString("reading body " + err.String())
+                               c.Error = os.NewError("reading body " + err.String())
                        }
                } else {
                        // We've got an error response. Give this to the request;
@@ -119,7 +119,7 @@ func (client *Client) input() {
                        c.Error = ServerError(response.Error)
                        err = client.codec.ReadResponseBody(nil)
                        if err != nil {
-                               err = os.ErrorString("reading error body: " + err.String())
+                               err = os.NewError("reading error body: " + err.String())
                        }
                }
                c.done()
@@ -221,7 +221,7 @@ func DialHTTPPath(network, address, path string) (*Client, os.Error) {
                return NewClient(conn), nil
        }
        if err == nil {
-               err = os.ErrorString("unexpected HTTP response: " + resp.Status)
+               err = os.NewError("unexpected HTTP response: " + resp.Status)
        }
        conn.Close()
        return nil, &net.OpError{"dial-http", network + " " + address, nil, err}
index 764ee7ff36183857fa7596ef519608917c3feb3c..02b9735eb1000ae396a8349234dee423a89d3044 100644 (file)
@@ -35,7 +35,7 @@ func (t *Arith) Mul(args *Args, reply *Reply) os.Error {
 
 func (t *Arith) Div(args *Args, reply *Reply) os.Error {
        if args.B == 0 {
-               return os.ErrorString("divide by zero")
+               return os.NewError("divide by zero")
        }
        reply.C = args.A / args.B
        return nil
index acadeec37f0a7b95f0974bdfe07f794531f35fae..17ba6a453aa17126531010801b30a730ab9258a9 100644 (file)
@@ -242,10 +242,10 @@ func (server *Server) register(rcvr interface{}, name string, useName bool) os.E
        if s.typ.PkgPath() != "" && !isExported(sname) && !useName {
                s := "rpc Register: type " + sname + " is not exported"
                log.Print(s)
-               return os.ErrorString(s)
+               return os.NewError(s)
        }
        if _, present := server.serviceMap[sname]; present {
-               return os.ErrorString("rpc: service already defined: " + sname)
+               return os.NewError("rpc: service already defined: " + sname)
        }
        s.name = sname
        s.method = make(map[string]*methodType)
@@ -294,7 +294,7 @@ func (server *Server) register(rcvr interface{}, name string, useName bool) os.E
        if len(s.method) == 0 {
                s := "rpc Register: type " + sname + " has no exported methods of suitable type"
                log.Print(s)
-               return os.ErrorString(s)
+               return os.NewError(s)
        }
        server.serviceMap[s.name] = s
        return nil
@@ -491,13 +491,13 @@ func (server *Server) readRequest(codec ServerCodec) (req *Request, service *ser
                if err == os.EOF || err == io.ErrUnexpectedEOF {
                        return
                }
-               err = os.ErrorString("rpc: server cannot decode request: " + err.String())
+               err = os.NewError("rpc: server cannot decode request: " + err.String())
                return
        }
 
        serviceMethod := strings.Split(req.ServiceMethod, ".", -1)
        if len(serviceMethod) != 2 {
-               err = os.ErrorString("rpc: service/method request ill-formed: " + req.ServiceMethod)
+               err = os.NewError("rpc: service/method request ill-formed: " + req.ServiceMethod)
                return
        }
        // Look up the request.
@@ -505,12 +505,12 @@ func (server *Server) readRequest(codec ServerCodec) (req *Request, service *ser
        service = server.serviceMap[serviceMethod[0]]
        server.Unlock()
        if service == nil {
-               err = os.ErrorString("rpc: can't find service " + req.ServiceMethod)
+               err = os.NewError("rpc: can't find service " + req.ServiceMethod)
                return
        }
        mtype = service.method[serviceMethod[1]]
        if mtype == nil {
-               err = os.ErrorString("rpc: can't find method " + req.ServiceMethod)
+               err = os.NewError("rpc: can't find method " + req.ServiceMethod)
        }
        return
 }
index cfff0c9ad50cc96af2664e149666b3d88458e3fe..1692168a8c073bedc7d2910a158d5d40ed1476f1 100644 (file)
@@ -52,7 +52,7 @@ func (t *Arith) Mul(args *Args, reply *Reply) os.Error {
 
 func (t *Arith) Div(args Args, reply *Reply) os.Error {
        if args.B == 0 {
-               return os.ErrorString("divide by zero")
+               return os.NewError("divide by zero")
        }
        reply.C = args.A / args.B
        return nil
index 1dfaaa6b51f9ce57ea8c55067035393c45d1a48e..e1154782b55c18c2cd23573fa425ccfe908b9029 100644 (file)
@@ -70,7 +70,7 @@ func Btoui64(s string, b int) (n uint64, err os.Error) {
                }
 
        default:
-               err = os.ErrorString("invalid base " + Itoa(b))
+               err = os.NewError("invalid base " + Itoa(b))
                goto Error
        }
 
index 10b0278e1c4413a11217244449c1ad641179054f..8423f7e452d028eb26dc3e15d73f5941aaee874f 100644 (file)
@@ -49,7 +49,7 @@ func (r *Reader) ReadByte() (b byte, err os.Error) {
 // read yet.
 func (r *Reader) UnreadByte() os.Error {
        if r.i <= 0 {
-               return os.ErrorString("strings.Reader: at beginning of string")
+               return os.NewError("strings.Reader: at beginning of string")
        }
        r.i--
        r.prevRune = -1
@@ -80,7 +80,7 @@ func (r *Reader) ReadRune() (rune int, size int, err os.Error) {
 // The last method called on r must have been ReadRune.
 func (r *Reader) UnreadRune() os.Error {
        if r.prevRune < 0 {
-               return os.ErrorString("strings.Reader: previous operation was not ReadRune")
+               return os.NewError("strings.Reader: previous operation was not ReadRune")
        }
        r.i = r.prevRune
        r.prevRune = -1
index fa15e882d079772701bb6d5d0492420913615a17..b1516715bca6a72d69c45dab521ddaf9f85b6c25 100644 (file)
@@ -27,5 +27,5 @@ func unixSyslog() (conn serverConn, err os.Error) {
                        }
                }
        }
-       return nil, os.ErrorString("Unix syslog delivery error")
+       return nil, os.NewError("Unix syslog delivery error")
 }
index 47d73634258dd6328befc49c6462921d756075c6..e0f56129e44699db4839b99fd7e96689ddc48af0 100644 (file)
@@ -355,7 +355,7 @@ func (t *Time) String() string {
        return t.Format(UnixDate)
 }
 
-var errBad = os.ErrorString("bad") // just a marker; not returned to user
+var errBad = os.NewError("bad") // just a marker; not returned to user
 
 // ParseError describes a problem parsing a time string.
 type ParseError struct {
index dde18000d1fe8751e412a7c5059cda05b4817abf..852bae9c935132e7aa75a04dd1de580f27a20a19 100644 (file)
@@ -160,7 +160,7 @@ var onceStartTickerLoop sync.Once
 // ns must be greater than zero; if not, NewTicker will panic.
 func NewTicker(ns int64) *Ticker {
        if ns <= 0 {
-               panic(os.ErrorString("non-positive interval for NewTicker"))
+               panic(os.NewError("non-positive interval for NewTicker"))
        }
        c := make(chan int64, 1) //  See comment on send in tickerLoop
        t := &Ticker{
index e283821969e60598676e6f4b5ed6d9533ef20c05..f066a183205a3992c609fc3e1ba6c5c74e62a57f 100644 (file)
@@ -19,11 +19,13 @@ import (
 )
 
 type ProtocolError struct {
-       os.ErrorString
+       ErrorString string
 }
 
+func (err *ProtocolError) String() string { return string(err.ErrorString) }
+
 var (
-       ErrBadScheme            = os.ErrorString("bad scheme")
+       ErrBadScheme            = &ProtocolError{"bad scheme"}
        ErrBadStatus            = &ProtocolError{"bad status"}
        ErrBadUpgrade           = &ProtocolError{"missing or bad upgrade"}
        ErrBadWebSocketOrigin   = &ProtocolError{"missing or bad WebSocket-Origin"}
index 1e921457ae365cce9e44bf52fae4626ce8ef8225..427c311583603866d0dc72530bf64acc1c437da3 100644 (file)
@@ -251,7 +251,7 @@ func (p *Parser) unmarshal(val reflect.Value, start *StartElement) os.Error {
 
        switch v := val; v.Kind() {
        default:
-               return os.ErrorString("unknown type " + v.Type().String())
+               return os.NewError("unknown type " + v.Type().String())
 
        case reflect.Slice:
                typ := v.Type()
@@ -508,7 +508,7 @@ func copyValue(dst reflect.Value, src []byte) (err os.Error) {
        case reflect.Invalid:
                // Probably a comment, handled below
        default:
-               return os.ErrorString("cannot happen: unknown type " + t.Type().String())
+               return os.NewError("cannot happen: unknown type " + t.Type().String())
        case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
                if !getInt64() {
                        return err
index 0c531968e669a01afd885cedb825853e54165d06..95514cfd650ae6d95c767e040fddc4c02c60c95e 100644 (file)
@@ -38,7 +38,7 @@ func Listen(x, y string) (T, string) {
 }
 
 func (t T) Addr() os.Error {
-       return os.ErrorString("stringer")
+       return os.NewError("stringer")
 }
 
 func (t T) Accept() (int, string) {
@@ -49,4 +49,3 @@ func Dial(x, y, z string) (int, string) {
        global <- 1
        return 0, ""
 }
-