version-handler: Produce errors for unavailable data

We want to make it clear to the reader that the data is actually
unavailable vs reading outside the bounds of the data space.

Change-Id: Ifb63dfe600c268af9e7df24397c28e20316dbb8f
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/bmc/version-handler/test/version_read_unittest.cpp b/bmc/version-handler/test/version_read_unittest.cpp
index e621df8..a9f440e 100644
--- a/bmc/version-handler/test/version_read_unittest.cpp
+++ b/bmc/version-handler/test/version_read_unittest.cpp
@@ -94,7 +94,7 @@
     EXPECT_CALL(*tm.at("blob0"), trigger()).WillOnce(Return(true));
 
     EXPECT_TRUE(h->open(defaultSessionNumber, blobs::read, "blob0"));
-    EXPECT_THAT(h->read(defaultSessionNumber, 0, 10), IsEmpty());
+    EXPECT_THROW(h->read(defaultSessionNumber, 0, 10), std::runtime_error);
 }
 
 TEST_F(VersionReadBlobTest, VerifyTriggerFailureReadFails)
@@ -105,7 +105,7 @@
     EXPECT_CALL(*tm.at("blob0"), status())
         .WillOnce(Return(ActionStatus::failed));
     EXPECT_TRUE(h->open(defaultSessionNumber, blobs::read, "blob0"));
-    EXPECT_THAT(h->read(defaultSessionNumber, 0, 10), IsEmpty());
+    EXPECT_THROW(h->read(defaultSessionNumber, 0, 10), std::runtime_error);
 }
 
 TEST_F(VersionReadBlobTest, VerifyReadFailsOnFileOpenFailure)
@@ -118,7 +118,7 @@
     EXPECT_CALL(*im.at("blob0"), open(_, std::ios::in)).WillOnce(Return(false));
 
     EXPECT_TRUE(h->open(defaultSessionNumber, blobs::read, "blob0"));
-    EXPECT_THAT(h->read(defaultSessionNumber, 0, 10), IsEmpty());
+    EXPECT_THROW(h->read(defaultSessionNumber, 0, 10), std::runtime_error);
 }
 
 TEST_F(VersionReadBlobTest, VerifyReadFailsOnFileReadFailure)
@@ -133,7 +133,7 @@
     EXPECT_CALL(*im.at("blob0"), close()).Times(1);
 
     EXPECT_TRUE(h->open(defaultSessionNumber, blobs::read, "blob0"));
-    EXPECT_THAT(h->read(defaultSessionNumber, 0, 10), IsEmpty());
+    EXPECT_THROW(h->read(defaultSessionNumber, 0, 10), std::runtime_error);
 }
 
 } // namespace ipmi_flash
diff --git a/bmc/version-handler/version_handler.cpp b/bmc/version-handler/version_handler.cpp
index 0b77f80..7cccf62 100644
--- a/bmc/version-handler/version_handler.cpp
+++ b/bmc/version-handler/version_handler.cpp
@@ -118,7 +118,11 @@
                                               uint32_t requestedSize)
 {
     auto& data = sessionInfoMap.at(session)->data;
-    if (data == nullptr || !*data || (*data)->size() < offset)
+    if (data == nullptr || !*data)
+    {
+        throw std::runtime_error("Version data not ready for read");
+    }
+    if ((*data)->size() < offset)
     {
         return {};
     }