]> Cypherpunks repositories - gostls13.git/commitdiff
src: rename unexported errors by adding prefix err
authorOleksandr Redko <oleksandr.red+github@gmail.com>
Sun, 12 Feb 2023 13:37:00 +0000 (15:37 +0200)
committerGopher Robot <gobot@golang.org>
Thu, 16 Feb 2023 23:09:19 +0000 (23:09 +0000)
By convention, use `err` as prefix for variables of type `error`.

Change-Id: I9401d5d47e994a27be245b2c8b1edd55cdd52db1
Reviewed-on: https://go-review.googlesource.com/c/go/+/467536
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>

src/encoding/binary/varint.go
src/encoding/binary/varint_test.go
src/fmt/scan.go
src/time/format.go
src/time/zoneinfo_plan9.go
src/time/zoneinfo_read.go

index 18e1ff15115202ba5b0f10ea5010b1621d33916d..7b14fb2b631b02b1dfd149def475a8ef9409c60d 100644 (file)
@@ -123,7 +123,7 @@ func Varint(buf []byte) (int64, int) {
        return x, n
 }
 
-var overflow = errors.New("binary: varint overflows a 64-bit integer")
+var errOverflow = errors.New("binary: varint overflows a 64-bit integer")
 
 // ReadUvarint reads an encoded unsigned integer from r and returns it as a uint64.
 // The error is EOF only if no bytes were read.
@@ -142,14 +142,14 @@ func ReadUvarint(r io.ByteReader) (uint64, error) {
                }
                if b < 0x80 {
                        if i == MaxVarintLen64-1 && b > 1 {
-                               return x, overflow
+                               return x, errOverflow
                        }
                        return x | uint64(b)<<s, nil
                }
                x |= uint64(b&0x7f) << s
                s += 7
        }
-       return x, overflow
+       return x, errOverflow
 }
 
 // ReadVarint reads an encoded signed integer from r and returns it as an int64.
index a3caea8a4303165cf000fb38ad1c59d60d7f168d..5c3ea318c397bdf650cc771d06d5b42631736abb 100644 (file)
@@ -212,9 +212,9 @@ func testOverflow(t *testing.T, buf []byte, x0 uint64, n0 int, err0 error) {
 }
 
 func TestOverflow(t *testing.T) {
-       testOverflow(t, []byte{0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x2}, 0, -10, overflow)
-       testOverflow(t, []byte{0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x1, 0, 0}, 0, -11, overflow)
-       testOverflow(t, []byte{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, 1<<64-1, -11, overflow) // 11 bytes, should overflow
+       testOverflow(t, []byte{0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x2}, 0, -10, errOverflow)
+       testOverflow(t, []byte{0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x1, 0, 0}, 0, -11, errOverflow)
+       testOverflow(t, []byte{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, 1<<64-1, -11, errOverflow) // 11 bytes, should overflow
 }
 
 func TestNonCanonicalZero(t *testing.T) {
index 2780b82de276acc3393a33547e8ca0a669e48184..5dd0971642d111f65f01c7b91e7ce2c46a52fa01 100644 (file)
@@ -462,8 +462,8 @@ func (s *ss) token(skipSpace bool, f func(rune) bool) []byte {
        return s.buf
 }
 
-var complexError = errors.New("syntax error scanning complex number")
-var boolError = errors.New("syntax error scanning boolean")
+var errComplex = errors.New("syntax error scanning complex number")
+var errBool = errors.New("syntax error scanning boolean")
 
 func indexRune(s string, r rune) int {
        for i, c := range s {
@@ -542,12 +542,12 @@ func (s *ss) scanBool(verb rune) bool {
                return true
        case 't', 'T':
                if s.accept("rR") && (!s.accept("uU") || !s.accept("eE")) {
-                       s.error(boolError)
+                       s.error(errBool)
                }
                return true
        case 'f', 'F':
                if s.accept("aA") && (!s.accept("lL") || !s.accept("sS") || !s.accept("eE")) {
-                       s.error(boolError)
+                       s.error(errBool)
                }
                return false
        }
@@ -747,16 +747,16 @@ func (s *ss) complexTokens() (real, imag string) {
        s.buf = s.buf[:0]
        // Must now have a sign.
        if !s.accept("+-") {
-               s.error(complexError)
+               s.error(errComplex)
        }
        // Sign is now in buffer
        imagSign := string(s.buf)
        imag = s.floatToken()
        if !s.accept("i") {
-               s.error(complexError)
+               s.error(errComplex)
        }
        if parens && !s.accept(")") {
-               s.error(complexError)
+               s.error(errComplex)
        }
        return real, imagSign + imag
 }
index f94d68ee024491f9064f66be4055c95a78af3f3e..7fbeddb540657471596d2441721fe6adbfe44cad 100644 (file)
@@ -446,7 +446,7 @@ func appendInt(b []byte, x int, width int) []byte {
 }
 
 // Never printed, just needs to be non-nil for return by atoi.
-var atoiError = errors.New("time: invalid number")
+var errAtoi = errors.New("time: invalid number")
 
 // Duplicates functionality in strconv, but avoids dependency.
 func atoi[bytes []byte | string](s bytes) (x int, err error) {
@@ -458,7 +458,7 @@ func atoi[bytes []byte | string](s bytes) (x int, err error) {
        q, rem, err := leadingInt(s)
        x = int(q)
        if err != nil || len(rem) > 0 {
-               return 0, atoiError
+               return 0, errAtoi
        }
        if neg {
                x = -x
index 5d432fe297dd9eaa664cc151dd35a3a97fc7fb9b..d13b623a3738e5470ace88a4202690848184d1bc 100644 (file)
@@ -56,7 +56,7 @@ func loadZoneDataPlan9(s string) (l *Location, err error) {
                if len(f) == 2 && f[0] == "GMT" {
                        return UTC, nil
                }
-               return nil, badData
+               return nil, errBadData
        }
 
        var zones [2]zone
@@ -64,14 +64,14 @@ func loadZoneDataPlan9(s string) (l *Location, err error) {
        // standard timezone offset
        o, err := atoi(f[1])
        if err != nil {
-               return nil, badData
+               return nil, errBadData
        }
        zones[0] = zone{name: f[0], offset: o, isDST: false}
 
        // alternate timezone offset
        o, err = atoi(f[3])
        if err != nil {
-               return nil, badData
+               return nil, errBadData
        }
        zones[1] = zone{name: f[2], offset: o, isDST: true}
 
@@ -85,7 +85,7 @@ func loadZoneDataPlan9(s string) (l *Location, err error) {
                }
                t, err := atoi(f[i])
                if err != nil {
-                       return nil, badData
+                       return nil, errBadData
                }
                t -= zones[0].offset
                tx = append(tx, zoneTrans{when: int64(t), index: uint8(zi)})
index 90814ad36a1ad437e91c105ee74ba90c091954e5..d8b35003a1d6374fcdd8d43dafd1ebed29fc83b6 100644 (file)
@@ -107,7 +107,7 @@ func byteString(p []byte) string {
        return string(p)
 }
 
-var badData = errors.New("malformed time zone information")
+var errBadData = errors.New("malformed time zone information")
 
 // LoadLocationFromTZData returns a Location with the given name
 // initialized from the IANA Time Zone database-formatted data.
@@ -118,14 +118,14 @@ func LoadLocationFromTZData(name string, data []byte) (*Location, error) {
 
        // 4-byte magic "TZif"
        if magic := d.read(4); string(magic) != "TZif" {
-               return nil, badData
+               return nil, errBadData
        }
 
        // 1-byte version, then 15 bytes of padding
        var version int
        var p []byte
        if p = d.read(16); len(p) != 16 {
-               return nil, badData
+               return nil, errBadData
        } else {
                switch p[0] {
                case 0:
@@ -135,7 +135,7 @@ func LoadLocationFromTZData(name string, data []byte) (*Location, error) {
                case '3':
                        version = 3
                default:
-                       return nil, badData
+                       return nil, errBadData
                }
        }
 
@@ -158,10 +158,10 @@ func LoadLocationFromTZData(name string, data []byte) (*Location, error) {
        for i := 0; i < 6; i++ {
                nn, ok := d.big4()
                if !ok {
-                       return nil, badData
+                       return nil, errBadData
                }
                if uint32(int(nn)) != nn {
-                       return nil, badData
+                       return nil, errBadData
                }
                n[i] = int(nn)
        }
@@ -191,10 +191,10 @@ func LoadLocationFromTZData(name string, data []byte) (*Location, error) {
                for i := 0; i < 6; i++ {
                        nn, ok := d.big4()
                        if !ok {
-                               return nil, badData
+                               return nil, errBadData
                        }
                        if uint32(int(nn)) != nn {
-                               return nil, badData
+                               return nil, errBadData
                        }
                        n[i] = int(nn)
                }
@@ -229,7 +229,7 @@ func LoadLocationFromTZData(name string, data []byte) (*Location, error) {
        isutc := d.read(n[NUTCLocal])
 
        if d.error { // ran out of data
-               return nil, badData
+               return nil, errBadData
        }
 
        var extend string
@@ -245,26 +245,26 @@ func LoadLocationFromTZData(name string, data []byte) (*Location, error) {
        if nzone == 0 {
                // Reject tzdata files with no zones. There's nothing useful in them.
                // This also avoids a panic later when we add and then use a fake transition (golang.org/issue/29437).
-               return nil, badData
+               return nil, errBadData
        }
        zones := make([]zone, nzone)
        for i := range zones {
                var ok bool
                var n uint32
                if n, ok = zonedata.big4(); !ok {
-                       return nil, badData
+                       return nil, errBadData
                }
                if uint32(int(n)) != n {
-                       return nil, badData
+                       return nil, errBadData
                }
                zones[i].offset = int(int32(n))
                var b byte
                if b, ok = zonedata.byte(); !ok {
-                       return nil, badData
+                       return nil, errBadData
                }
                zones[i].isDST = b != 0
                if b, ok = zonedata.byte(); !ok || int(b) >= len(abbrev) {
-                       return nil, badData
+                       return nil, errBadData
                }
                zones[i].name = byteString(abbrev[b:])
                if runtime.GOOS == "aix" && len(name) > 8 && (name[:8] == "Etc/GMT+" || name[:8] == "Etc/GMT-") {
@@ -283,20 +283,20 @@ func LoadLocationFromTZData(name string, data []byte) (*Location, error) {
                var n int64
                if !is64 {
                        if n4, ok := txtimes.big4(); !ok {
-                               return nil, badData
+                               return nil, errBadData
                        } else {
                                n = int64(int32(n4))
                        }
                } else {
                        if n8, ok := txtimes.big8(); !ok {
-                               return nil, badData
+                               return nil, errBadData
                        } else {
                                n = int64(n8)
                        }
                }
                tx[i].when = n
                if int(txzones[i]) >= len(zones) {
-                       return nil, badData
+                       return nil, errBadData
                }
                tx[i].index = txzones[i]
                if i < len(isstd) {