From 5e3ea588ccc31a5ab3a0b107600ab365bab5ceea Mon Sep 17 00:00:00 2001 From: NguyenNguyen Date: Thu, 27 Jun 2019 11:20:50 +0700 Subject: [PATCH] error-handling --- tomox/snapshot.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tomox/snapshot.go b/tomox/snapshot.go index 270606ecb425..4925dc1311c6 100644 --- a/tomox/snapshot.go +++ b/tomox/snapshot.go @@ -94,7 +94,7 @@ func prepareOrderTreeData(tree *OrderTree) (*OrderTreeSnapshot, error) { snap := new(OrderTreeSnapshot) serializedTree, err = EncodeBytesItem(tree.Item) if err != nil { - return snap, err + return nil, err } snap.OrderTreeItem = serializedTree @@ -104,7 +104,11 @@ func prepareOrderTreeData(tree *OrderTree) (*OrderTreeSnapshot, error) { priceKeyHash := common.BytesToHash(key) bytes, found := tree.PriceTree.Get(key) if found { - ol := tree.decodeOrderList(bytes) + var ol *OrderList + ol, err = tree.decodeOrderList(bytes) + if err != nil { + return nil, err + } // snapshot orderItems var ( items [][]byte @@ -113,11 +117,11 @@ func prepareOrderTreeData(tree *OrderTree) (*OrderTreeSnapshot, error) { for ol != nil && ol.Item != nil && ol.Item.Length > 0 { headOrder := ol.GetOrder(ol.Item.HeadOrder) if byteItem, err = EncodeBytesItem(headOrder.Item); err != nil { - return snap, err + return nil, err } items = append(items, byteItem) if err = ol.RemoveOrder(headOrder); err != nil { - return snap, err + return nil, err } }