From c5e1f88e22987365754e26c0f8a4e51cf572018f Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Wed, 2 Nov 2022 19:18:21 +0100 Subject: chore: Improve logging of file read failures --- src/Args.cpp | 2 ++ src/Depfile.cpp | 4 +++- src/ccache.cpp | 12 ++++++++---- src/core/mainoptions.cpp | 2 +- src/hashutil.cpp | 1 + src/storage/local/StatsFile.cpp | 2 +- src/util/LockFile.cpp | 2 +- src/util/file.cpp | 3 --- 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 #include #include #include @@ -51,6 +52,7 @@ Args::from_atfile(const std::string& filename, AtFileFormat format) { const auto argtext = util::read_file(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(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(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(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(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(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>(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(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(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)); } -- cgit v1.2.1