aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOleksandr Redko <oleksandr.red+github@gmail.com>2023-02-12 15:37:00 +0200
committerGopher Robot <gobot@golang.org>2023-02-16 23:09:19 +0000
commit3ad6393f8676b1b408673bf40b8a876f29561eef (patch)
tree7338eaf302fd64d9d24e9776999a919e87c71778
parent135c470b2277e1c9514ba8a5478408fea0dee8a2 (diff)
downloadgo-3ad6393f8676b1b408673bf40b8a876f29561eef.tar.xz
src: rename unexported errors by adding prefix err
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>
-rw-r--r--src/encoding/binary/varint.go6
-rw-r--r--src/encoding/binary/varint_test.go6
-rw-r--r--src/fmt/scan.go14
-rw-r--r--src/time/format.go4
-rw-r--r--src/time/zoneinfo_plan9.go8
-rw-r--r--src/time/zoneinfo_read.go34
6 files changed, 36 insertions, 36 deletions
diff --git a/src/encoding/binary/varint.go b/src/encoding/binary/varint.go
index 18e1ff1511..7b14fb2b63 100644
--- a/src/encoding/binary/varint.go
+++ b/src/encoding/binary/varint.go
@@ -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.
diff --git a/src/encoding/binary/varint_test.go b/src/encoding/binary/varint_test.go
index a3caea8a43..5c3ea318c3 100644
--- a/src/encoding/binary/varint_test.go
+++ b/src/encoding/binary/varint_test.go
@@ -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) {
diff --git a/src/fmt/scan.go b/src/fmt/scan.go
index 2780b82de2..5dd0971642 100644
--- a/src/fmt/scan.go
+++ b/src/fmt/scan.go
@@ -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
}
diff --git a/src/time/format.go b/src/time/format.go
index f94d68ee02..7fbeddb540 100644
--- a/src/time/format.go
+++ b/src/time/format.go
@@ -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
diff --git a/src/time/zoneinfo_plan9.go b/src/time/zoneinfo_plan9.go
index 5d432fe297..d13b623a37 100644
--- a/src/time/zoneinfo_plan9.go
+++ b/src/time/zoneinfo_plan9.go
@@ -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)})
diff --git a/src/time/zoneinfo_read.go b/src/time/zoneinfo_read.go
index 90814ad36a..d8b35003a1 100644
--- a/src/time/zoneinfo_read.go
+++ b/src/time/zoneinfo_read.go
@@ -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) {