]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Move exceptions.hpp to core
authorJoel Rosdahl <joel@rosdahl.net>
Mon, 19 Jul 2021 11:29:53 +0000 (13:29 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 20 Jul 2021 17:42:54 +0000 (19:42 +0200)
41 files changed:
src/Args.cpp
src/AtomicFile.cpp
src/CacheEntryReader.cpp
src/CacheEntryWriter.cpp
src/Compression.cpp
src/Config.cpp
src/Depfile.cpp
src/Logging.cpp
src/Manifest.cpp
src/NullCompressor.cpp
src/NullDecompressor.cpp
src/Result.cpp
src/ResultExtractor.cpp
src/ResultRetriever.cpp
src/Stat.cpp
src/Stat.hpp
src/Statistics.cpp
src/TemporaryFile.cpp
src/Util.cpp
src/Util.hpp
src/ZstdCompressor.cpp
src/ZstdDecompressor.cpp
src/argprocessing.cpp
src/ccache.cpp
src/compress.cpp
src/core/exceptions.hpp [moved from src/exceptions.hpp with 93% similarity]
src/execute.cpp
src/fmtmacros.hpp
src/hashutil.cpp
src/storage/Storage.cpp
src/storage/primary/PrimaryStorage.cpp
src/storage/secondary/FileStorage.cpp
src/storage/secondary/HttpStorage.cpp
src/storage/secondary/RedisStorage.cpp
src/storage/secondary/SecondaryStorage.hpp
src/util/file.cpp
src/util/string.cpp
unittest/TestUtil.cpp
unittest/test_Config.cpp
unittest/test_Stat.cpp
unittest/test_Util.cpp

index 85405f2efbba5480cfa35566dac4f87ada2c17c3..e918c6a481823c5662f2c31274abde9a83cf99bc 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "Util.hpp"
 
+#include <core/exceptions.hpp>
 #include <util/string.hpp>
 
 using nonstd::nullopt;
@@ -54,7 +55,7 @@ Args::from_gcc_atfile(const std::string& filename)
   std::string argtext;
   try {
     argtext = Util::read_file(filename);
-  } catch (Error&) {
+  } catch (core::Error&) {
     return nullopt;
   }
 
index d02679b40f5c3585a845999f086280948822fdaa..f85957379c2d4ad6a1301c836e52f1b3439a4253 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2019-2020 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -21,7 +21,8 @@
 #include "TemporaryFile.hpp"
 #include "Util.hpp"
 #include "assertions.hpp"
-#include "exceptions.hpp"
+
+#include <core/exceptions.hpp>
 
 AtomicFile::AtomicFile(const std::string& path, Mode mode) : m_path(path)
 {
@@ -43,7 +44,8 @@ void
 AtomicFile::write(const std::string& data)
 {
   if (fwrite(data.data(), data.size(), 1, m_stream) != 1) {
-    throw Error("failed to write data to {}: {}", m_path, strerror(errno));
+    throw core::Error(
+      "failed to write data to {}: {}", m_path, strerror(errno));
   }
 }
 
@@ -51,7 +53,8 @@ void
 AtomicFile::write(const std::vector<uint8_t>& data)
 {
   if (fwrite(data.data(), data.size(), 1, m_stream) != 1) {
-    throw Error("failed to write data to {}: {}", m_path, strerror(errno));
+    throw core::Error(
+      "failed to write data to {}: {}", m_path, strerror(errno));
   }
 }
 
@@ -63,7 +66,8 @@ AtomicFile::commit()
   m_stream = nullptr;
   if (result == EOF) {
     Util::unlink_tmp(m_tmp_path);
-    throw Error("failed to write data to {}: {}", m_path, strerror(errno));
+    throw core::Error(
+      "failed to write data to {}: {}", m_path, strerror(errno));
   }
   Util::rename(m_tmp_path, m_path);
 }
index 36dd3931ee210d9d62438d6b50c7a1f913ea3d0c..31bbd30998f6a9c594f5d5e76aa4fa7f067b712f 100644 (file)
 #include "CacheEntryReader.hpp"
 
 #include "Compressor.hpp"
-#include "exceptions.hpp"
 #include "fmtmacros.hpp"
 
+#include <core/exceptions.hpp>
+
 #include "third_party/fmt/core.h"
 
 CacheEntryReader::CacheEntryReader(FILE* stream,
@@ -30,7 +31,7 @@ CacheEntryReader::CacheEntryReader(FILE* stream,
 {
   uint8_t header_bytes[15];
   if (fread(header_bytes, sizeof(header_bytes), 1, stream) != 1) {
-    throw Error("Error reading header");
+    throw core::Error("Error reading header");
   }
 
   memcpy(m_magic, header_bytes, sizeof(m_magic));
@@ -40,14 +41,14 @@ CacheEntryReader::CacheEntryReader(FILE* stream,
   Util::big_endian_to_int(header_bytes + 7, m_content_size);
 
   if (memcmp(m_magic, expected_magic, sizeof(m_magic)) != 0) {
-    throw Error("Bad magic value 0x{:02x}{:02x}{:02x}{:02x}",
-                m_magic[0],
-                m_magic[1],
-                m_magic[2],
-                m_magic[3]);
+    throw core::Error("Bad magic value 0x{:02x}{:02x}{:02x}{:02x}",
+                      m_magic[0],
+                      m_magic[1],
+                      m_magic[2],
+                      m_magic[3]);
   }
   if (m_version != expected_version) {
-    throw Error(
+    throw core::Error(
       "Unknown version (actual {}, expected {})", m_version, expected_version);
   }
 
@@ -85,9 +86,10 @@ CacheEntryReader::finalize()
   Util::big_endian_to_int(buffer, expected_digest);
 
   if (actual_digest != expected_digest) {
-    throw Error("Incorrect checksum (actual 0x{:016x}, expected 0x{:016x})",
-                actual_digest,
-                expected_digest);
+    throw core::Error(
+      "Incorrect checksum (actual 0x{:016x}, expected 0x{:016x})",
+      actual_digest,
+      expected_digest);
   }
 
   m_decompressor->finalize();
index b9369476731b9344700434edab04f836e0e9ebf8..d29f7d446da94d9445cab20cb3a0c6d2d30b7331 100644 (file)
@@ -18,6 +18,8 @@
 
 #include "CacheEntryWriter.hpp"
 
+#include <core/exceptions.hpp>
+
 CacheEntryWriter::CacheEntryWriter(FILE* stream,
                                    const uint8_t* magic,
                                    uint8_t version,
@@ -37,7 +39,7 @@ CacheEntryWriter::CacheEntryWriter(FILE* stream,
   uint64_t content_size = 15 + payload_size + 8;
   Util::int_to_big_endian(content_size, header_bytes + 7);
   if (fwrite(header_bytes, sizeof(header_bytes), 1, stream) != 1) {
-    throw Error("Failed to write cache entry header");
+    throw core::Error("Failed to write cache entry header");
   }
   m_checksum.update(header_bytes, sizeof(header_bytes));
 }
index aa2a182719545932d0ca12c4e0f7b95fd15e0528..8b1ef00cfb21f06c710bef571f8347dab1c89c2a 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2019-2020 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -21,7 +21,8 @@
 #include "Config.hpp"
 #include "Context.hpp"
 #include "assertions.hpp"
-#include "exceptions.hpp"
+
+#include <core/exceptions.hpp>
 
 namespace Compression {
 
@@ -48,7 +49,7 @@ type_from_int(uint8_t type)
     return Type::zstd;
   }
 
-  throw Error("Unknown type: {}", type);
+  throw core::Error("Unknown type: {}", type);
 }
 
 std::string
index d9780e8c17d5635111714685402d7a7bbc524255..409a4a6e36f06692bfed7cd83f659edac3491892 100644 (file)
@@ -24,9 +24,9 @@
 #include "Sloppiness.hpp"
 #include "Util.hpp"
 #include "assertions.hpp"
-#include "exceptions.hpp"
 #include "fmtmacros.hpp"
 
+#include <core/exceptions.hpp>
 #include <core/wincompat.hpp>
 #include <util/expected.hpp>
 #include <util/path.hpp>
@@ -205,7 +205,7 @@ parse_bool(const std::string& value,
     std::string lower_value = Util::to_lowercase(value);
     if (value == "0" || lower_value == "false" || lower_value == "disable"
         || lower_value == "no") {
-      throw Error(
+      throw core::Error(
         "invalid boolean environment variable value \"{}\" (did you mean to"
         " set \"CCACHE_{}{}=true\"?)",
         value,
@@ -218,7 +218,7 @@ parse_bool(const std::string& value,
   } else if (value == "false") {
     return false;
   } else {
-    throw Error("not a boolean value: \"{}\"", value);
+    throw core::Error("not a boolean value: \"{}\"", value);
   }
 }
 
@@ -236,10 +236,10 @@ parse_double(const std::string& value)
   try {
     result = std::stod(value, &end);
   } catch (std::exception& e) {
-    throw Error(e.what());
+    throw core::Error(e.what());
   }
   if (end != value.size()) {
-    throw Error("invalid floating point: \"{}\"", value);
+    throw core::Error("invalid floating point: \"{}\"", value);
   }
   return result;
 }
@@ -365,7 +365,7 @@ void
 verify_absolute_path(const std::string& value)
 {
   if (!util::is_absolute_path(value)) {
-    throw Error("not an absolute path: \"{}\"", value);
+    throw core::Error("not an absolute path: \"{}\"", value);
   }
 }
 
@@ -417,11 +417,11 @@ parse_config_file(const std::string& path,
       std::string value;
       std::string error_message;
       if (!parse_line(line, &key, &value, &error_message)) {
-        throw Error(error_message);
+        throw core::Error(error_message);
       }
       config_line_handler(line, key, value);
-    } catch (const Error& e) {
-      throw Error("{}:{}: {}", path, line_number, e.what());
+    } catch (const core::Error& e) {
+      throw core::Error("{}:{}: {}", path, line_number, e.what());
     }
   }
   return true;
@@ -611,8 +611,8 @@ Config::update_from_environment()
 
     try {
       set_item(config_key, value, key, negate, "environment");
-    } catch (const Error& e) {
-      throw Error("CCACHE_{}{}: {}", negate ? "NO" : "", key, e.what());
+    } catch (const core::Error& e) {
+      throw core::Error("CCACHE_{}{}: {}", negate ? "NO" : "", key, e.what());
     }
   }
 }
@@ -622,7 +622,7 @@ Config::get_string_value(const std::string& key) const
 {
   auto it = k_config_key_table.find(key);
   if (it == k_config_key_table.end()) {
-    throw Error("unknown configuration option \"{}\"", key);
+    throw core::Error("unknown configuration option \"{}\"", key);
   }
 
   switch (it->second) {
@@ -756,7 +756,7 @@ Config::set_value_in_file(const std::string& path,
                           const std::string& value)
 {
   if (k_config_key_table.find(key) == k_config_key_table.end()) {
-    throw Error("unknown configuration option \"{}\"", key);
+    throw core::Error("unknown configuration option \"{}\"", key);
   }
 
   // Verify that the value is valid; set_item will throw if not.
@@ -769,8 +769,8 @@ Config::set_value_in_file(const std::string& path,
     Util::ensure_dir_exists(Util::dir_name(resolved_path));
     try {
       Util::write_file(resolved_path, "");
-    } catch (const Error& e) {
-      throw Error("failed to write to {}: {}", resolved_path, e.what());
+    } catch (const core::Error& e) {
+      throw core::Error("failed to write to {}: {}", resolved_path, e.what());
     }
   }
 
@@ -787,7 +787,7 @@ Config::set_value_in_file(const std::string& path,
             output.write(FMT("{}\n", c_line));
           }
         })) {
-    throw Error("failed to open {}: {}", path, strerror(errno));
+    throw core::Error("failed to open {}: {}", path, strerror(errno));
   }
 
   if (!found) {
@@ -861,7 +861,7 @@ Config::set_item(const std::string& key,
     break;
 
   case ConfigItem::compression_level:
-    m_compression_level = util::value_or_throw<Error>(
+    m_compression_level = util::value_or_throw<core::Error>(
       util::parse_signed(value, INT8_MIN, INT8_MAX, "compression_level"));
     break;
 
@@ -930,7 +930,7 @@ Config::set_item(const std::string& key,
     break;
 
   case ConfigItem::max_files:
-    m_max_files = util::value_or_throw<Error>(
+    m_max_files = util::value_or_throw<core::Error>(
       util::parse_unsigned(value, nullopt, nullopt, "max_files"));
     break;
 
@@ -995,7 +995,7 @@ Config::set_item(const std::string& key,
     if (!value.empty()) {
       const auto umask = util::parse_umask(value);
       if (!umask) {
-        throw Error(umask.error());
+        throw core::Error(umask.error());
       }
       m_umask = *umask;
     }
@@ -1010,7 +1010,7 @@ Config::check_key_tables_consistency()
 {
   for (const auto& item : k_env_variable_table) {
     if (k_config_key_table.find(item.second) == k_config_key_table.end()) {
-      throw Error(
+      throw core::Error(
         "env var {} mapped to {} which is missing from k_config_key_table",
         item.first,
         item.second);
index e1f7aabf22990340938d8721a62e567ffaec6426..5a13cc220b4ec50e0fa1725891697682e55455d5 100644 (file)
@@ -23,6 +23,7 @@
 #include "Logging.hpp"
 #include "assertions.hpp"
 
+#include <core/exceptions.hpp>
 #include <util/path.hpp>
 
 static inline bool
@@ -123,7 +124,7 @@ make_paths_relative_in_output_dep(const Context& ctx)
   std::string file_content;
   try {
     file_content = Util::read_file(output_dep);
-  } catch (const Error& e) {
+  } catch (const core::Error& e) {
     LOG("Cannot open dependency file {}: {}", output_dep, e.what());
     return;
   }
index 45a785a95f4cfde769954cfbb6c017c5fd46176c..4b41dff5483edd19a97cd22fdeecb3f83a9c66a7 100644 (file)
@@ -23,7 +23,6 @@
 #include "File.hpp"
 #include "Util.hpp"
 #include "Win32Util.hpp"
-#include "exceptions.hpp"
 #include "execute.hpp"
 #include "fmtmacros.hpp"
 
index d0eac687cf08e16462293b2d0d841628783710b7..9fd4fd8f66f058d7ed9dc9d0594f5c86828ad8de 100644 (file)
@@ -32,6 +32,8 @@
 #include "fmtmacros.hpp"
 #include "hashutil.hpp"
 
+#include <core/exceptions.hpp>
+
 #include <memory>
 
 // Manifest data format
@@ -512,7 +514,7 @@ get(const Context& ctx, const std::string& path)
       LOG_RAW("No such manifest file");
       return nullopt;
     }
-  } catch (const Error& e) {
+  } catch (const core::Error& e) {
     LOG("Error: {}", e.what());
     return nullopt;
   }
@@ -553,7 +555,7 @@ put(const Config& config,
       // Manifest file didn't exist.
       mf = std::make_unique<ManifestData>();
     }
-  } catch (const Error& e) {
+  } catch (const core::Error& e) {
     LOG("Error: {}", e.what());
     // Manifest file was corrupt, ignore.
     mf = std::make_unique<ManifestData>();
@@ -589,7 +591,7 @@ put(const Config& config,
     try {
       write_manifest(config, path, *mf);
       return true;
-    } catch (const Error& e) {
+    } catch (const core::Error& e) {
       LOG("Error: {}", e.what());
     }
   } else {
@@ -604,7 +606,7 @@ dump(const std::string& path, FILE* stream)
   std::unique_ptr<ManifestData> mf;
   try {
     mf = read_manifest(path, stream);
-  } catch (const Error& e) {
+  } catch (const core::Error& e) {
     PRINT(stream, "Error: {}\n", e.what());
     return false;
   }
index 13494fcb95c414980f54acff284f2f02bee6ce21..b51d84d18d04b2a62648823ab43d03d618cb1184 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2019-2020 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -18,7 +18,7 @@
 
 #include "NullCompressor.hpp"
 
-#include "exceptions.hpp"
+#include <core/exceptions.hpp>
 
 NullCompressor::NullCompressor(FILE* stream) : m_stream(stream)
 {
@@ -34,7 +34,7 @@ void
 NullCompressor::write(const void* data, size_t count)
 {
   if (fwrite(data, 1, count, m_stream) != count) {
-    throw Error("failed to write to uncompressed stream");
+    throw core::Error("failed to write to uncompressed stream");
   }
 }
 
@@ -42,6 +42,6 @@ void
 NullCompressor::finalize()
 {
   if (fflush(m_stream) != 0) {
-    throw Error("failed to finalize uncompressed stream");
+    throw core::Error("failed to finalize uncompressed stream");
   }
 }
index 090bdf5d1fad749f3eabe9f52277294f4a925d9b..bcb1c69df119685a0ab94fb42275493521f601aa 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2019 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -18,7 +18,7 @@
 
 #include "NullDecompressor.hpp"
 
-#include "exceptions.hpp"
+#include <core/exceptions.hpp>
 
 NullDecompressor::NullDecompressor(FILE* stream) : m_stream(stream)
 {
@@ -28,7 +28,7 @@ void
 NullDecompressor::read(void* data, size_t count)
 {
   if (fread(data, count, 1, m_stream) != 1) {
-    throw Error("failed to read from uncompressed stream");
+    throw core::Error("failed to read from uncompressed stream");
   }
 }
 
@@ -36,6 +36,6 @@ void
 NullDecompressor::finalize()
 {
   if (fgetc(m_stream) != EOF) {
-    throw Error("garbage data at end of uncompressed stream");
+    throw core::Error("garbage data at end of uncompressed stream");
   }
 }
index 4d541ffef873c9a9f31ed67f166ed9ee67f932be..e4867c675a1fedf77934884363191ead4f2d1ced 100644 (file)
@@ -29,9 +29,9 @@
 #include "Stat.hpp"
 #include "Statistic.hpp"
 #include "Util.hpp"
-#include "exceptions.hpp"
 #include "fmtmacros.hpp"
 
+#include <core/exceptions.hpp>
 #include <core/wincompat.hpp>
 #include <util/path.hpp>
 
@@ -231,7 +231,7 @@ Result::Reader::read(Consumer& consumer)
     } else {
       return "No such result file";
     }
-  } catch (const Error& e) {
+  } catch (const core::Error& e) {
     return e.what();
   }
 }
@@ -265,7 +265,7 @@ Reader::read_result(Consumer& consumer)
   }
 
   if (i != n_entries) {
-    throw Error("Too few entries (read {}, expected {})", i, n_entries);
+    throw core::Error("Too few entries (read {}, expected {})", i, n_entries);
   }
 
   cache_entry_reader.finalize();
@@ -286,7 +286,7 @@ Reader::read_entry(CacheEntryReader& cache_entry_reader,
     break;
 
   default:
-    throw Error("Unknown entry type: {}", marker);
+    throw core::Error("Unknown entry type: {}", marker);
   }
 
   UnderlyingFileTypeInt type;
@@ -313,10 +313,11 @@ Reader::read_entry(CacheEntryReader& cache_entry_reader,
     auto raw_path = get_raw_file_path(m_result_path, entry_number);
     auto st = Stat::stat(raw_path, Stat::OnError::throw_error);
     if (st.size() != file_len) {
-      throw Error("Bad file size of {} (actual {} bytes, expected {} bytes)",
-                  raw_path,
-                  st.size(),
-                  file_len);
+      throw core::Error(
+        "Bad file size of {} (actual {} bytes, expected {} bytes)",
+        raw_path,
+        st.size(),
+        file_len);
     }
 
     consumer.on_entry_start(entry_number, file_type, file_len, raw_path);
@@ -342,7 +343,7 @@ Writer::finalize()
 {
   try {
     return do_finalize();
-  } catch (const Error& e) {
+  } catch (const core::Error& e) {
     return nonstd::make_unexpected(e.what());
   }
 }
@@ -416,7 +417,7 @@ Result::Writer::write_embedded_file_entry(CacheEntryWriter& writer,
 {
   Fd file(open(path.c_str(), O_RDONLY | O_BINARY));
   if (!file) {
-    throw Error("Failed to open {} for reading", path);
+    throw core::Error("Failed to open {} for reading", path);
   }
 
   uint64_t remain = file_size;
@@ -428,10 +429,10 @@ Result::Writer::write_embedded_file_entry(CacheEntryWriter& writer,
       if (errno == EINTR) {
         continue;
       }
-      throw Error("Error reading from {}: {}", path, strerror(errno));
+      throw core::Error("Error reading from {}: {}", path, strerror(errno));
     }
     if (bytes_read == 0) {
-      throw Error("Error reading from {}: end of file", path);
+      throw core::Error("Error reading from {}: end of file", path);
     }
     writer.write(buf, bytes_read);
     remain -= bytes_read;
@@ -446,8 +447,8 @@ Result::Writer::write_raw_file_entry(const std::string& path,
   const auto old_stat = Stat::stat(raw_file);
   try {
     Util::clone_hard_link_or_copy_file(m_ctx, path, raw_file, true);
-  } catch (Error& e) {
-    throw Error(
+  } catch (core::Error& e) {
+    throw core::Error(
       "Failed to store {} as raw file {}: {}", path, raw_file, e.what());
   }
   const auto new_stat = Stat::stat(raw_file);
index b46f3000c6f8598f26d043fce31ccb6f0fa02016..077f324426f084152e0bb1dfce69d9747b67478d 100644 (file)
@@ -21,6 +21,7 @@
 #include "Util.hpp"
 #include "fmtmacros.hpp"
 
+#include <core/exceptions.hpp>
 #include <core/wincompat.hpp>
 
 #include <fcntl.h>
@@ -57,14 +58,14 @@ ResultExtractor::on_entry_start(uint32_t /*entry_number*/,
     m_dest_fd = Fd(
       open(m_dest_path.c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666));
     if (!m_dest_fd) {
-      throw Error(
+      throw core::Error(
         "Failed to open {} for writing: {}", m_dest_path, strerror(errno));
     }
   } else {
     try {
       Util::copy_file(*raw_file, m_dest_path, false);
-    } catch (Error& e) {
-      throw Error(
+    } catch (core::Error& e) {
+      throw core::Error(
         "Failed to copy {} to {}: {}", *raw_file, m_dest_path, e.what());
     }
   }
@@ -77,8 +78,8 @@ ResultExtractor::on_entry_data(const uint8_t* data, size_t size)
 
   try {
     Util::write_fd(*m_dest_fd, data, size);
-  } catch (Error& e) {
-    throw Error("Failed to write to {}: {}", m_dest_path, e.what());
+  } catch (core::Error& e) {
+    throw core::Error("Failed to write to {}: {}", m_dest_path, e.what());
   }
 }
 
index 9eff7125abefea5b7a5b77b0505ae8d44af22749..06dab86866dfa7c888f8b6ce6a67b4b72b4262e4 100644 (file)
@@ -22,6 +22,7 @@
 #include "Depfile.hpp"
 #include "Logging.hpp"
 
+#include <core/exceptions.hpp>
 #include <core/wincompat.hpp>
 
 #include <fcntl.h>
@@ -129,7 +130,7 @@ ResultRetriever::on_entry_start(uint32_t entry_number,
     m_dest_fd = Fd(
       open(dest_path.c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666));
     if (!m_dest_fd) {
-      throw Error(
+      throw core::Error(
         "Failed to open {} for writing: {}", dest_path, strerror(errno));
     }
     m_dest_path = dest_path;
@@ -147,8 +148,8 @@ ResultRetriever::on_entry_data(const uint8_t* data, size_t size)
   } else if (m_dest_fd) {
     try {
       Util::write_fd(*m_dest_fd, data, size);
-    } catch (Error& e) {
-      throw Error("Failed to write to {}: {}", m_dest_path, e.what());
+    } catch (core::Error& e) {
+      throw core::Error("Failed to write to {}: {}", m_dest_path, e.what());
     }
   }
 }
@@ -189,7 +190,7 @@ ResultRetriever::write_dependency_file()
     Util::write_fd(*m_dest_fd,
                    m_dest_data.data() + start_pos,
                    m_dest_data.length() - start_pos);
-  } catch (Error& e) {
-    throw Error("Failed to write to {}: {}", m_dest_path, e.what());
+  } catch (core::Error& e) {
+    throw core::Error("Failed to write to {}: {}", m_dest_path, e.what());
   }
 }
index ffd11843d4e3e55a427c0f89c40c4792f9f34eb3..6e8d44eb9acc46451a4bfc3fe4b4f6c96f2aa923 100644 (file)
@@ -22,6 +22,7 @@
 #include "Logging.hpp"
 #include "Win32Util.hpp"
 
+#include <core/exceptions.hpp>
 #include <core/wincompat.hpp>
 
 #ifdef _WIN32
@@ -211,7 +212,7 @@ Stat::Stat(StatFunction stat_function,
   } else {
     m_errno = errno;
     if (on_error == OnError::throw_error) {
-      throw Error("failed to stat {}: {}", path, strerror(errno));
+      throw core::Error("failed to stat {}: {}", path, strerror(errno));
     }
     if (on_error == OnError::log) {
       LOG("Failed to stat {}: {}", path, strerror(errno));
index 9cf9a210b5b91fe33e09d9640ff02c0216037ce9..b6e84e0da3c321f7d9454eaac6c483da0b11ecb4 100644 (file)
 
 #pragma once
 
-#include "exceptions.hpp"
+#include <core/wincompat.hpp>
 
 #include <sys/stat.h>
 #include <sys/types.h>
 
+#include <ctime>
 #include <string>
 
 #ifdef _WIN32
index cfba041ab3a681b6984a3335446d0c3632a73a8a..c454ff744bd6ca7931ee431f35fdc02c62c17ffb 100644 (file)
 #include "Logging.hpp"
 #include "Util.hpp"
 #include "assertions.hpp"
-#include "exceptions.hpp"
 #include "fmtmacros.hpp"
 
+#include <core/exceptions.hpp>
+
 #include <fstream>
 #include <unordered_map>
 
@@ -202,7 +203,7 @@ read(const std::string& path)
   std::string data;
   try {
     data = Util::read_file(path);
-  } catch (const Error&) {
+  } catch (const core::Error&) {
     // Ignore.
     return counters;
   }
@@ -270,7 +271,7 @@ update(const std::string& path,
   }
   try {
     file.commit();
-  } catch (const Error& e) {
+  } catch (const core::Error& e) {
     // Make failure to write a stats file a soft error since it's not
     // important enough to fail whole the process and also because it is
     // called in the Context destructor.
index feaa5f18236c1d0cb9c7cd1e57e01ac93e01a1bc..8c9e3868d694a0cdc1d6ac3d9bdb5958ca198f9e 100644 (file)
@@ -20,6 +20,8 @@
 
 #include "Util.hpp"
 
+#include <core/exceptions.hpp>
+
 #ifdef _WIN32
 #  include "third_party/win32/mktemp.h"
 #endif
@@ -61,7 +63,7 @@ TemporaryFile::TemporaryFile(string_view path_prefix)
   fd = Fd(mkstemp(&path[0]));
 #endif
   if (!fd) {
-    throw Fatal(
+    throw core::Fatal(
       "Failed to create temporary file for {}: {}", path, strerror(errno));
   }
 
index ab0041da83710fa5ec65b46fa316896b9ba3bc2a..2e3c210accf4520da75a9fd14873790a9a4a3dec 100644 (file)
 #include "Config.hpp"
 #include "Context.hpp"
 #include "Fd.hpp"
-#include "FormatNonstdStringView.hpp"
 #include "Logging.hpp"
 #include "TemporaryFile.hpp"
 #include "Win32Util.hpp"
 #include "fmtmacros.hpp"
 
+#include <core/exceptions.hpp>
 #include <core/wincompat.hpp>
 #include <util/path.hpp>
 #include <util/string.hpp>
@@ -236,7 +236,7 @@ clone_file(const std::string& src, const std::string& dest, bool via_tmp_file)
 #  if defined(__linux__)
   Fd src_fd(open(src.c_str(), O_RDONLY));
   if (!src_fd) {
-    throw Error("{}: {}", src, strerror(errno));
+    throw core::Error("{}: {}", src, strerror(errno));
   }
 
   Fd dest_fd;
@@ -249,12 +249,12 @@ clone_file(const std::string& src, const std::string& dest, bool via_tmp_file)
     dest_fd =
       Fd(open(dest.c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666));
     if (!dest_fd) {
-      throw Error("{}: {}", src, strerror(errno));
+      throw core::Error("{}: {}", src, strerror(errno));
     }
   }
 
   if (ioctl(*dest_fd, FICLONE, *src_fd) != 0) {
-    throw Error(strerror(errno));
+    throw core::Error(strerror(errno));
   }
 
   dest_fd.close();
@@ -266,13 +266,13 @@ clone_file(const std::string& src, const std::string& dest, bool via_tmp_file)
 #  elif defined(__APPLE__)
   (void)via_tmp_file;
   if (clonefile(src.c_str(), dest.c_str(), CLONE_NOOWNERCOPY) != 0) {
-    throw Error(strerror(errno));
+    throw core::Error(strerror(errno));
   }
 #  else
   (void)src;
   (void)dest;
   (void)via_tmp_file;
-  throw Error(strerror(EOPNOTSUPP));
+  throw core::Error(strerror(EOPNOTSUPP));
 #  endif
 }
 #endif // FILE_CLONING_SUPPORTED
@@ -289,7 +289,7 @@ clone_hard_link_or_copy_file(const Context& ctx,
     try {
       clone_file(source, dest, via_tmp_file);
       return;
-    } catch (Error& e) {
+    } catch (core::Error& e) {
       LOG("Failed to clone: {}", e.what());
     }
 #else
@@ -304,7 +304,7 @@ clone_hard_link_or_copy_file(const Context& ctx,
         LOG("Failed to chmod: {}", strerror(errno));
       }
       return;
-    } catch (const Error& e) {
+    } catch (const core::Error& e) {
       LOG_RAW(e.what());
       // Fall back to copying.
     }
@@ -356,7 +356,7 @@ copy_file(const std::string& src, const std::string& dest, bool via_tmp_file)
 {
   Fd src_fd(open(src.c_str(), O_RDONLY));
   if (!src_fd) {
-    throw Error("{}: {}", src, strerror(errno));
+    throw core::Error("{}: {}", src, strerror(errno));
   }
 
   Fd dest_fd;
@@ -369,7 +369,7 @@ copy_file(const std::string& src, const std::string& dest, bool via_tmp_file)
     dest_fd =
       Fd(open(dest.c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666));
     if (!dest_fd) {
-      throw Error("{}: {}", dest, strerror(errno));
+      throw core::Error("{}: {}", dest, strerror(errno));
     }
   }
 
@@ -455,7 +455,7 @@ expand_environment_variables(const std::string& str)
         ++right;
       }
       if (curly && *right != '}') {
-        throw Error("syntax error: missing '}}' after \"{}\"", left);
+        throw core::Error("syntax error: missing '}}' after \"{}\"", left);
       }
       if (right == left) {
         // Special case: don't consider a single $ the left of a variable.
@@ -465,7 +465,7 @@ expand_environment_variables(const std::string& str)
         std::string name(left, right - left);
         const char* value = getenv(name.c_str());
         if (!value) {
-          throw Error("environment variable \"{}\" not set", name);
+          throw core::Error("environment variable \"{}\" not set", name);
         }
         result += value;
         if (!curly) {
@@ -505,7 +505,7 @@ fallocate(int fd, long new_size)
   int err = 0;
   try {
     write_fd(fd, buf, bytes_to_write);
-  } catch (Error&) {
+  } catch (core::Error&) {
     err = errno;
   }
   lseek(fd, saved_pos, SEEK_SET);
@@ -596,7 +596,8 @@ void
 ensure_dir_exists(nonstd::string_view dir)
 {
   if (!create_dir(dir)) {
-    throw Fatal("Failed to create directory {}: {}", dir, strerror(errno));
+    throw core::Fatal(
+      "Failed to create directory {}: {}", dir, strerror(errno));
   }
 }
 
@@ -713,7 +714,8 @@ get_home_directory()
     }
   }
 #endif
-  throw Fatal("Could not determine home directory from $HOME or getpwuid(3)");
+  throw core::Fatal(
+    "Could not determine home directory from $HOME or getpwuid(3)");
 }
 
 const char*
@@ -786,16 +788,16 @@ hard_link(const std::string& oldpath, const std::string& newpath)
 
 #ifndef _WIN32
   if (link(oldpath.c_str(), newpath.c_str()) != 0) {
-    throw Error(
+    throw core::Error(
       "failed to link {} to {}: {}", oldpath, newpath, strerror(errno));
   }
 #else
   if (!CreateHardLink(newpath.c_str(), oldpath.c_str(), nullptr)) {
     DWORD error = GetLastError();
-    throw Error("failed to link {} to {}: {}",
-                oldpath,
-                newpath,
-                Win32Util::error_message(error));
+    throw core::Error("failed to link {} to {}: {}",
+                      oldpath,
+                      newpath,
+                      Win32Util::error_message(error));
   }
 #endif
 }
@@ -1002,8 +1004,8 @@ parse_duration(const std::string& duration)
     factor = 1;
     break;
   default:
-    throw Error("invalid suffix (supported: d (day) and s (second)): \"{}\"",
-                duration);
+    throw core::Error(
+      "invalid suffix (supported: d (day) and s (second)): \"{}\"", duration);
   }
 
   const auto value =
@@ -1011,7 +1013,7 @@ parse_duration(const std::string& duration)
   if (value) {
     return factor * *value;
   } else {
-    throw Error(value.error());
+    throw core::Error(value.error());
   }
 }
 
@@ -1023,7 +1025,7 @@ parse_size(const std::string& value)
   char* p;
   double result = strtod(value.c_str(), &p);
   if (errno != 0 || result < 0 || p == value.c_str() || value.empty()) {
-    throw Error("invalid size: \"{}\"", value);
+    throw core::Error("invalid size: \"{}\"", value);
   }
 
   while (isspace(*p)) {
@@ -1047,7 +1049,7 @@ parse_size(const std::string& value)
       result *= multiplier;
       break;
     default:
-      throw Error("invalid size: \"{}\"", value);
+      throw core::Error("invalid size: \"{}\"", value);
     }
   } else {
     // Default suffix: G.
@@ -1078,7 +1080,7 @@ read_file(const std::string& path, size_t size_hint)
   if (size_hint == 0) {
     auto stat = Stat::stat(path);
     if (!stat) {
-      throw Error(strerror(errno));
+      throw core::Error(strerror(errno));
     }
     size_hint = stat.size();
   }
@@ -1088,7 +1090,7 @@ read_file(const std::string& path, size_t size_hint)
 
   Fd fd(open(path.c_str(), O_RDONLY | O_BINARY));
   if (!fd) {
-    throw Error(strerror(errno));
+    throw core::Error(strerror(errno));
   }
 
   ssize_t ret = 0;
@@ -1115,7 +1117,7 @@ read_file(const std::string& path, size_t size_hint)
 
   if (ret == -1) {
     LOG("Failed reading {}", path);
-    throw Error(strerror(errno));
+    throw core::Error(strerror(errno));
   }
 
   result.resize(pos);
@@ -1189,7 +1191,7 @@ rename(const std::string& oldpath, const std::string& newpath)
 {
 #ifndef _WIN32
   if (::rename(oldpath.c_str(), newpath.c_str()) != 0) {
-    throw Error(
+    throw core::Error(
       "failed to rename {} to {}: {}", oldpath, newpath, strerror(errno));
   }
 #else
@@ -1198,10 +1200,10 @@ rename(const std::string& oldpath, const std::string& newpath)
   if (!MoveFileExA(
         oldpath.c_str(), newpath.c_str(), MOVEFILE_REPLACE_EXISTING)) {
     DWORD error = GetLastError();
-    throw Error("failed to rename {} to {}: {}",
-                oldpath,
-                newpath,
-                Win32Util::error_message(error));
+    throw core::Error("failed to rename {} to {}: {}",
+                      oldpath,
+                      newpath,
+                      Win32Util::error_message(error));
   }
 #endif
 }
@@ -1229,7 +1231,7 @@ send_to_stderr(const Context& ctx, const std::string& text)
     try {
       modified_text = strip_ansi_csi_seqs(text);
       text_to_send = &modified_text;
-    } catch (const Error&) {
+    } catch (const core::Error&) {
       // Fall through
     }
   }
@@ -1241,8 +1243,8 @@ send_to_stderr(const Context& ctx, const std::string& text)
 
   try {
     write_fd(STDERR_FILENO, text_to_send->data(), text_to_send->length());
-  } catch (Error& e) {
-    throw Error("Failed to write to stderr: {}", e.what());
+  } catch (core::Error& e) {
+    throw core::Error("Failed to write to stderr: {}", e.what());
   }
 }
 
@@ -1345,9 +1347,9 @@ traverse(const std::string& path, const TraverseVisitor& visitor)
           if (stat.error_number() == ENOENT || stat.error_number() == ESTALE) {
             continue;
           }
-          throw Error("failed to lstat {}: {}",
-                      entry_path,
-                      strerror(stat.error_number()));
+          throw core::Error("failed to lstat {}: {}",
+                            entry_path,
+                            strerror(stat.error_number()));
         }
         is_dir = stat.is_directory();
       }
@@ -1362,7 +1364,7 @@ traverse(const std::string& path, const TraverseVisitor& visitor)
   } else if (errno == ENOTDIR) {
     visitor(path, false);
   } else {
-    throw Error("failed to open directory {}: {}", path, strerror(errno));
+    throw core::Error("failed to open directory {}: {}", path, strerror(errno));
   }
 }
 
@@ -1385,7 +1387,7 @@ traverse(const std::string& path, const TraverseVisitor& visitor)
   } else if (std::filesystem::exists(path)) {
     visitor(path, false);
   } else {
-    throw Error("failed to open directory {}: {}", path, strerror(errno));
+    throw core::Error("failed to open directory {}: {}", path, strerror(errno));
   }
 }
 
@@ -1404,7 +1406,7 @@ unlink_safe(const std::string& path, UnlinkLog unlink_log)
   bool success = true;
   try {
     Util::rename(path, tmp_name);
-  } catch (Error&) {
+  } catch (core::Error&) {
     success = false;
     saved_errno = errno;
   }
@@ -1474,10 +1476,10 @@ wipe_path(const std::string& path)
   traverse(path, [](const std::string& p, bool is_dir) {
     if (is_dir) {
       if (rmdir(p.c_str()) != 0 && errno != ENOENT && errno != ESTALE) {
-        throw Error("failed to rmdir {}: {}", p, strerror(errno));
+        throw core::Error("failed to rmdir {}: {}", p, strerror(errno));
       }
     } else if (unlink(p.c_str()) != 0 && errno != ENOENT && errno != ESTALE) {
-      throw Error("failed to unlink {}: {}", p, strerror(errno));
+      throw core::Error("failed to unlink {}: {}", p, strerror(errno));
     }
   });
 }
@@ -1491,7 +1493,7 @@ write_fd(int fd, const void* data, size_t size)
       write(fd, static_cast<const uint8_t*>(data) + written, size - written);
     if (count == -1) {
       if (errno != EAGAIN && errno != EINTR) {
-        throw Error(strerror(errno));
+        throw core::Error(strerror(errno));
       }
     } else {
       written += count;
@@ -1505,13 +1507,13 @@ write_file(const std::string& path,
            std::ios_base::openmode open_mode)
 {
   if (path.empty()) {
-    throw Error("No such file or directory");
+    throw core::Error("No such file or directory");
   }
 
   open_mode |= std::ios::out;
   std::ofstream file(path, open_mode);
   if (!file) {
-    throw Error(strerror(errno));
+    throw core::Error(strerror(errno));
   }
   file << data;
 }
index 06ea153b49225bcf97cf0152f985a6107e8b518b..42c2e52395b4d7c272dd8fd2d991e18ac7606f13 100644 (file)
@@ -94,14 +94,15 @@ clamp(T value, T min, T max)
 }
 
 // Clone a file from `src` to `dest`. If `via_tmp_file` is true, `src` is cloned
-// to a temporary file and then renamed to `dest`. Throws `Error` on error.
+// to a temporary file and then renamed to `dest`. Throws `core::Error` on
+// error.
 void clone_file(const std::string& src,
                 const std::string& dest,
                 bool via_tmp_file = false);
 
 // Clone, hard link or copy a file from `source` to `dest` depending on settings
 // in `ctx`. If cloning or hard linking cannot and should not be done the file
-// will be copied instead. Throws `Error` on error.
+// will be copied instead. Throws `core::Error` on error.
 void clone_hard_link_or_copy_file(const Context& ctx,
                                   const std::string& source,
                                   const std::string& dest,
@@ -112,11 +113,11 @@ void clone_hard_link_or_copy_file(const Context& ctx,
 size_t common_dir_prefix_length(nonstd::string_view dir,
                                 nonstd::string_view path);
 
-// Copy all data from `fd_in` to `fd_out`. Throws `Error` on error.
+// Copy all data from `fd_in` to `fd_out`. Throws `core::Error` on error.
 void copy_fd(int fd_in, int fd_out);
 
 // Copy a file from `src` to `dest`. If via_tmp_file is true, `src` is copied to
-// a temporary file and then renamed to dest. Throws `Error` on error.
+// a temporary file and then renamed to dest. Throws `core::Error` on error.
 void copy_file(const std::string& src,
                const std::string& dest,
                bool via_tmp_file = false);
@@ -133,7 +134,7 @@ nonstd::string_view dir_name(nonstd::string_view path);
 void ensure_dir_exists(nonstd::string_view dir);
 
 // Expand all instances of $VAR or ${VAR}, where VAR is an environment variable,
-// in `str`. Throws `Error` if one of the environment variables.
+// in `str`. Throws `core::Error` if one of the environment variables.
 [[nodiscard]] std::string expand_environment_variables(const std::string& str);
 
 // Extends file size to at least new_size by calling posix_fallocate() if
@@ -220,7 +221,7 @@ const char* get_hostname();
 std::string get_relative_path(nonstd::string_view dir,
                               nonstd::string_view path);
 
-// Hard-link `oldpath` to `newpath`. Throws `Error` on error.
+// Hard-link `oldpath` to `newpath`. Throws `core::Error` on error.
 void hard_link(const std::string& oldpath, const std::string& newpath);
 
 // Write bytes in big endian order from an integer value.
@@ -305,12 +306,12 @@ bool matches_dir_prefix_or_file(nonstd::string_view dir_prefix_or_file,
 std::string normalize_absolute_path(nonstd::string_view path);
 
 // Parse `duration`, an unsigned integer with d (days) or s (seconds) suffix,
-// into seconds. Throws `Error` on error.
+// into seconds. Throws `core::Error` on error.
 uint64_t parse_duration(const std::string& duration);
 
 // Parse a "size value", i.e. a string that can end in k, M, G, T (10-based
 // suffixes) or Ki, Mi, Gi, Ti (2-based suffixes). For backward compatibility, K
-// is also recognized as a synonym of k. Throws `Error` on parse error.
+// is also recognized as a synonym of k. Throws `core::Error` on parse error.
 uint64_t parse_size(const std::string& value);
 
 // Read data from `fd` until end of file and call `data_receiver` with the read
@@ -321,8 +322,8 @@ bool read_fd(int fd, DataReceiver data_receiver);
 // Return `path`'s content as a string. If `size_hint` is not 0 then assume that
 // `path` has this size (this saves system calls).
 //
-// Throws `Error` on error. The description contains the error message without
-// the path.
+// Throws `core::Error` on error. The description contains the error message
+// without the path.
 std::string read_file(const std::string& path, size_t size_hint = 0);
 
 #ifndef _WIN32
@@ -340,7 +341,8 @@ std::string real_path(const std::string& path,
 // extension as determined by `get_extension()`.
 nonstd::string_view remove_extension(nonstd::string_view path);
 
-// Rename `oldpath` to `newpath` (deleting `newpath`). Throws `Error` on error.
+// Rename `oldpath` to `newpath` (deleting `newpath`). Throws `core::Error` on
+// error.
 void rename(const std::string& oldpath, const std::string& newpath);
 
 // Detmine if `program_name` is equal to `canonical_program_name`. On Windows,
@@ -351,8 +353,8 @@ bool same_program_name(nonstd::string_view program_name,
 
 // Send `text` to STDERR_FILENO, optionally stripping ANSI color sequences if
 // `ctx.args_info.strip_diagnostics_colors` is true and rewriting paths to
-// absolute if `ctx.config.absolute_paths_in_stderr` is true. Throws `Error` on
-// error.
+// absolute if `ctx.config.absolute_paths_in_stderr` is true. Throws
+// `core::Error` on error.
 void send_to_stderr(const Context& ctx, const std::string& text);
 
 // Set the FD_CLOEXEC on file descriptor `fd`. This is a NOP on Windows.
@@ -393,7 +395,7 @@ std::vector<std::string> split_into_strings(
 // Traverse `path` recursively (postorder, i.e. files are visited before their
 // parent directory).
 //
-// Throws Error on error.
+// Throws core::Error on error.
 void traverse(const std::string& path, const TraverseVisitor& visitor);
 
 // Remove `path` (non-directory), NFS safe. Logs according to `unlink_log`.
@@ -420,18 +422,18 @@ void update_mtime(const std::string& path);
 // Remove `path` (and its contents if it's a directory). A nonexistent path is
 // not considered an error.
 //
-// Throws Error on error.
+// Throws core::Error on error.
 void wipe_path(const std::string& path);
 
-// Write `size` bytes from `data` to `fd`. Throws `Error` on error.
+// Write `size` bytes from `data` to `fd`. Throws `core::Error` on error.
 void write_fd(int fd, const void* data, size_t size);
 
 // Write `data` to `path`. The file will be opened according to `open_mode`,
 // which always will include `std::ios::out` even if not specified at the call
 // site.
 //
-// Throws `Error` on error. The description contains the error message without
-// the path.
+// Throws `core::Error` on error. The description contains the error message
+// without the path.
 void write_file(const std::string& path,
                 const std::string& data,
                 std::ios_base::openmode open_mode = std::ios::binary);
index 75c60baca92bece54457129b8095dbf6d459ea1f..c89d60cbd29854d07cead42b18f4ed0374a78202 100644 (file)
@@ -20,7 +20,8 @@
 
 #include "Logging.hpp"
 #include "assertions.hpp"
-#include "exceptions.hpp"
+
+#include <core/exceptions.hpp>
 
 #include <algorithm>
 
@@ -54,7 +55,7 @@ ZstdCompressor::ZstdCompressor(FILE* stream, int8_t compression_level)
   size_t ret = ZSTD_initCStream(m_zstd_stream, m_compression_level);
   if (ZSTD_isError(ret)) {
     ZSTD_freeCStream(m_zstd_stream);
-    throw Error("error initializing zstd compression stream");
+    throw core::Error("error initializing zstd compression stream");
   }
 }
 
@@ -89,7 +90,7 @@ ZstdCompressor::write(const void* data, size_t count)
     size_t compressed_bytes = m_zstd_out.pos;
     if (fwrite(buffer, 1, compressed_bytes, m_stream) != compressed_bytes
         || ferror(m_stream)) {
-      throw Error("failed to write to zstd output stream ");
+      throw core::Error("failed to write to zstd output stream ");
     }
   }
   ret = flush;
@@ -102,7 +103,7 @@ ZstdCompressor::write(const void* data, size_t count)
     size_t compressed_bytes = m_zstd_out.pos;
     if (fwrite(buffer, 1, compressed_bytes, m_stream) != compressed_bytes
         || ferror(m_stream)) {
-      throw Error("failed to write to zstd output stream");
+      throw core::Error("failed to write to zstd output stream");
     }
   }
 }
index c08d0f90b9aefdd7bb7d822f8feb396b3f6d301e..f02f2e4d84f3ded0981675c6045f6426fa429fc0 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2019-2020 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -19,7 +19,8 @@
 #include "ZstdDecompressor.hpp"
 
 #include "assertions.hpp"
-#include "exceptions.hpp"
+
+#include <core/exceptions.hpp>
 
 ZstdDecompressor::ZstdDecompressor(FILE* stream)
   : m_stream(stream),
@@ -31,7 +32,7 @@ ZstdDecompressor::ZstdDecompressor(FILE* stream)
   size_t ret = ZSTD_initDStream(m_zstd_stream);
   if (ZSTD_isError(ret)) {
     ZSTD_freeDStream(m_zstd_stream);
-    throw Error("failed to initialize zstd decompression stream");
+    throw core::Error("failed to initialize zstd decompression stream");
   }
 }
 
@@ -49,7 +50,7 @@ ZstdDecompressor::read(void* data, size_t count)
     if (m_input_size == m_input_consumed) {
       m_input_size = fread(m_input_buffer, 1, sizeof(m_input_buffer), m_stream);
       if (m_input_size == 0) {
-        throw Error("failed to read from zstd input stream");
+        throw core::Error("failed to read from zstd input stream");
       }
       m_input_consumed = 0;
     }
@@ -63,7 +64,7 @@ ZstdDecompressor::read(void* data, size_t count)
     m_zstd_out.pos = 0;
     size_t ret = ZSTD_decompressStream(m_zstd_stream, &m_zstd_out, &m_zstd_in);
     if (ZSTD_isError(ret)) {
-      throw Error("failed to read from zstd input stream");
+      throw core::Error("failed to read from zstd input stream");
     }
     if (ret == 0) {
       m_reached_stream_end = true;
@@ -78,6 +79,6 @@ void
 ZstdDecompressor::finalize()
 {
   if (!m_reached_stream_end) {
-    throw Error("garbage data at end of zstd input stream");
+    throw core::Error("garbage data at end of zstd input stream");
   }
 }
index 886926bf1d92bec10e5d96d7b4776c2181551fa1..9fcdb041a6c3af8a4a4c5a59e1569674cba38c68 100644 (file)
@@ -19,7 +19,6 @@
 #include "argprocessing.hpp"
 
 #include "Context.hpp"
-#include "FormatNonstdStringView.hpp"
 #include "Logging.hpp"
 #include "assertions.hpp"
 #include "compopt.hpp"
index 2ffba2d90894402e6e5037f701d285f940b0b0f0..9be2837a7c4592198e35a4e843f131d391a47f60 100644 (file)
 #include "cleanup.hpp"
 #include "compopt.hpp"
 #include "compress.hpp"
-#include "exceptions.hpp"
 #include "execute.hpp"
 #include "fmtmacros.hpp"
 #include "hashutil.hpp"
 #include "language.hpp"
 
+#include <core/exceptions.hpp>
 #include <core/types.hpp>
 #include <core/wincompat.hpp>
 #include <storage/Storage.hpp>
@@ -223,7 +223,7 @@ add_prefix(const Context& ctx, Args& args, const std::string& prefix_command)
   for (const auto& word : Util::split_into_strings(prefix_command, " ")) {
     std::string path = find_executable(ctx, word, CCACHE_NAME);
     if (path.empty()) {
-      throw Fatal("{}: {}", word, strerror(errno));
+      throw core::Fatal("{}: {}", word, strerror(errno));
     }
 
     prefix.push_back(path);
@@ -248,7 +248,7 @@ prepare_debug_path(const std::string& debug_dir,
 #endif
   try {
     Util::ensure_dir_exists(Util::dir_name(prefix));
-  } catch (Error&) {
+  } catch (core::Error&) {
     // Ignore since we can't handle an error in another way in this context. The
     // caller takes care of logging when trying to open the path for writing.
   }
@@ -519,7 +519,7 @@ process_preprocessed_file(Context& ctx,
   std::string data;
   try {
     data = Util::read_file(path);
-  } catch (Error&) {
+  } catch (core::Error&) {
     return Statistic::internal_error;
   }
 
@@ -702,7 +702,7 @@ result_key_from_depfile(Context& ctx, Hash& hash)
   std::string file_content;
   try {
     file_content = Util::read_file(ctx.args_info.output_dep);
-  } catch (const Error& e) {
+  } catch (const core::Error& e) {
     LOG(
       "Cannot open dependency file {}: {}", ctx.args_info.output_dep, e.what());
     return nullopt;
@@ -1852,12 +1852,12 @@ find_compiler(Context& ctx,
       : find_executable_function(ctx, compiler, CCACHE_NAME);
 
   if (resolved_compiler.empty()) {
-    throw Fatal("Could not find compiler \"{}\" in PATH", compiler);
+    throw core::Fatal("Could not find compiler \"{}\" in PATH", compiler);
   }
 
   if (Util::same_program_name(Util::base_name(resolved_compiler),
                               CCACHE_NAME)) {
-    throw Fatal(
+    throw core::Fatal(
       "Recursive invocation (the name of the ccache binary must be \"{}\")",
       CCACHE_NAME);
   }
@@ -1937,7 +1937,7 @@ finalize_at_exit(Context& ctx)
     }
 
     ctx.storage.finalize();
-  } catch (const ErrorBase& e) {
+  } catch (const core::ErrorBase& e) {
     // finalize_at_exit must not throw since it's called by a destructor.
     LOG("Error while finalizing stats: {}", e.what());
   }
@@ -2009,7 +2009,7 @@ cache_compilation(int argc, const char* const* argv)
     }
     auto execv_argv = saved_orig_args.to_argv();
     execute_noreturn(execv_argv.data(), saved_temp_dir);
-    throw Fatal(
+    throw core::Fatal(
       "execute_noreturn of {} failed: {}", execv_argv[0], strerror(errno));
   }
 
@@ -2392,7 +2392,7 @@ handle_main_options(int argc, const char* const* argv)
       break;
 
     case 'F': { // --max-files
-      auto files = util::value_or_throw<Error>(util::parse_unsigned(arg));
+      auto files = util::value_or_throw<core::Error>(util::parse_unsigned(arg));
       Config::set_value_in_file(
         ctx.config.primary_config_path(), "max_files", arg);
       if (files == 0) {
@@ -2422,7 +2422,7 @@ handle_main_options(int argc, const char* const* argv)
       // for the -o=K=V case (key "=K" and value "V").
       size_t eq_pos = arg.find('=', 1);
       if (eq_pos == std::string::npos) {
-        throw Error("missing equal sign in \"{}\"", arg);
+        throw core::Error("missing equal sign in \"{}\"", arg);
       }
       std::string key = arg.substr(0, eq_pos);
       std::string value = arg.substr(eq_pos + 1);
@@ -2436,7 +2436,7 @@ handle_main_options(int argc, const char* const* argv)
 
     case SHOW_LOG_STATS: {
       if (ctx.config.stats_log().empty()) {
-        throw Fatal("No stats log has been configured");
+        throw core::Fatal("No stats log has been configured");
       }
       PRINT_RAW(stdout, Statistics::format_stats_log(ctx.config));
       Counters counters = Statistics::read_log(ctx.config.stats_log());
@@ -2477,7 +2477,7 @@ handle_main_options(int argc, const char* const* argv)
       if (arg == "uncompressed") {
         wanted_level = nullopt;
       } else {
-        wanted_level = util::value_or_throw<Error>(
+        wanted_level = util::value_or_throw<core::Error>(
           util::parse_signed(arg, INT8_MIN, INT8_MAX, "compression level"));
       }
 
@@ -2523,7 +2523,7 @@ ccache_main(int argc, const char* const* argv)
     }
 
     return cache_compilation(argc, argv);
-  } catch (const ErrorBase& e) {
+  } catch (const core::ErrorBase& e) {
     PRINT(stderr, "ccache: error: {}\n", e.what());
     return EXIT_FAILURE;
   }
index 274a101feca1a2b161ccf6bf83b9e01920fddbca..30d92afe738c9231eb588e9f88d61bdde32c477f 100644 (file)
@@ -32,6 +32,7 @@
 #include "assertions.hpp"
 #include "fmtmacros.hpp"
 
+#include <core/exceptions.hpp>
 #include <core/wincompat.hpp>
 #include <util/string.hpp>
 
@@ -115,7 +116,8 @@ open_file(const std::string& path, const char* mode)
 {
   File f(path, mode);
   if (!f) {
-    throw Error("failed to open {} for reading: {}", path, strerror(errno));
+    throw core::Error(
+      "failed to open {} for reading: {}", path, strerror(errno));
   }
   return f;
 }
@@ -124,7 +126,7 @@ std::unique_ptr<CacheEntryReader>
 create_reader(const CacheFile& cache_file, FILE* stream)
 {
   if (cache_file.type() == CacheFile::Type::unknown) {
-    throw Error("unknown file type for {}", cache_file.path());
+    throw core::Error("unknown file type for {}", cache_file.path());
   }
 
   switch (cache_file.type()) {
@@ -239,7 +241,7 @@ compress_stats(const Config& config,
           auto reader = create_reader(cache_file, file.get());
           compr_size += cache_file.lstat().size();
           content_size += reader->content_size();
-        } catch (Error&) {
+        } catch (core::Error&) {
           incompr_size += cache_file.lstat().size();
         }
 
@@ -306,7 +308,7 @@ compress_recompress(Context& ctx,
           thread_pool.enqueue([&statistics, stats_file, file, level] {
             try {
               recompress_file(statistics, stats_file, file, level);
-            } catch (Error&) {
+            } catch (core::Error&) {
               // Ignore for now.
             }
           });
similarity index 93%
rename from src/exceptions.hpp
rename to src/core/exceptions.hpp
index 65c4e2e863d15b9d61bc7407dcaf84217c149739..aae4b26e04fe7f34741cb0943b279394b029189c 100644 (file)
 
 #pragma once
 
-#include "FormatNonstdStringView.hpp"
+#include <FormatNonstdStringView.hpp>
 
-#include "third_party/fmt/core.h"
-#include "third_party/nonstd/optional.hpp"
+#include <third_party/fmt/core.h>
+#include <third_party/nonstd/optional.hpp>
 
 #include <stdexcept>
 #include <string>
 #include <utility>
 
+namespace core {
+
 // Don't throw or catch ErrorBase directly, use a subclass.
 class ErrorBase : public std::runtime_error
 {
@@ -77,3 +79,5 @@ inline Fatal::Fatal(T&&... args)
   : ErrorBase(fmt::format(std::forward<T>(args)...))
 {
 }
+
+} // namespace core
index f6fa14dd163645784010e504b9596a5638200aeb..8f4e787a577dc24a590339a64cac1c82c673bbf2 100644 (file)
@@ -30,6 +30,7 @@
 #include "Win32Util.hpp"
 #include "fmtmacros.hpp"
 
+#include <core/exceptions.hpp>
 #include <core/wincompat.hpp>
 #include <util/path.hpp>
 
@@ -203,7 +204,7 @@ execute(Context& ctx, const char* const* argv, Fd&& fd_out, Fd&& fd_err)
   }
 
   if (ctx.compiler_pid == -1) {
-    throw Fatal("Failed to fork: {}", strerror(errno));
+    throw core::Fatal("Failed to fork: {}", strerror(errno));
   }
 
   if (ctx.compiler_pid == 0) {
@@ -225,7 +226,7 @@ execute(Context& ctx, const char* const* argv, Fd&& fd_out, Fd&& fd_err)
     if (result == -1 && errno == EINTR) {
       continue;
     }
-    throw Fatal("waitpid failed: {}", strerror(errno));
+    throw core::Fatal("waitpid failed: {}", strerror(errno));
   }
 
   {
index 9a017fae9bff54dc2422763928eef27f41ce7248..3b7cf5d3118e9744805e2e4555cddfdba5ff5030 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2019-2020 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
 
 #pragma once
 
-#include "third_party/fmt/core.h"
-#include "third_party/fmt/format.h"
+#include <FormatNonstdStringView.hpp>
+
+#include <third_party/fmt/core.h>
+#include <third_party/fmt/format.h>
 
 // Convenience macro for calling `fmt::format` with `FMT_STRING` around the
 // format string literal.
index 074eaa571445839cdf208f8ae48f6b044d133c84..03d2e748e81bd45597ee5781ce8840144b5a29c8 100644 (file)
@@ -31,6 +31,7 @@
 #include "fmtmacros.hpp"
 #include "macroskip.hpp"
 
+#include <core/exceptions.hpp>
 #include <core/wincompat.hpp>
 #include <util/string.hpp>
 
@@ -189,7 +190,7 @@ hash_source_code_file_nocache(const Context& ctx,
     std::string data;
     try {
       data = Util::read_file(path, size_hint);
-    } catch (Error&) {
+    } catch (core::Error&) {
       return HASH_SOURCE_CODE_ERROR;
     }
     int result = hash_source_code_string(ctx, hash, data, path);
@@ -471,12 +472,12 @@ hash_command_output(Hash& hash,
 #else
   int pipefd[2];
   if (pipe(pipefd) == -1) {
-    throw Fatal("pipe failed: {}", strerror(errno));
+    throw core::Fatal("pipe failed: {}", strerror(errno));
   }
 
   pid_t pid = fork();
   if (pid == -1) {
-    throw Fatal("fork failed: {}", strerror(errno));
+    throw core::Fatal("fork failed: {}", strerror(errno));
   }
 
   if (pid == 0) {
index fd2847b4f9c45d9c10dbc0129bf278497c59e48b..74fc0db2e7ec8726cfc94acb49ada7dd04d22dd5 100644 (file)
@@ -23,6 +23,7 @@
 #include <TemporaryFile.hpp>
 #include <Util.hpp>
 #include <assertions.hpp>
+#include <core/exceptions.hpp>
 #include <fmtmacros.hpp>
 #include <storage/secondary/FileStorage.hpp>
 #include <storage/secondary/HttpStorage.hpp>
@@ -97,7 +98,7 @@ parse_storage_config(const nonstd::string_view entry)
     Util::split_into_views(entry, "|", util::Tokenizer::Mode::include_empty);
 
   if (parts.empty() || parts.front().empty()) {
-    throw Error("secondary storage config must provide a URL: {}", entry);
+    throw core::Error("secondary storage config must provide a URL: {}", entry);
   }
 
   SecondaryStorageConfig result;
@@ -106,11 +107,11 @@ parse_storage_config(const nonstd::string_view entry)
   try {
     std::ignore = result.params.url.host();
   } catch (const Url::parse_error& e) {
-    throw Error("Cannot parse URL: {}", e.what());
+    throw core::Error("Cannot parse URL: {}", e.what());
   }
 
   if (result.params.url.scheme().empty()) {
-    throw Error("URL scheme must not be empty: {}", entry);
+    throw core::Error("URL scheme must not be empty: {}", entry);
   }
 
   for (size_t i = 1; i < parts.size(); ++i) {
@@ -121,7 +122,7 @@ parse_storage_config(const nonstd::string_view entry)
     const auto& key = kv_pair.first;
     const auto& raw_value = kv_pair.second.value_or("true");
     const auto value =
-      util::value_or_throw<Error>(util::percent_decode(raw_value));
+      util::value_or_throw<core::Error>(util::percent_decode(raw_value));
     if (key == "read-only" && value == "true") {
       result.read_only = true;
     }
@@ -197,14 +198,14 @@ Storage::get(const Digest& key, const core::CacheEntryType type)
   m_tmp_files.push_back(tmp_file.path);
   try {
     Util::write_file(tmp_file.path, *value);
-  } catch (const Error& e) {
-    throw Fatal("Error writing to {}: {}", tmp_file.path, e.what());
+  } catch (const core::Error& e) {
+    throw core::Fatal("Error writing to {}: {}", tmp_file.path, e.what());
   }
 
   m_primary_storage.put(key, type, [&](const std::string& path) {
     try {
       Util::copy_file(tmp_file.path, path);
-    } catch (const Error& e) {
+    } catch (const core::Error& e) {
       LOG("Failed to copy {} to {}: {}", tmp_file.path, path, e.what());
       // Don't indicate failure since get from primary storage was OK.
     }
@@ -236,7 +237,7 @@ Storage::put(const Digest& key,
     std::string value;
     try {
       value = Util::read_file(*path);
-    } catch (const Error& e) {
+    } catch (const core::Error& e) {
       LOG("Failed to read {}: {}", *path, e.what());
       return true; // Don't indicate failure since primary storage was OK.
     }
@@ -275,7 +276,8 @@ Storage::add_secondary_storages()
     url_for_logging.user_info("");
     const auto storage = get_storage(config.params.url);
     if (!storage) {
-      throw Error("unknown secondary storage URL: {}", url_for_logging.str());
+      throw core::Error("unknown secondary storage URL: {}",
+                        url_for_logging.str());
     }
     m_secondary_storages.emplace_back(
       std::make_unique<SecondaryStorageEntry>(SecondaryStorageEntry{
index a4dd77906bf47c925e3b9410d0c514a855c53ab3..f5022693cacbe3d1f06c84e551efeb44b71cb9f4 100644 (file)
@@ -27,8 +27,8 @@
 #include <Util.hpp>
 #include <assertions.hpp>
 #include <cleanup.hpp>
+#include <core/exceptions.hpp>
 #include <core/wincompat.hpp>
-#include <exceptions.hpp>
 #include <fmtmacros.hpp>
 #include <util/file.hpp>
 
@@ -375,7 +375,7 @@ PrimaryStorage::update_stats_and_maybe_move_cache_file(
       LOG("Moving {} to {}", current_path, wanted_path);
       try {
         Util::rename(current_path, wanted_path);
-      } catch (const Error&) {
+      } catch (const core::Error&) {
         // Two ccache processes may move the file at the same time, so failure
         // to rename is OK.
       }
index d29d1fd7e097621f1e1a38575f761644d6e47805..222825b485588ccc53351e466daa5a4890cf66bb 100644 (file)
@@ -24,7 +24,7 @@
 #include <UmaskScope.hpp>
 #include <Util.hpp>
 #include <assertions.hpp>
-#include <exceptions.hpp>
+#include <core/exceptions.hpp>
 #include <fmtmacros.hpp>
 #include <util/expected.hpp>
 #include <util/file.hpp>
@@ -66,7 +66,7 @@ FileStorageBackend::FileStorageBackend(const Params& params)
 {
   ASSERT(params.url.scheme() == "file");
   if (!params.url.host().empty()) {
-    throw Fatal(FMT(
+    throw core::Fatal(FMT(
       "invalid file path \"{}\":  specifying a host (\"{}\") is not supported",
       params.url.str(),
       params.url.host()));
@@ -74,7 +74,8 @@ FileStorageBackend::FileStorageBackend(const Params& params)
 
   for (const auto& attr : params.attributes) {
     if (attr.key == "umask") {
-      m_umask = util::value_or_throw<Fatal>(util::parse_umask(attr.value));
+      m_umask =
+        util::value_or_throw<core::Fatal>(util::parse_umask(attr.value));
     } else if (attr.key == "update-mtime") {
       m_update_mtime = attr.value == "true";
     } else if (!is_framework_attribute(attr.key)) {
@@ -104,7 +105,7 @@ FileStorageBackend::get(const Digest& key)
   try {
     LOG("Reading {}", path);
     return Util::read_file(path);
-  } catch (const Error& e) {
+  } catch (const core::Error& e) {
     LOG("Failed to read {}: {}", path, e.what());
     return nonstd::make_unexpected(Failure::error);
   }
@@ -139,7 +140,7 @@ FileStorageBackend::put(const Digest& key,
       file.write(value);
       file.commit();
       return true;
-    } catch (const Error& e) {
+    } catch (const core::Error& e) {
       LOG("Failed to write {}: {}", path, e.what());
       return nonstd::make_unexpected(Failure::error);
     }
index c0259a51b123cf55fe0d5d444fdc2531841ee032..1ee4078177ba1ba2f0d6b06cef9f219eb1c229f7 100644 (file)
@@ -21,7 +21,7 @@
 #include <Digest.hpp>
 #include <Logging.hpp>
 #include <ccache.hpp>
-#include <exceptions.hpp>
+#include <core/exceptions.hpp>
 #include <fmtmacros.hpp>
 #include <util/expected.hpp>
 #include <util/string.hpp>
@@ -125,9 +125,9 @@ get_host_header_value(const Url& url)
   // slashes must be stripped.
   const auto prefix = nonstd::string_view{"//"};
   if (!util::starts_with(rendered_value, prefix)) {
-    throw Fatal(R"(Expected partial URL "{}" to start with "{}")",
-                rendered_value,
-                prefix);
+    throw core::Fatal(R"(Expected partial URL "{}" to start with "{}")",
+                      rendered_value,
+                      prefix);
   }
   return rendered_value.substr(prefix.size());
 }
@@ -136,7 +136,8 @@ std::string
 get_url(const Url& url)
 {
   if (url.host().empty()) {
-    throw Fatal("A host is required in HTTP storage URL \"{}\"", url.str());
+    throw core::Fatal("A host is required in HTTP storage URL \"{}\"",
+                      url.str());
   }
 
   // httplib requires a partial URL with just scheme, host and port.
@@ -150,8 +151,8 @@ HttpStorageBackend::HttpStorageBackend(const Params& params)
   if (!params.url.user_info().empty()) {
     const auto pair = util::split_once(params.url.user_info(), ':');
     if (!pair.second) {
-      throw Fatal("Expected username:password in URL but got \"{}\"",
-                  params.url.user_info());
+      throw core::Fatal("Expected username:password in URL but got \"{}\"",
+                        params.url.user_info());
     }
     m_http_client.set_basic_auth(to_string(pair.first).c_str(),
                                  to_string(*pair.second).c_str());
index 81e5866b017960cd9f135c0331390713d4d6683c..518e97cacb851bbc204e9e2c37209a4251c1e6de 100644 (file)
@@ -20,7 +20,7 @@
 
 #include <Digest.hpp>
 #include <Logging.hpp>
-#include <exceptions.hpp>
+#include <core/exceptions.hpp>
 #include <fmtmacros.hpp>
 #include <util/expected.hpp>
 #include <util/string.hpp>
@@ -210,7 +210,7 @@ RedisStorageBackend::connect(const Url& url,
   const std::string host = url.host().empty() ? "localhost" : url.host();
   const uint32_t port = url.port().empty()
                           ? DEFAULT_PORT
-                          : util::value_or_throw<Fatal>(
+                          : util::value_or_throw<core::Fatal>(
                             util::parse_unsigned(url.port(), 1, 65535, "port"));
   ASSERT(url.path().empty() || url.path()[0] == '/');
 
@@ -246,7 +246,7 @@ RedisStorageBackend::select_database(const Url& url)
 {
   const uint32_t db_number =
     url.path().empty() ? 0
-                       : util::value_or_throw<Fatal>(util::parse_unsigned(
+                       : util::value_or_throw<core::Fatal>(util::parse_unsigned(
                          url.path().substr(1),
                          0,
                          std::numeric_limits<uint32_t>::max(),
index 84ea2a853c44de7f105e806031d623563d3d9734..628a9a748322007ac7aae15f3c9b5773379bc069 100644 (file)
@@ -107,9 +107,9 @@ public:
 
   // Create an instance of the backend. The instance is created just before the
   // first call to a backend method, so the backend constructor can open a
-  // connection or similar right away if wanted. The method should throw `Fatal`
-  // on fatal configuration error or `Backend::Failed` on connection error or
-  // timeout.
+  // connection or similar right away if wanted. The method should throw
+  // `core::Fatal` on fatal configuration error or `Backend::Failed` on
+  // connection error or timeout.
   virtual std::unique_ptr<Backend>
   create_backend(const Backend::Params& parameters) const = 0;
 
index 27cc5cda77494028a75a5b4bf5902106217acb3e..85c62c16a6d37a40b2638a82aaf60c32fa3fa476 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <Logging.hpp>
 #include <Util.hpp>
+#include <core/exceptions.hpp>
 #include <fmtmacros.hpp>
 
 namespace util {
@@ -40,7 +41,7 @@ create_cachedir_tag(const std::string& dir)
   }
   try {
     Util::write_file(path, cachedir_tag);
-  } catch (const Error& e) {
+  } catch (const core::Error& e) {
     LOG("Failed to create {}: {}", path, e.what());
   }
 }
index cb68f03c7c7e9515d350e7e0410034ff1c830e10..88f1c9b5426c76e5e813d1fd2766b682062a3a63 100644 (file)
@@ -18,7 +18,6 @@
 
 #include "string.hpp"
 
-#include <FormatNonstdStringView.hpp>
 #include <fmtmacros.hpp>
 
 #include <cctype>
index 615f8bcb90cb4a214afcce7ba9ef99dae0400eeb..d97ddba91b7699765579f133ade730e1309952b9 100644 (file)
@@ -19,9 +19,9 @@
 #include "TestUtil.hpp"
 
 #include "../src/Util.hpp"
-#include "../src/exceptions.hpp"
 #include "../src/fmtmacros.hpp"
 
+#include <core/exceptions.hpp>
 #include <core/wincompat.hpp>
 
 #ifdef HAVE_UNISTD_H
@@ -35,7 +35,7 @@ size_t TestContext::m_subdir_counter = 0;
 TestContext::TestContext() : m_test_dir(Util::get_actual_cwd())
 {
   if (Util::base_name(Util::dir_name(m_test_dir)) != "testdir") {
-    throw Error("TestContext instantiated outside test directory");
+    throw core::Error("TestContext instantiated outside test directory");
   }
   ++m_subdir_counter;
   std::string subtest_dir = FMT("{}/test_{}", m_test_dir, m_subdir_counter);
@@ -56,7 +56,8 @@ void
 check_chdir(const std::string& dir)
 {
   if (chdir(dir.c_str()) != 0) {
-    throw Error("failed to change directory to {}: {}", dir, strerror(errno));
+    throw core::Error(
+      "failed to change directory to {}: {}", dir, strerror(errno));
   }
 }
 
index 7bce9029405a5811ce3bb9952ee67850d21ac67f..010f2256510c32eb425a1f69cf8d2d6ca68b9e41 100644 (file)
 #include "../src/Config.hpp"
 #include "../src/Sloppiness.hpp"
 #include "../src/Util.hpp"
-#include "../src/exceptions.hpp"
 #include "../src/fmtmacros.hpp"
 #include "TestUtil.hpp"
 
+#include <core/exceptions.hpp>
+
 #include "third_party/doctest.h"
 #include "third_party/fmt/core.h"
 
@@ -310,7 +311,7 @@ TEST_CASE("Config::set_value_in_file")
     try {
       Config::set_value_in_file("ccache.conf", "foo", "bar");
       CHECK(false);
-    } catch (const Error& e) {
+    } catch (const core::Error& e) {
       CHECK(std::string(e.what()) == "unknown configuration option \"foo\"");
     }
 
@@ -351,7 +352,7 @@ TEST_CASE("Config::get_string_value")
     try {
       config.get_string_value("foo");
       CHECK(false);
-    } catch (const Error& e) {
+    } catch (const core::Error& e) {
       CHECK(std::string(e.what()) == "unknown configuration option \"foo\"");
     }
   }
index c67673299236a855d2dcd131ced700116e4562fc..9253f6857df1bd98737495b260b98fcc6a004488 100644 (file)
@@ -21,6 +21,7 @@
 #include "../src/Util.hpp"
 #include "TestUtil.hpp"
 
+#include <core/exceptions.hpp>
 #include <core/wincompat.hpp>
 
 #include "third_party/doctest.h"
@@ -620,7 +621,7 @@ TEST_CASE("Win32 No Sharing")
   Finalizer cleanup([&] { CloseHandle(handle); });
 
   // Sanity check we can't open the file for read/write access.
-  REQUIRE_THROWS_AS(Util::read_file("file"), const Error&);
+  REQUIRE_THROWS_AS(Util::read_file("file"), const core::Error&);
 
   SUBCASE("stat file no sharing")
   {
index ae57fd80b322f36eb9f9682d9e259436c8b2651b..bb0dc6a1b461968ebe93139cf49f54cdc39ec17e 100644 (file)
@@ -22,6 +22,7 @@
 #include "../src/fmtmacros.hpp"
 #include "TestUtil.hpp"
 
+#include <core/exceptions.hpp>
 #include <core/wincompat.hpp>
 
 #include "third_party/doctest.h"
@@ -450,7 +451,7 @@ TEST_CASE("Util::hard_link")
 
   SUBCASE("Link nonexistent file")
   {
-    CHECK_THROWS_AS(Util::hard_link("old", "new"), Error);
+    CHECK_THROWS_AS(Util::hard_link("old", "new"), core::Error);
   }
 }