]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
chore: Improve logging of file read failures
authorJoel Rosdahl <joel@rosdahl.net>
Wed, 2 Nov 2022 18:18:21 +0000 (19:18 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Wed, 2 Nov 2022 18:18:21 +0000 (19:18 +0100)
src/Args.cpp
src/Depfile.cpp
src/ccache.cpp
src/core/mainoptions.cpp
src/hashutil.cpp
src/storage/local/StatsFile.cpp
src/util/LockFile.cpp
src/util/file.cpp

index d4077a351c5a17577b97286efa55ef840dc1017c..50cfa672a82fb24de15a4af54b277c790fbe42fa 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "Util.hpp"
 
+#include <Logging.hpp>
 #include <core/exceptions.hpp>
 #include <util/file.hpp>
 #include <util/string.hpp>
@@ -51,6 +52,7 @@ Args::from_atfile(const std::string& filename, AtFileFormat format)
 {
   const auto argtext = util::read_file<std::string>(filename);
   if (!argtext) {
+    LOG("Failed to read atfile {}: {}", filename, argtext.error());
     return std::nullopt;
   }
 
index 2d721a6c1609ea7690caa8407b0e0abb6c42d753..f1ef39a1df66492881828ab377f218b703cf9fd4 100644 (file)
@@ -130,7 +130,9 @@ make_paths_relative_in_output_dep(const Context& ctx)
   const std::string& output_dep = ctx.args_info.output_dep;
   const auto file_content = util::read_file<std::string>(output_dep);
   if (!file_content) {
-    LOG("Cannot open dependency file {}: {}", output_dep, file_content.error());
+    LOG("Failed to read dependency file {}: {}",
+        output_dep,
+        file_content.error());
     return;
   }
   const auto new_content = rewrite_source_paths(ctx, *file_content);
index e701e204a29c49dd3253bd61e366078b86cb2f35..392818ff31a53699709355ca37eb515ce9d90ab9 100644 (file)
@@ -452,7 +452,7 @@ process_preprocessed_file(Context& ctx, Hash& hash, const std::string& path)
 {
   auto data = util::read_file<std::string>(path);
   if (!data) {
-    LOG("Failed reading {}: {}", path, data.error());
+    LOG("Failed to read {}: {}", path, data.error());
     return nonstd::make_unexpected(Statistic::internal_error);
   }
 
@@ -633,7 +633,7 @@ result_key_from_depfile(Context& ctx, Hash& hash)
   const auto file_content =
     util::read_file<std::string>(ctx.args_info.output_dep);
   if (!file_content) {
-    LOG("Cannot open dependency file {}: {}",
+    LOG("Failed to read dependency file {}: {}",
         ctx.args_info.output_dep,
         file_content.error());
     return std::nullopt;
@@ -763,7 +763,9 @@ do_execute(Context& ctx, Args& args, const bool capture_stdout = true)
   if (capture_stdout) {
     auto stdout_data_result = util::read_file<util::Bytes>(tmp_stdout.path);
     if (!stdout_data_result) {
-      // The stdout file was removed - cleanup in progress? Better bail out.
+      LOG("Failed to read {} (cleanup in progress?): {}",
+          tmp_stdout.path,
+          stdout_data_result.error());
       return nonstd::make_unexpected(Statistic::missing_cache_file);
     }
     stdout_data = *stdout_data_result;
@@ -771,7 +773,9 @@ do_execute(Context& ctx, Args& args, const bool capture_stdout = true)
 
   auto stderr_data_result = util::read_file<util::Bytes>(tmp_stderr.path);
   if (!stderr_data_result) {
-    // The stdout file was removed - cleanup in progress? Better bail out.
+    LOG("Failed to read {} (cleanup in progress?): {}",
+        tmp_stderr.path,
+        stderr_data_result.error());
     return nonstd::make_unexpected(Statistic::missing_cache_file);
   }
 
index 1f6e651cc58fe8f96015762fc654ae96d191fd5e..2283162fa180072976f977117579f070fc0d4cf7 100644 (file)
@@ -175,7 +175,7 @@ read_from_path_or_stdin(const std::string& path)
     const auto result = util::read_file<std::vector<uint8_t>>(path);
     if (!result) {
       return nonstd::make_unexpected(
-        FMT("Failed to read from {}: {}", path, result.error()));
+        FMT("Failed to read {}: {}", path, result.error()));
     }
     return *result;
   }
index 990561ffa1b4ea4b5342614e13897aff75cbc4eb..8d7151d680f25b42b968cf2cce1468775cf342ac 100644 (file)
@@ -202,6 +202,7 @@ do_hash_file(const Context& ctx,
 
   const auto data = util::read_file<std::string>(path, size_hint);
   if (!data) {
+    LOG("Failed to read {}: {}", path, data.error());
     return HASH_SOURCE_CODE_ERROR;
   }
 
index b00fc82e526b07454a5ba08ce458d29ebbada9fa..4332d80ed119607a37bd1946c4c0f01c18fa199b 100644 (file)
@@ -38,7 +38,7 @@ StatsFile::read() const
 
   const auto data = util::read_file<std::string>(m_path);
   if (!data) {
-    // Ignore.
+    // A nonexistent stats file is OK.
     return counters;
   }
 
index 0d7e96e8e9ad2feebba4bbaa794ea9799a17edb3..f90b762624ed371cf57e9ff076bf8e7f8fc78418 100644 (file)
@@ -178,7 +178,6 @@ LockFile::do_acquire(const bool blocking)
     }
 
     int saved_errno = errno;
-    LOG("Could not acquire {}: {}", m_lock_file, strerror(saved_errno));
     if (saved_errno == ENOENT) {
       // Directory doesn't exist?
       if (Util::create_dir(Util::dir_name(m_lock_file))) {
@@ -186,6 +185,7 @@ LockFile::do_acquire(const bool blocking)
         continue;
       }
     }
+    LOG("Could not acquire {}: {}", m_lock_file, strerror(saved_errno));
 
     if (saved_errno == EPERM) {
       // The file system does not support symbolic links. We have no choice but
index 5ddc05bbaa5f011aaf2e059292d58c091e38c261..db0f4e83952495ea5aa16133ff2423984a55b4eb 100644 (file)
@@ -111,7 +111,6 @@ read_file(const std::string& path, size_t size_hint)
   if (size_hint == 0) {
     const auto stat = Stat::stat(path);
     if (!stat) {
-      LOG("Failed to stat {}: {}", path, strerror(errno));
       return nonstd::make_unexpected(strerror(errno));
     }
     size_hint = stat.size();
@@ -129,7 +128,6 @@ read_file(const std::string& path, size_t size_hint)
   }();
   Fd fd(open(path.c_str(), open_flags));
   if (!fd) {
-    LOG("Failed to open {}: {}", path, strerror(errno));
     return nonstd::make_unexpected(strerror(errno));
   }
 
@@ -156,7 +154,6 @@ read_file(const std::string& path, size_t size_hint)
   }
 
   if (ret == -1) {
-    LOG("Failed to read {}: {}", path, strerror(errno));
     return nonstd::make_unexpected(strerror(errno));
   }