From 166aa563ad41c4566c02cff583df612e328d1520 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 20 Jul 2015 20:42:52 +0200 Subject: Deal with non-existing index --- common/index.cpp | 4 ++++ common/index.h | 4 ++++ 2 files changed, 8 insertions(+) (limited to 'common') diff --git a/common/index.cpp b/common/index.cpp index 9bb467b..a8de697 100644 --- a/common/index.cpp +++ b/common/index.cpp @@ -17,6 +17,10 @@ void Index::add(const QByteArray &key, const QByteArray &value) void Index::lookup(const QByteArray &key, const std::function &resultHandler, const std::function &errorHandler) { + if (!mStorage.exists()) { + errorHandler(Error("index", IndexNotAvailable, "Index not existing")); + return; + } mStorage.scan(key, [this, resultHandler](void *keyPtr, int keySize, void *valuePtr, int valueSize) -> bool { resultHandler(QByteArray(static_cast(valuePtr), valueSize)); return true; diff --git a/common/index.h b/common/index.h index 3cd7cc8..08b499f 100644 --- a/common/index.h +++ b/common/index.h @@ -11,6 +11,10 @@ class Index { public: + enum ErrorCodes { + IndexNotAvailable = -1 + }; + class Error { public: -- cgit v1.2.3