change json::Source::load_file to produce a more descriptive exception message
authorJacob Lifshay <programmerjake@gmail.com>
Thu, 29 Jun 2017 07:25:39 +0000 (00:25 -0700)
committerJacob Lifshay <programmerjake@gmail.com>
Thu, 29 Jun 2017 07:25:39 +0000 (00:25 -0700)
src/json/source.cpp

index 833bee1d884784c66157899dde864892336f83a2..93e7eba66758ad72240b662ef8d90bd035dcabae 100644 (file)
@@ -102,8 +102,12 @@ Source Source::load_file(const util::filesystem::path &file_path)
 {
     // TODO: add code to use mmap
     std::ifstream is;
-    is.exceptions(std::ios::badbit | std::ios::failbit);
+    is.exceptions(std::ios::badbit);
     is.open(file_path);
+    if(!is)
+        throw util::filesystem::filesystem_error(
+            "open failed", file_path, std::make_error_code(std::io_errc::stream));
+    is.exceptions(std::ios::badbit | std::ios::failbit);
     std::vector<char> buffer;
     while(is.peek() != std::char_traits<char>::eof())
     {