Skip to content

Commit

Permalink
Merge "[FAB-5830] Replace panic by an error during simulation"
Browse files Browse the repository at this point in the history
  • Loading branch information
Srinivasan Muralidharan authored and Gerrit Code Review committed Aug 29, 2017
2 parents 4f844cd + 44a832a commit f22c3ac
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions core/ledger/kvledger/txmgmt/txmgr/lockbasedtxmgr/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ type queryHelper struct {
}

func (h *queryHelper) getState(ns string, key string) ([]byte, error) {
h.checkDone()
if err := h.checkDone(); err != nil {
return nil, err
}
versionedValue, err := h.txmgr.db.GetState(ns, key)
if err != nil {
return nil, err
Expand All @@ -50,7 +52,9 @@ func (h *queryHelper) getState(ns string, key string) ([]byte, error) {
}

func (h *queryHelper) getStateMultipleKeys(namespace string, keys []string) ([][]byte, error) {
h.checkDone()
if err := h.checkDone(); err != nil {
return nil, err
}
versionedValues, err := h.txmgr.db.GetStateMultipleKeys(namespace, keys)
if err != nil {
return nil, nil
Expand All @@ -67,7 +71,9 @@ func (h *queryHelper) getStateMultipleKeys(namespace string, keys []string) ([][
}

func (h *queryHelper) getStateRangeScanIterator(namespace string, startKey string, endKey string) (commonledger.ResultsIterator, error) {
h.checkDone()
if err := h.checkDone(); err != nil {
return nil, err
}
itr, err := newResultsItr(namespace, startKey, endKey, h.txmgr.db, h.rwsetBuilder,
ledgerconfig.IsQueryReadsHashingEnabled(), ledgerconfig.GetMaxDegreeQueryReadsHashing())
if err != nil {
Expand All @@ -78,7 +84,9 @@ func (h *queryHelper) getStateRangeScanIterator(namespace string, startKey strin
}

func (h *queryHelper) executeQuery(namespace, query string) (commonledger.ResultsIterator, error) {
h.checkDone()
if err := h.checkDone(); err != nil {
return nil, err
}
dbItr, err := h.txmgr.db.ExecuteQuery(namespace, query)
if err != nil {
return nil, err
Expand All @@ -87,7 +95,9 @@ func (h *queryHelper) executeQuery(namespace, query string) (commonledger.Result
}

func (h *queryHelper) getPrivateData(ns, coll, key string) ([]byte, error) {
h.checkDone()
if err := h.checkDone(); err != nil {
return nil, err
}
versionedValue, err := h.txmgr.db.GetPrivateData(ns, coll, key)
if err != nil {
return nil, err
Expand All @@ -100,7 +110,9 @@ func (h *queryHelper) getPrivateData(ns, coll, key string) ([]byte, error) {
}

func (h *queryHelper) getPrivateDataMultipleKeys(ns, coll string, keys []string) ([][]byte, error) {
h.checkDone()
if err := h.checkDone(); err != nil {
return nil, err
}
versionedValues, err := h.txmgr.db.GetPrivateDataMultipleKeys(ns, coll, keys)
if err != nil {
return nil, nil
Expand Down Expand Up @@ -157,10 +169,11 @@ func (h *queryHelper) done() {
}
}

func (h *queryHelper) checkDone() {
func (h *queryHelper) checkDone() error {
if h.doneInvoked {
panic("This instance should not be used after calling Done()")
return errors.New("This instance should not be used after calling Done()")
}
return nil
}

// resultsItr implements interface ledger.ResultsIterator
Expand Down

0 comments on commit f22c3ac

Please sign in to comment.