From f373ba3583122f07611fec4037caf9a2dc913876 Mon Sep 17 00:00:00 2001 From: Dale Rahn Date: Thu, 17 Jul 2014 10:48:03 -0400 Subject: [PATCH] Introduce new error to indicate that block is not found vs db error. ok @davecgh --- db.go | 11 ++++++----- ldb/block.go | 5 ++++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/db.go b/db.go index 157f24ed..489d4767 100644 --- a/db.go +++ b/db.go @@ -13,11 +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") - DuplicateSha = errors.New("Duplicate insert attempted") - DbDoesNotExist = errors.New("Non-existent database") - DbUnknownType = errors.New("Non-existent database type") + 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") ) // AllShas is a special value that can be used as the final sha when requesting diff --git a/ldb/block.go b/ldb/block.go index 5e5ad56d..85588d16 100644 --- a/ldb/block.go +++ b/ldb/block.go @@ -76,6 +76,9 @@ 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 + } return 0, err } @@ -203,7 +206,7 @@ func (db *LevelDb) blkExistsSha(sha *btcwire.ShaHash) (bool, error) { switch err { case nil: return true, nil - case leveldb.ErrNotFound: + case leveldb.ErrNotFound, btcdb.BlockShaMissing: return false, nil } return false, err