summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Rosdahl <joel@rosdahl.net>2022-11-02 19:18:21 +0100
committerJoel Rosdahl <joel@rosdahl.net>2022-11-02 19:18:21 +0100
commitc5e1f88e22987365754e26c0f8a4e51cf572018f (patch)
treecf47f7d3e57cf270a3daff2a7b7b37c027867349
parent98a04d7c881859910080619ba926eb74988c8c74 (diff)
downloadccache-c5e1f88e22987365754e26c0f8a4e51cf572018f.tar.gz
chore: Improve logging of file read failures
-rw-r--r--src/Args.cpp2
-rw-r--r--src/Depfile.cpp4
-rw-r--r--src/ccache.cpp12
-rw-r--r--src/core/mainoptions.cpp2
-rw-r--r--src/hashutil.cpp1
-rw-r--r--src/storage/local/StatsFile.cpp2
-rw-r--r--src/util/LockFile.cpp2
-rw-r--r--src/util/file.cpp3
8 files changed, 17 insertions, 11 deletions
diff --git a/src/Args.cpp b/src/Args.cpp
index d4077a35..50cfa672 100644
--- a/src/Args.cpp
+++ b/src/Args.cpp
@@ -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;
}
diff --git a/src/Depfile.cpp b/src/Depfile.cpp
index 2d721a6c..f1ef39a1 100644
--- a/src/Depfile.cpp
+++ b/src/Depfile.cpp
@@ -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);
diff --git a/src/ccache.cpp b/src/ccache.cpp
index e701e204..392818ff 100644
--- a/src/ccache.cpp
+++ b/src/ccache.cpp
@@ -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);
}
diff --git a/src/core/mainoptions.cpp b/src/core/mainoptions.cpp
index 1f6e651c..2283162f 100644
--- a/src/core/mainoptions.cpp
+++ b/src/core/mainoptions.cpp
@@ -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;
}
diff --git a/src/hashutil.cpp b/src/hashutil.cpp
index 990561ff..8d7151d6 100644
--- a/src/hashutil.cpp
+++ b/src/hashutil.cpp
@@ -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;
}
diff --git a/src/storage/local/StatsFile.cpp b/src/storage/local/StatsFile.cpp
index b00fc82e..4332d80e 100644
--- a/src/storage/local/StatsFile.cpp
+++ b/src/storage/local/StatsFile.cpp
@@ -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;
}
diff --git a/src/util/LockFile.cpp b/src/util/LockFile.cpp
index 0d7e96e8..f90b7626 100644
--- a/src/util/LockFile.cpp
+++ b/src/util/LockFile.cpp
@@ -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
diff --git a/src/util/file.cpp b/src/util/file.cpp
index 5ddc05bb..db0f4e83 100644
--- a/src/util/file.cpp
+++ b/src/util/file.cpp
@@ -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));
}