Skip to content
This repository has been archived by the owner on Jan 28, 2021. It is now read-only.

Commit

Permalink
Dont rename err to e except when needed
Browse files Browse the repository at this point in the history
Signed-off-by: Juanjo Alvarez <juanjo@sourced.tech>
  • Loading branch information
Juanjo Alvarez committed Apr 24, 2019
1 parent 16e67f1 commit 23d36b5
Show file tree
Hide file tree
Showing 14 changed files with 103 additions and 82 deletions.
17 changes: 9 additions & 8 deletions auth/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,20 @@ func testAuthentication(
t.Run(fmt.Sprintf("%s-%s", c.user, c.password), func(t *testing.T) {
r := require.New(t)

db, e := dsql.Open("mysql", connString(c.user, c.password))
r.NoError(e)
_, e = db.Query("SELECT 1")
var db *dsql.DB
db, err = dsql.Open("mysql", connString(c.user, c.password))
r.NoError(err)
_, err = db.Query("SELECT 1")

if c.success {
r.NoError(e)
r.NoError(err)
} else {
r.Error(e)
r.Contains(e.Error(), "Access denied")
r.Error(err)
r.Contains(err.Error(), "Access denied")
}

e = db.Close()
r.NoError(e)
err = db.Close()
r.NoError(err)

if extra != nil {
extra(t, c)
Expand Down
15 changes: 9 additions & 6 deletions mem/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,17 @@ func TestTable(t *testing.T) {
require.NoError(err)

for i := 0; i < test.numPartitions; i++ {
p, e := pIter.Next()
require.NoError(e)
var p sql.Partition
p, err = pIter.Next()
require.NoError(err)

iter, e := table.PartitionRows(sql.NewEmptyContext(), p)
require.NoError(e)
var iter sql.RowIter
iter, err = table.PartitionRows(sql.NewEmptyContext(), p)
require.NoError(err)

rows, e := sql.RowIterToRows(iter)
require.NoError(e)
var rows []sql.Row
rows, err = sql.RowIterToRows(iter)
require.NoError(err)

expected := table.partitions[string(p.Key())]
require.Len(rows, len(expected))
Expand Down
18 changes: 10 additions & 8 deletions sql/expression/function/ceil_round_floor.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,10 @@ func (r *Round) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
dVal := float64(0)

if r.Right != nil {
dTemp, e := r.Right.Eval(ctx, row)
if e != nil {
return nil, e
var dTemp interface{}
dTemp, err = r.Right.Eval(ctx, row)
if err != nil {
return nil, err
}

if dTemp != nil {
Expand All @@ -207,8 +208,8 @@ func (r *Round) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
case int:
dVal = float64(dNum)
default:
dTemp, e = sql.Float64.Convert(dTemp)
if e == nil {
dTemp, err = sql.Float64.Convert(dTemp)
if err == nil {
dVal = dTemp.(float64)
}
}
Expand Down Expand Up @@ -280,9 +281,10 @@ func (r *Round) TransformUp(f sql.TransformExprFunc) (sql.Expression, error) {

args[1] = nil
if r.Right != nil {
arg, e := r.Right.TransformUp(f)
if e != nil {
return nil, e
var arg sql.Expression
arg, err = r.Right.TransformUp(f)
if err != nil {
return nil, err
}
args[1] = arg
}
Expand Down
4 changes: 2 additions & 2 deletions sql/expression/function/time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,10 @@ func TestCalcWeek(t *testing.T) {
func TestNow(t *testing.T) {
require := require.New(t)
date := time.Date(2018, time.December, 2, 16, 25, 0, 0, time.Local)
cl := clock(func() time.Time {
clk := clock(func() time.Time {
return date
})
f := &Now{cl}
f := &Now{clk}

result, err := f.Eval(nil, nil)
require.NoError(err)
Expand Down
13 changes: 7 additions & 6 deletions sql/expression/like.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,14 @@ func (l *Like) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
)
// eval right and convert to text
if !l.cached || l.pool == nil {
v, e := l.Right.Eval(ctx, row)
if e != nil || v == nil {
return nil, e
var v interface{}
v, err = l.Right.Eval(ctx, row)
if err != nil || v == nil {
return nil, err
}
v, e = sql.Text.Convert(v)
if e != nil {
return nil, e
v, err = sql.Text.Convert(v)
if err != nil {
return nil, err
}
right = patternToRegex(v.(string))
}
Expand Down
9 changes: 5 additions & 4 deletions sql/index/pilosa/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func (d *Driver) loadIndex(db, table, id string) (*pilosaIndex, error) {
"dir": dir,
})
log.Warn("could not read index file, index is corrupt and will be deleted")
if e := os.RemoveAll(dir); e != nil {
if err = os.RemoveAll(dir); err != nil {
log.Warn("unable to remove corrupted index: " + dir)
}

Expand Down Expand Up @@ -262,8 +262,8 @@ func (d *Driver) savePartition(
if !ok {
return 0, errMappingNotFound.New(mk)
}
if e := mapping.openCreate(true); e != nil {
return 0, e
if err := mapping.openCreate(true); err != nil {
return 0, err
}

defer func() {
Expand Down Expand Up @@ -304,7 +304,8 @@ func (d *Driver) savePartition(
continue
}

rowID, err := mapping.getRowID(field.Name(), values[i])
var rowID uint64
rowID, err = mapping.getRowID(field.Name(), values[i])
if err != nil {
return 0, err
}
Expand Down
32 changes: 19 additions & 13 deletions sql/index/pilosa/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,18 +192,21 @@ func TestSaveAndLoad(t *testing.T) {

for partition, records := range it.records {
for _, r := range records {
lookup, e := sqlIdx.Get(r.values...)
require.NoError(e)
var lookup sql.IndexLookup
lookup, err = sqlIdx.Get(r.values...)
require.NoError(err)

lit, e := lookup.Values(testPartition(partition))
require.NoError(e)
var lit sql.IndexValueIter
lit, err = lookup.Values(testPartition(partition))
require.NoError(err)

for {
loc, e := lit.Next()
if e == io.EOF {
var loc []byte
loc, err = lit.Next()
if err == io.EOF {
break
}
require.NoError(e)
require.NoError(err)

locations[partition] = append(locations[partition], string(loc))
}
Expand Down Expand Up @@ -869,8 +872,9 @@ func TestUnionDiffAsc(t *testing.T) {
for partition, records := range it.records {
ls[partition] = make([]*indexLookup, it.total)
for i, r := range records {
l, e := pilosaIdx.Get(r.values...)
require.NoError(e)
var l sql.IndexLookup
l, err = pilosaIdx.Get(r.values...)
require.NoError(err)
ls[partition][i], _ = l.(*indexLookup)
}
}
Expand All @@ -882,8 +886,9 @@ func TestUnionDiffAsc(t *testing.T) {
require.NoError(err)

for i := 1; i < it.total-1; i += 2 {
loc, e := diffIt.Next()
require.NoError(e)
var loc []byte
loc, err = diffIt.Next()
require.NoError(err)

require.Equal(it.records[0][i].location, loc)
}
Expand Down Expand Up @@ -936,8 +941,9 @@ func TestInterRanges(t *testing.T) {
require.NoError(err)

for i := ranges[0]; i < ranges[1]; i++ {
loc, e := interIt.Next()
require.NoError(e)
var loc []byte
loc, err = interIt.Next()
require.NoError(err)
require.Equal(it.records[0][i].location, loc)
}

Expand Down
14 changes: 8 additions & 6 deletions sql/index/pilosa/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,10 @@ func newAscendLookup(f *filteredLookup, gte []interface{}, lt []interface{}) *as
return false, err
}

cmp, e := compare(v, l.gte[i])
if e != nil {
return false, e
var cmp int
cmp, err = compare(v, l.gte[i])
if err != nil {
return false, err
}

if cmp < 0 {
Expand Down Expand Up @@ -349,9 +350,10 @@ func newDescendLookup(f *filteredLookup, gt []interface{}, lte []interface{}) *d
return false, err
}

cmp, e := compare(v, l.gt[i])
if e != nil {
return false, e
var cmp int
cmp, err = compare(v, l.gt[i])
if err != nil {
return false, err
}

if cmp <= 0 {
Expand Down
7 changes: 4 additions & 3 deletions sql/index/pilosa/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,8 @@ func (l *filteredLookup) Values(p sql.Partition) (sql.IndexValueIter, error) {
}

bits := row.Columns()
if e := m.open(); e != nil {
return nil, e
if err = m.open(); err != nil {
return nil, err
}

defer m.close()
Expand Down Expand Up @@ -455,7 +455,8 @@ func (l *negateLookup) intersectExpressions(p sql.Partition, m *mapping) (*pilos
var r *pilosa.Row
// rowIDs start with 1
for ri := uint64(1); ri <= maxRowID; ri++ {
rr, err := field.Row(ri)
var rr *pilosa.Row
rr, err = field.Row(ri)
if err != nil {
return nil, err
}
Expand Down
7 changes: 4 additions & 3 deletions sql/parse/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ func readTableLocks(tables *[]*plan.TableLock) parseFunc {

*tables = append(*tables, t)

if e := skipSpaces(rd); e != nil {
return e
if err = skipSpaces(rd); err != nil {
return err
}

b, err := rd.Peek(1)
var b []byte
b, err = rd.Peek(1)
if err == io.EOF {
return nil
} else if err != nil {
Expand Down
14 changes: 8 additions & 6 deletions sql/parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -1043,14 +1043,16 @@ func caseExprToExpression(e *sqlparser.CaseExpr) (sql.Expression, error) {

var branches []expression.CaseBranch
for _, w := range e.Whens {
cond, e := exprToExpression(w.Cond)
if e != nil {
return nil, e
var cond sql.Expression
cond, err = exprToExpression(w.Cond)
if err != nil {
return nil, err
}

val, e := exprToExpression(w.Val)
if e != nil {
return nil, e
var val sql.Expression
val, err = exprToExpression(w.Val)
if err != nil {
return nil, err
}

branches = append(branches, expression.CaseBranch{
Expand Down
18 changes: 9 additions & 9 deletions sql/parse/show_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ func parseShowCreate(s string) (sql.Node, error) {
} else if err == nil && ru == '.' {
db = table

if e := readQuotableIdent(&table)(r); e != nil {
return nil, e
if err = readQuotableIdent(&table)(r); err != nil {
return nil, err
}
}

Expand Down Expand Up @@ -71,26 +71,26 @@ func parseShowCreate(s string) (sql.Node, error) {
// If ` is the next character, it's a db name. Otherwise it may be
// a table name or IF NOT EXISTS.
if nextByte[0] == '`' {
if e := readQuotableIdent(&next)(r); e != nil {
return nil, e
if err = readQuotableIdent(&next)(r); err != nil {
return nil, err
}
} else {
if e := readIdent(&next)(r); e != nil {
return nil, e
if err = readIdent(&next)(r); err != nil {
return nil, err
}

if next == "if" {
ifNotExists = true
e := parseFuncs{
err = parseFuncs{
skipSpaces,
expect("not"),
skipSpaces,
expect("exists"),
skipSpaces,
readQuotableIdent(&next),
}.exec(r)
if e != nil {
return nil, e
if err != nil {
return nil, err
}
}
}
Expand Down
13 changes: 7 additions & 6 deletions sql/plan/innerjoin.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strconv"
"strings"

opentracing "github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go"
"github.com/pbnjay/memory"
"github.com/sirupsen/logrus"
"gopkg.in/src-d/go-mysql-server.v0/sql"
Expand Down Expand Up @@ -270,8 +270,8 @@ func (i *innerJoinIter) fitsInMemory() bool {
func (i *innerJoinIter) loadRight() (row sql.Row, skip bool, err error) {
if i.mode == memoryMode {
if len(i.right) == 0 {
if e := i.loadRightInMemory(); e != nil {
return nil, false, e
if err = i.loadRightInMemory(); err != nil {
return nil, false, err
}
}

Expand All @@ -287,9 +287,10 @@ func (i *innerJoinIter) loadRight() (row sql.Row, skip bool, err error) {
}

if i.r == nil {
iter, e := i.rp.RowIter(i.ctx)
if e != nil {
return nil, false, e
var iter sql.RowIter
iter, err = i.rp.RowIter(i.ctx)
if err != nil {
return nil, false, err
}

i.r = iter
Expand Down
4 changes: 2 additions & 2 deletions sql/plan/resolved_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ func (i *tableIter) Next() (sql.Row, error) {

row, err := i.rows.Next()
if err != nil && err == io.EOF {
if e := i.rows.Close(); e != nil {
return nil, e
if err = i.rows.Close(); err != nil {
return nil, err
}

i.partition = nil
Expand Down

0 comments on commit 23d36b5

Please sign in to comment.