Skip to content

Commit

Permalink
Remove cmn.Panic*
Browse files Browse the repository at this point in the history
  • Loading branch information
jaekwon committed Dec 9, 2017
1 parent 1b04ab3 commit 6d19e9f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 27 deletions.
13 changes: 6 additions & 7 deletions node.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"golang.org/x/crypto/ripemd160"

"github.com/tendermint/go-wire"
cmn "github.com/tendermint/tmlibs/common"
)

// Node represents a node in a Tree.
Expand Down Expand Up @@ -102,7 +101,7 @@ func (node *Node) String() string {
// clone creates a shallow copy of a node with its hash set to nil.
func (node *Node) clone(version int64) *Node {
if node.isLeaf() {
cmn.PanicSanity("Attempt to copy a leaf node")
panic("Attempt to copy a leaf node")
}
return &Node{
key: node.key,
Expand Down Expand Up @@ -189,7 +188,7 @@ func (node *Node) _hash() []byte {
hasher := ripemd160.New()
buf := new(bytes.Buffer)
if _, err := node.writeHashBytes(buf); err != nil {
cmn.PanicCrisis(err)
panic(err)
}
hasher.Write(buf.Bytes())
node.hash = hasher.Sum(nil)
Expand All @@ -208,7 +207,7 @@ func (node *Node) hashWithCount() ([]byte, int64) {
buf := new(bytes.Buffer)
_, hashCount, err := node.writeHashBytesRecursively(buf)
if err != nil {
cmn.PanicCrisis(err)
panic(err)
}
hasher.Write(buf.Bytes())
node.hash = hasher.Sum(nil)
Expand All @@ -230,7 +229,7 @@ func (node *Node) writeHashBytes(w io.Writer) (n int, err error) {
wire.WriteByteSlice(node.value, w, &n, &err)
} else {
if node.leftHash == nil || node.rightHash == nil {
cmn.PanicSanity("Found an empty child hash")
panic("Found an empty child hash")
}
wire.WriteByteSlice(node.leftHash, w, &n, &err)
wire.WriteByteSlice(node.rightHash, w, &n, &err)
Expand Down Expand Up @@ -269,12 +268,12 @@ func (node *Node) writeBytes(w io.Writer) (n int, err error) {
wire.WriteByteSlice(node.value, w, &n, &err)
} else {
if node.leftHash == nil {
cmn.PanicSanity("node.leftHash was nil in writeBytes")
panic("node.leftHash was nil in writeBytes")
}
wire.WriteByteSlice(node.leftHash, w, &n, &err)

if node.rightHash == nil {
cmn.PanicSanity("node.rightHash was nil in writeBytes")
panic("node.rightHash was nil in writeBytes")
}
wire.WriteByteSlice(node.rightHash, w, &n, &err)
}
Expand Down
23 changes: 11 additions & 12 deletions nodedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"sort"
"sync"

cmn "github.com/tendermint/tmlibs/common"
dbm "github.com/tendermint/tmlibs/db"
)

Expand Down Expand Up @@ -73,12 +72,12 @@ func (ndb *nodeDB) GetNode(hash []byte) *Node {
// Doesn't exist, load.
buf := ndb.db.Get(ndb.nodeKey(hash))
if buf == nil {
cmn.PanicSanity(cmn.Fmt("Value missing for key %x", hash))
panic(fmt.Sprintf("Value missing for key %x", hash))
}

node, err := MakeNode(buf)
if err != nil {
cmn.PanicCrisis(cmn.Fmt("Error reading Node. bytes: %x, error: %v", buf, err))
panic(fmt.Sprintf("Error reading Node. bytes: %x, error: %v", buf, err))
}

node.hash = hash
Expand All @@ -94,16 +93,16 @@ func (ndb *nodeDB) SaveNode(node *Node) {
defer ndb.mtx.Unlock()

if node.hash == nil {
cmn.PanicSanity("Expected to find node.hash, but none found.")
panic("Expected to find node.hash, but none found.")
}
if node.persisted {
cmn.PanicSanity("Shouldn't be calling save on an already persisted node.")
panic("Shouldn't be calling save on an already persisted node.")
}

// Save node bytes to db.
buf := new(bytes.Buffer)
if _, err := node.writeBytes(buf); err != nil {
cmn.PanicCrisis(err)
panic(err)
}
ndb.batch.Set(ndb.nodeKey(node.hash), buf.Bytes())
debug("BATCH SAVE %X %p\n", node.hash, node)
Expand All @@ -119,7 +118,7 @@ func (ndb *nodeDB) Has(hash []byte) bool {
if ldb, ok := ndb.db.(*dbm.GoLevelDB); ok {
exists, err := ldb.DB().Has(key, nil)
if err != nil {
cmn.PanicSanity("Got error from leveldb: " + err.Error())
panic("Got error from leveldb: " + err.Error())
}
return exists
}
Expand Down Expand Up @@ -267,7 +266,7 @@ func (ndb *nodeDB) getPreviousVersion(version int64) int64 {
// deleteRoot deletes the root entry from disk, but not the node it points to.
func (ndb *nodeDB) deleteRoot(version int64) {
if version == ndb.getLatestVersion() {
cmn.PanicSanity("Tried to delete latest version")
panic("Tried to delete latest version")
}

key := ndb.rootKey(version)
Expand All @@ -294,7 +293,7 @@ func (ndb *nodeDB) traverse(fn func(key, value []byte)) {
fn(it.Key(), it.Value())
}
if err := it.GetError(); err != nil {
cmn.PanicSanity(err.Error())
panic(err)
}
}

Expand All @@ -307,7 +306,7 @@ func (ndb *nodeDB) traversePrefix(prefix []byte, fn func(k, v []byte)) {
fn(it.Key(), it.Value())
}
if err := it.GetError(); err != nil {
cmn.PanicSanity(err.Error())
panic(err)
}
}

Expand Down Expand Up @@ -355,7 +354,7 @@ func (ndb *nodeDB) getRoots() (map[int64][]byte, error) {
// loaded later.
func (ndb *nodeDB) SaveRoot(root *Node, version int64) error {
if len(root.hash) == 0 {
cmn.PanicSanity("Hash should not be empty")
panic("Hash should not be empty")
}
return ndb.saveRoot(root.hash, version)
}
Expand Down Expand Up @@ -432,7 +431,7 @@ func (ndb *nodeDB) traverseNodes(fn func(hash []byte, node *Node)) {
ndb.traversePrefix([]byte(nodePrefix), func(key, value []byte) {
node, err := MakeNode(value)
if err != nil {
cmn.PanicSanity("Couldn't decode node from database")
panic("Couldn't decode node from database")
}
fmt.Sscanf(string(key), nodeKeyFmt, &node.hash)
nodes = append(nodes, node)
Expand Down
4 changes: 1 addition & 3 deletions orphaning_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package iavl

import (
"fmt"

cmn "github.com/tendermint/tmlibs/common"
)

// orphaningTree is a tree which keeps track of orphaned nodes.
Expand Down Expand Up @@ -68,7 +66,7 @@ func (tree *orphaningTree) addOrphans(orphans []*Node) {
continue
}
if len(node.hash) == 0 {
cmn.PanicSanity("Expected to find node hash, but was empty")
panic("Expected to find node hash, but was empty")
}
tree.orphans[string(node.hash)] = node.version
}
Expand Down
5 changes: 2 additions & 3 deletions proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/tendermint/go-wire"
"github.com/tendermint/go-wire/data"
cmn "github.com/tendermint/tmlibs/common"
)

var (
Expand Down Expand Up @@ -55,7 +54,7 @@ func (branch proofInnerNode) Hash(childHash []byte) []byte {
wire.WriteByteSlice(childHash, buf, &n, &err)
}
if err != nil {
cmn.PanicCrisis(cmn.Fmt("Failed to hash proofInnerNode: %v", err))
panic(fmt.Sprintf("Failed to hash proofInnerNode: %v", err))
}
hasher.Write(buf.Bytes())

Expand All @@ -80,7 +79,7 @@ func (leaf proofLeafNode) Hash() []byte {
wire.WriteByteSlice(leaf.ValueBytes, buf, &n, &err)

if err != nil {
cmn.PanicCrisis(cmn.Fmt("Failed to hash proofLeafNode: %v", err))
panic(fmt.Sprintf("Failed to hash proofLeafNode: %v", err))
}
hasher.Write(buf.Bytes())

Expand Down
3 changes: 1 addition & 2 deletions tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"strings"

cmn "github.com/tendermint/tmlibs/common"
dbm "github.com/tendermint/tmlibs/db"

"github.com/pkg/errors"
Expand Down Expand Up @@ -90,7 +89,7 @@ func (t *Tree) Set(key []byte, value []byte) (updated bool) {

func (t *Tree) set(key []byte, value []byte) (orphaned []*Node, updated bool) {
if value == nil {
cmn.PanicSanity(cmn.Fmt("Attempt to store nil value at key '%s'", key))
panic(fmt.Sprintf("Attempt to store nil value at key '%s'", key))
}
if t.root == nil {
t.root = NewNode(key, value, t.version+1)
Expand Down

0 comments on commit 6d19e9f

Please sign in to comment.