diff options
| author | Gustavo Niemeyer <gustavo@niemeyer.net> | 2011-11-04 09:50:20 -0400 |
|---|---|---|
| committer | Gustavo Niemeyer <gustavo@niemeyer.net> | 2011-11-04 09:50:20 -0400 |
| commit | f2dc50b48d011d4d585d09d5e6bed350894add3d (patch) | |
| tree | a2f4d381dedf7ed00ffa2ac4c1ab9145ae032426 /src/pkg | |
| parent | 39fcca60cb5a13d2836d5d92cf1ed9aea07f6366 (diff) | |
| download | go-f2dc50b48d011d4d585d09d5e6bed350894add3d.tar.xz | |
html,bzip2,sql: rename Error methods that return error to Err
There are three classes of methods/functions called Error:
a) The Error method in the just introduced error interface
b) Error methods that create or report errors (http.Error, etc)
c) Error methods that return errors previously associated with
the receiver (Tokenizer.Error, rows.Error, etc).
This CL introduces the convention that methods in case (c)
should be named Err.
The reasoning for the change is:
- The change differentiates the two kinds of APIs based on
names rather than just on signature, unloading Error a bit
- Err is closer to the err variable name that is so commonly
used with the intent of verifying an error
- Err is shorter and thus more convenient to be used often
on error verifications, such as in iterators following the
convention of the sql package.
R=bradfitz, rsc
CC=golang-dev
https://golang.org/cl/5327064
Diffstat (limited to 'src/pkg')
| -rw-r--r-- | src/pkg/compress/bzip2/bit_reader.go | 4 | ||||
| -rw-r--r-- | src/pkg/compress/bzip2/bzip2.go | 4 | ||||
| -rw-r--r-- | src/pkg/exp/sql/sql.go | 6 | ||||
| -rw-r--r-- | src/pkg/html/parse.go | 2 | ||||
| -rw-r--r-- | src/pkg/html/token.go | 4 | ||||
| -rw-r--r-- | src/pkg/html/token_test.go | 10 |
6 files changed, 15 insertions, 15 deletions
diff --git a/src/pkg/compress/bzip2/bit_reader.go b/src/pkg/compress/bzip2/bit_reader.go index d058c14833..b2c13e50ca 100644 --- a/src/pkg/compress/bzip2/bit_reader.go +++ b/src/pkg/compress/bzip2/bit_reader.go @@ -37,7 +37,7 @@ func newBitReader(r io.Reader) bitReader { // ReadBits64 reads the given number of bits and returns them in the // least-significant part of a uint64. In the event of an error, it returns 0 -// and the error can be obtained by calling Error(). +// and the error can be obtained by calling Err(). func (br *bitReader) ReadBits64(bits uint) (n uint64) { for bits > br.bits { b, err := br.r.ReadByte() @@ -82,6 +82,6 @@ func (br *bitReader) ReadBit() bool { return n != 0 } -func (br *bitReader) Error() error { +func (br *bitReader) Err() error { return br.err } diff --git a/src/pkg/compress/bzip2/bzip2.go b/src/pkg/compress/bzip2/bzip2.go index 343cca03e3..3dc8c62061 100644 --- a/src/pkg/compress/bzip2/bzip2.go +++ b/src/pkg/compress/bzip2/bzip2.go @@ -80,7 +80,7 @@ func (bz2 *reader) Read(buf []byte) (n int, err error) { if !bz2.setupDone { err = bz2.setup() - brErr := bz2.br.Error() + brErr := bz2.br.Err() if brErr != nil { err = brErr } @@ -91,7 +91,7 @@ func (bz2 *reader) Read(buf []byte) (n int, err error) { } n, err = bz2.read(buf) - brErr := bz2.br.Error() + brErr := bz2.br.Err() if brErr != nil { err = brErr } diff --git a/src/pkg/exp/sql/sql.go b/src/pkg/exp/sql/sql.go index 1af8e063cf..291af7f67d 100644 --- a/src/pkg/exp/sql/sql.go +++ b/src/pkg/exp/sql/sql.go @@ -620,7 +620,7 @@ func (s *Stmt) Close() error { // err = rows.Scan(&id, &name) // ... // } -// err = rows.Error() // get any Error encountered during iteration +// err = rows.Err() // get any error encountered during iteration // ... type Rows struct { db *DB @@ -651,8 +651,8 @@ func (rs *Rows) Next() bool { return rs.lasterr == nil } -// Error returns the error, if any, that was encountered during iteration. -func (rs *Rows) Error() error { +// Err returns the error, if any, that was encountered during iteration. +func (rs *Rows) Err() error { if rs.lasterr == io.EOF { return nil } diff --git a/src/pkg/html/parse.go b/src/pkg/html/parse.go index 811e265473..fae0975d37 100644 --- a/src/pkg/html/parse.go +++ b/src/pkg/html/parse.go @@ -250,7 +250,7 @@ func (p *parser) read() error { p.tok = p.tokenizer.Token() switch p.tok.Type { case ErrorToken: - return p.tokenizer.Error() + return p.tokenizer.Err() case SelfClosingTagToken: p.hasSelfClosingToken = true p.tok.Type = StartTagToken diff --git a/src/pkg/html/token.go b/src/pkg/html/token.go index 9213844728..2c138227b1 100644 --- a/src/pkg/html/token.go +++ b/src/pkg/html/token.go @@ -149,9 +149,9 @@ type Tokenizer struct { textIsRaw bool } -// Error returns the error associated with the most recent ErrorToken token. +// Err returns the error associated with the most recent ErrorToken token. // This is typically io.EOF, meaning the end of tokenization. -func (z *Tokenizer) Error() error { +func (z *Tokenizer) Err() error { if z.tt != ErrorToken { return nil } diff --git a/src/pkg/html/token_test.go b/src/pkg/html/token_test.go index 76cc9f835d..61d4e67c06 100644 --- a/src/pkg/html/token_test.go +++ b/src/pkg/html/token_test.go @@ -427,7 +427,7 @@ loop: if tt.golden != "" { for i, s := range strings.Split(tt.golden, "$") { if z.Next() == ErrorToken { - t.Errorf("%s token %d: want %q got error %v", tt.desc, i, s, z.Error()) + t.Errorf("%s token %d: want %q got error %v", tt.desc, i, s, z.Err()) continue loop } actual := z.Token().String() @@ -438,8 +438,8 @@ loop: } } z.Next() - if z.Error() != io.EOF { - t.Errorf("%s: want EOF got %q", tt.desc, z.Error()) + if z.Err() != io.EOF { + t.Errorf("%s: want EOF got %q", tt.desc, z.Err()) } } } @@ -543,8 +543,8 @@ loop: tt := z.Next() switch tt { case ErrorToken: - if z.Error() != io.EOF { - t.Error(z.Error()) + if z.Err() != io.EOF { + t.Error(z.Err()) } break loop case TextToken: |
