Skip to content

Commit

Permalink
*: add error trace (pingcap#1477)
Browse files Browse the repository at this point in the history
  • Loading branch information
zimulala authored Jul 20, 2016
1 parent 8749945 commit 945fd1d
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func newDriverConn(sess *session, d *sqlDriver, schema string, params *driverPar
func (c *driverConn) Prepare(query string) (driver.Stmt, error) {
stmtID, paramCount, fields, err := c.s.PrepareStmt(query)
if err != nil {
return nil, err
return nil, errors.Trace(err)
}
s := &driverStmt{
conn: c,
Expand Down
2 changes: 1 addition & 1 deletion plan/expression_rewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func constructBinaryOpFunction(l expression.Expression, r expression.Expression,
var err error
funcs[i], err = constructBinaryOpFunction(getRowArg(l, i), getRowArg(r, i), op)
if err != nil {
return nil, err
return nil, errors.Trace(err)
}
}
return expression.ComposeCNFCondition(funcs), nil
Expand Down
4 changes: 2 additions & 2 deletions server/driver_tidb.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (ts *TiDBStatement) ID() int {
func (ts *TiDBStatement) Execute(args ...interface{}) (rs ResultSet, err error) {
tidbRecordset, err := ts.ctx.session.ExecutePreparedStmt(ts.id, args...)
if err != nil {
return nil, err
return nil, errors.Trace(err)
}
if tidbRecordset == nil {
return
Expand Down Expand Up @@ -116,7 +116,7 @@ func (qd *TiDBDriver) OpenCtx(connID uint64, capability uint32, collation uint8,
if dbname != "" {
_, err := session.Execute("use " + dbname)
if err != nil {
return nil, err
return nil, errors.Trace(err)
}
}
tc := &TiDBContext{
Expand Down
4 changes: 2 additions & 2 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ func checkArgs(args ...interface{}) error {
func (s *session) ExecutePreparedStmt(stmtID uint32, args ...interface{}) (ast.RecordSet, error) {
err := checkArgs(args...)
if err != nil {
return nil, err
return nil, errors.Trace(err)
}
st := executor.CompileExecutePreparedStmt(s, stmtID, args...)
r, err := runStmt(s, st, args...)
Expand Down Expand Up @@ -626,7 +626,7 @@ func CreateSession(store kv.Storage) (Session, error) {
}
domain, err := domap.Get(store)
if err != nil {
return nil, err
return nil, errors.Trace(err)
}
sessionctx.BindDomain(s, domain)

Expand Down
8 changes: 4 additions & 4 deletions store/localstore/boltdb/boltdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,21 +179,21 @@ func (driver Driver) Open(dbPath string) (engine.DB, error) {

d, err := bolt.Open(dbPath, 0600, nil)
if err != nil {
return nil, err
return nil, errors.Trace(err)
}

tx, err := d.Begin(true)
if err != nil {
return nil, err
return nil, errors.Trace(err)
}

if _, err = tx.CreateBucketIfNotExists(bucketName); err != nil {
tx.Rollback()
return nil, err
return nil, errors.Trace(err)
}

if err = tx.Commit(); err != nil {
return nil, err
return nil, errors.Trace(err)
}

return &db{d}, nil
Expand Down
3 changes: 2 additions & 1 deletion store/localstore/local_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package localstore
import (
"io"

"github.com/juju/errors"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tipb/go-tipb"
)
Expand Down Expand Up @@ -132,7 +133,7 @@ func (it *response) Next() (resp io.ReadCloser, err error) {
}
if err != nil {
it.Close()
return nil, err
return nil, errors.Trace(err)
}
if len(regionResp.newStartKey) != 0 {
it.client.updateRegionInfo()
Expand Down
2 changes: 1 addition & 1 deletion store/tikv/coprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ func (it *copIterator) Next() (io.ReadCloser, error) {
defer it.mu.Unlock()
if err != nil {
it.Close()
return nil, err
return nil, errors.Trace(err)
}
it.respGot++
if it.respGot == len(it.tasks) {
Expand Down
5 changes: 3 additions & 2 deletions store/tikv/mock-tikv/mvcc.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"bytes"
"sync"

"github.com/juju/errors"
"github.com/petar/GoLLRB/llrb"
"github.com/pingcap/kvproto/pkg/kvrpcpb"
)
Expand Down Expand Up @@ -328,7 +329,7 @@ func (s *MvccStore) CommitThenGet(key []byte, lockTS, commitTS, getTS uint64) ([
entry := s.getOrNewEntry(key)
err := entry.Commit(lockTS, commitTS)
if err != nil {
return nil, err
return nil, errors.Trace(err)
}
s.submit(entry)
return entry.Get(getTS)
Expand Down Expand Up @@ -374,7 +375,7 @@ func (s *MvccStore) RollbackThenGet(key []byte, lockTS uint64) ([]byte, error) {
entry := s.getOrNewEntry(key)
err := entry.Rollback(lockTS)
if err != nil {
return nil, err
return nil, errors.Trace(err)
}
s.submit(entry)
return entry.Get(lockTS)
Expand Down
3 changes: 2 additions & 1 deletion util/mock/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package mock
import (
"fmt"

"github.com/juju/errors"
"github.com/pingcap/tidb/context"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/sessionctx/variable"
Expand Down Expand Up @@ -62,7 +63,7 @@ func (c *Context) GetTxn(forceNew bool) (kv.Transaction, error) {
if forceNew {
err = c.CommitTxn()
if err != nil {
return nil, err
return nil, errors.Trace(err)
}
c.txn, err = c.Store.Begin()
return c.txn, err
Expand Down
8 changes: 4 additions & 4 deletions util/testkit/testkit.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,19 @@ func (tk *TestKit) Exec(sql string, args ...interface{}) (ast.RecordSet, error)
if err == nil && len(rss) > 0 {
return rss[0], nil
}
return nil, err
return nil, errors.Trace(err)
}
stmtID, _, _, err := tk.Se.PrepareStmt(sql)
if err != nil {
return nil, err
return nil, errors.Trace(err)
}
rs, err := tk.Se.ExecutePreparedStmt(stmtID, args...)
if err != nil {
return nil, err
return nil, errors.Trace(err)
}
err = tk.Se.DropPreparedStmt(stmtID)
if err != nil {
return nil, err
return nil, errors.Trace(err)
}
return rs, nil
}
Expand Down

0 comments on commit 945fd1d

Please sign in to comment.