Error improvements for lint.
Rename errors to Err*. Lowercase error text. Add golint for top level package ok @davecgh
This commit is contained in:
parent
372bbe5c49
commit
a7ac93f5b6
7 changed files with 29 additions and 28 deletions
|
@ -11,6 +11,7 @@ install:
|
|||
script:
|
||||
- export PATH=$PATH:$HOME/gopath/bin
|
||||
- go vet ./...
|
||||
- fgt golint .
|
||||
- fgt golint memdb
|
||||
- fgt golint ldb
|
||||
- go test -v
|
||||
|
|
16
db.go
16
db.go
|
@ -13,12 +13,12 @@ import (
|
|||
|
||||
// Errors that the various database functions may return.
|
||||
var (
|
||||
PrevShaMissing = errors.New("Previous sha missing from database")
|
||||
TxShaMissing = errors.New("Requested transaction does not exist")
|
||||
BlockShaMissing = errors.New("Requested block does not exist")
|
||||
DuplicateSha = errors.New("Duplicate insert attempted")
|
||||
DbDoesNotExist = errors.New("Non-existent database")
|
||||
DbUnknownType = errors.New("Non-existent database type")
|
||||
ErrPrevShaMissing = errors.New("previous sha missing from database")
|
||||
ErrTxShaMissing = errors.New("requested transaction does not exist")
|
||||
ErrBlockShaMissing = errors.New("requested block does not exist")
|
||||
ErrDuplicateSha = errors.New("duplicate insert attempted")
|
||||
ErrDbDoesNotExist = errors.New("non-existent database")
|
||||
ErrDbUnknownType = errors.New("non-existent database type")
|
||||
)
|
||||
|
||||
// AllShas is a special value that can be used as the final sha when requesting
|
||||
|
@ -156,7 +156,7 @@ func CreateDB(dbtype string, args ...interface{}) (pbdb Db, err error) {
|
|||
return drv.CreateDB(args...)
|
||||
}
|
||||
}
|
||||
return nil, DbUnknownType
|
||||
return nil, ErrDbUnknownType
|
||||
}
|
||||
|
||||
// OpenDB opens an existing database.
|
||||
|
@ -166,7 +166,7 @@ func OpenDB(dbtype string, args ...interface{}) (pbdb Db, err error) {
|
|||
return drv.OpenDB(args...)
|
||||
}
|
||||
}
|
||||
return nil, DbUnknownType
|
||||
return nil, ErrDbUnknownType
|
||||
}
|
||||
|
||||
// SupportedDBs returns a slice of strings that represent the database drivers
|
||||
|
|
|
@ -77,7 +77,7 @@ func (db *LevelDb) getBlkLoc(sha *btcwire.ShaHash) (int64, error) {
|
|||
data, err := db.lDb.Get(key, db.ro)
|
||||
if err != nil {
|
||||
if err == leveldb.ErrNotFound {
|
||||
err = btcdb.BlockShaMissing
|
||||
err = btcdb.ErrBlockShaMissing
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
|
@ -206,7 +206,7 @@ func (db *LevelDb) blkExistsSha(sha *btcwire.ShaHash) (bool, error) {
|
|||
switch err {
|
||||
case nil:
|
||||
return true, nil
|
||||
case leveldb.ErrNotFound, btcdb.BlockShaMissing:
|
||||
case leveldb.ErrNotFound, btcdb.ErrBlockShaMissing:
|
||||
return false, nil
|
||||
}
|
||||
return false, err
|
||||
|
|
|
@ -17,7 +17,7 @@ func FetchSha(db btcdb.Db, sha *btcwire.ShaHash) (buf []byte, pver uint32,
|
|||
blkid int64, err error) {
|
||||
sqldb, ok := db.(*LevelDb)
|
||||
if !ok {
|
||||
err = fmt.Errorf("Invalid data type")
|
||||
err = fmt.Errorf("invalid data type")
|
||||
return
|
||||
}
|
||||
buf, blkid, err = sqldb.fetchSha(sha)
|
||||
|
|
|
@ -175,7 +175,7 @@ func openDB(dbpath string, create bool) (pbdb btcdb.Db, err error) {
|
|||
} else {
|
||||
_, err = os.Stat(dbpath)
|
||||
if err != nil {
|
||||
err = btcdb.DbDoesNotExist
|
||||
err = btcdb.ErrDbDoesNotExist
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
14
ldb/tx.go
14
ldb/tx.go
|
@ -99,7 +99,7 @@ func (db *LevelDb) getTxFullySpent(txsha *btcwire.ShaHash) ([]*spentTx, error) {
|
|||
key := shaSpentTxToKey(txsha)
|
||||
buf, err := db.lDb.Get(key, db.ro)
|
||||
if err == leveldb.ErrNotFound {
|
||||
return badTxList, btcdb.TxShaMissing
|
||||
return badTxList, btcdb.ErrTxShaMissing
|
||||
} else if err != nil {
|
||||
return badTxList, err
|
||||
}
|
||||
|
@ -186,7 +186,7 @@ func (db *LevelDb) FetchTxByShaList(txShaList []*btcwire.ShaHash) []*btcdb.TxLis
|
|||
btxspent[idx] = (txspent[byteidx] & (byte(1) << byteoff)) != 0
|
||||
}
|
||||
}
|
||||
if err == btcdb.TxShaMissing {
|
||||
if err == btcdb.ErrTxShaMissing {
|
||||
// if the unspent pool did not have the tx,
|
||||
// look in the fully spent pool (only last instance
|
||||
|
||||
|
@ -244,7 +244,7 @@ func (db *LevelDb) fetchTxDataBySha(txsha *btcwire.ShaHash) (rtx *btcwire.MsgTx,
|
|||
blkHeight, txOff, txLen, txspent, err = db.getTxData(txsha)
|
||||
if err != nil {
|
||||
if err == leveldb.ErrNotFound {
|
||||
err = btcdb.TxShaMissing
|
||||
err = btcdb.ErrTxShaMissing
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -260,7 +260,7 @@ func (db *LevelDb) fetchTxDataByLoc(blkHeight int64, txOff int, txLen int, txspe
|
|||
blksha, blkbuf, err = db.getBlkByHeight(blkHeight)
|
||||
if err != nil {
|
||||
if err == leveldb.ErrNotFound {
|
||||
err = btcdb.TxShaMissing
|
||||
err = btcdb.ErrTxShaMissing
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -269,7 +269,7 @@ func (db *LevelDb) fetchTxDataByLoc(blkHeight int64, txOff int, txLen int, txspe
|
|||
// txsha, blksha, blkHeight, txOff, txLen)
|
||||
|
||||
if len(blkbuf) < txOff+txLen {
|
||||
err = btcdb.TxShaMissing
|
||||
err = btcdb.ErrTxShaMissing
|
||||
return
|
||||
}
|
||||
rbuf := bytes.NewReader(blkbuf[txOff : txOff+txLen])
|
||||
|
@ -297,7 +297,7 @@ func (db *LevelDb) FetchTxBySha(txsha *btcwire.ShaHash) ([]*btcdb.TxListReply, e
|
|||
if txerr == nil {
|
||||
replylen++
|
||||
} else {
|
||||
if txerr != btcdb.TxShaMissing {
|
||||
if txerr != btcdb.ErrTxShaMissing {
|
||||
return []*btcdb.TxListReply{}, txerr
|
||||
}
|
||||
}
|
||||
|
@ -305,7 +305,7 @@ func (db *LevelDb) FetchTxBySha(txsha *btcwire.ShaHash) ([]*btcdb.TxListReply, e
|
|||
sTxList, fSerr := db.getTxFullySpent(txsha)
|
||||
|
||||
if fSerr != nil {
|
||||
if fSerr != btcdb.TxShaMissing {
|
||||
if fSerr != btcdb.ErrTxShaMissing {
|
||||
return []*btcdb.TxListReply{}, fSerr
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -17,7 +17,7 @@ import (
|
|||
|
||||
// Errors that the various database functions may return.
|
||||
var (
|
||||
ErrDbClosed = errors.New("Database is closed")
|
||||
ErrDbClosed = errors.New("database is closed")
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -383,7 +383,7 @@ func (db *MemDb) FetchTxBySha(txHash *btcwire.ShaHash) ([]*btcdb.TxListReply, er
|
|||
if !exists {
|
||||
log.Warnf("FetchTxBySha: requested hash of %s does not exist",
|
||||
txHash)
|
||||
return nil, btcdb.TxShaMissing
|
||||
return nil, btcdb.ErrTxShaMissing
|
||||
}
|
||||
|
||||
txHashCopy := *txHash
|
||||
|
@ -431,7 +431,7 @@ func (db *MemDb) fetchTxByShaList(txShaList []*btcwire.ShaHash, includeSpent boo
|
|||
// information if the transaction exists.
|
||||
reply := btcdb.TxListReply{
|
||||
Sha: txShaList[i],
|
||||
Err: btcdb.TxShaMissing,
|
||||
Err: btcdb.ErrTxShaMissing,
|
||||
}
|
||||
replyList = append(replyList, &reply)
|
||||
|
||||
|
@ -548,7 +548,7 @@ func (db *MemDb) InsertBlock(block *btcutil.Block) (int64, error) {
|
|||
msgBlock := block.MsgBlock()
|
||||
if _, exists := db.blocksBySha[msgBlock.Header.PrevBlock]; !exists {
|
||||
if len(db.blocks) > 0 {
|
||||
return 0, btcdb.PrevShaMissing
|
||||
return 0, btcdb.ErrPrevShaMissing
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -599,7 +599,7 @@ func (db *MemDb) InsertBlock(block *btcutil.Block) (int64, error) {
|
|||
log.Warnf("InsertBlock: requested hash "+
|
||||
" of %s does not exist in-flight",
|
||||
tx.Sha())
|
||||
return 0, btcdb.TxShaMissing
|
||||
return 0, btcdb.ErrTxShaMissing
|
||||
}
|
||||
} else {
|
||||
originTxns, exists := db.txns[prevOut.Hash]
|
||||
|
@ -607,14 +607,14 @@ func (db *MemDb) InsertBlock(block *btcutil.Block) (int64, error) {
|
|||
log.Warnf("InsertBlock: requested hash "+
|
||||
"of %s by %s does not exist",
|
||||
prevOut.Hash, tx.Sha())
|
||||
return 0, btcdb.TxShaMissing
|
||||
return 0, btcdb.ErrTxShaMissing
|
||||
}
|
||||
originTxD := originTxns[len(originTxns)-1]
|
||||
if prevOut.Index > uint32(len(originTxD.spentBuf)) {
|
||||
log.Warnf("InsertBlock: requested hash "+
|
||||
"of %s with index %d does not "+
|
||||
"exist", tx.Sha(), prevOut.Index)
|
||||
return 0, btcdb.TxShaMissing
|
||||
return 0, btcdb.ErrTxShaMissing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -624,7 +624,7 @@ func (db *MemDb) InsertBlock(block *btcutil.Block) (int64, error) {
|
|||
inFlightIndex < i {
|
||||
log.Warnf("Block contains duplicate transaction %s",
|
||||
tx.Sha())
|
||||
return 0, btcdb.DuplicateSha
|
||||
return 0, btcdb.ErrDuplicateSha
|
||||
}
|
||||
|
||||
// Prevent duplicate transactions unless the old one is fully
|
||||
|
@ -634,7 +634,7 @@ func (db *MemDb) InsertBlock(block *btcutil.Block) (int64, error) {
|
|||
if !isFullySpent(txD) {
|
||||
log.Warnf("Attempt to insert duplicate "+
|
||||
"transaction %s", tx.Sha())
|
||||
return 0, btcdb.DuplicateSha
|
||||
return 0, btcdb.ErrDuplicateSha
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue