From: Joel Rosdahl Date: Wed, 19 Aug 2020 05:26:23 +0000 (+0200) Subject: Rename FatalError class to Fatal X-Git-Tag: v4.0~191 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bfd905c17c3a4d39f5c41994e823f90618c09c4f;p=thirdparty%2Fccache.git Rename FatalError class to Fatal This makes the naming more consistent with the other exception classes (Error and Failure). --- diff --git a/src/Logging.cpp b/src/Logging.cpp index b8ee4a395..04a6a4b47 100644 --- a/src/Logging.cpp +++ b/src/Logging.cpp @@ -68,7 +68,7 @@ bool debug_log_enabled = false; [[noreturn]] void print_fatal_error_and_exit() { - // Note: Can't throw FatalError since that would lead to recursion. + // Note: Can't throw Fatal since that would lead to recursion. fmt::print(stderr, "ccache: error: Failed to write to {}: {}\n", logfile_path, diff --git a/src/TemporaryFile.cpp b/src/TemporaryFile.cpp index 88814fa99..285654f48 100644 --- a/src/TemporaryFile.cpp +++ b/src/TemporaryFile.cpp @@ -63,13 +63,12 @@ TemporaryFile::TemporaryFile(string_view path_prefix) if (!initialize(path_prefix) && errno == ENOENT) { auto dir = Util::dir_name(path); if (!Util::create_dir(dir)) { - throw FatalError( - "Failed to create directory {}: {}", dir, strerror(errno)); + throw Fatal("Failed to create directory {}: {}", dir, strerror(errno)); } initialize(path_prefix); } if (!fd) { - throw FatalError( + throw Fatal( "Failed to create temporary file for {}: {}", path, strerror(errno)); } diff --git a/src/Util.cpp b/src/Util.cpp index 5c60c5525..755049320 100644 --- a/src/Util.cpp +++ b/src/Util.cpp @@ -661,8 +661,7 @@ get_home_directory() } } #endif - throw FatalError( - "Could not determine home directory from $HOME or getpwuid(3)"); + throw Fatal("Could not determine home directory from $HOME or getpwuid(3)"); } const char* diff --git a/src/Util.hpp b/src/Util.hpp index 44ad8599b..712f06ad9 100644 --- a/src/Util.hpp +++ b/src/Util.hpp @@ -195,7 +195,7 @@ void get_level_1_files(const std::string& dir, const ProgressReceiver& progress_receiver, std::vector>& files); -// Return the current user's home directory, or throw `FatalError` if it can't +// Return the current user's home directory, or throw `Fatal` if it can't // be determined. std::string get_home_directory(); diff --git a/src/ccache.cpp b/src/ccache.cpp index 734dae6a6..386594d82 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -164,7 +164,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 FatalError("{}: {}", word, strerror(errno)); + throw Fatal("{}: {}", word, strerror(errno)); } prefix.push_back(path); @@ -1707,10 +1707,10 @@ find_compiler(Context& ctx, const char* const* argv) std::string compiler = find_executable(ctx, base, CCACHE_NAME); if (compiler.empty()) { - throw FatalError("Could not find compiler \"{}\" in PATH", base); + throw Fatal("Could not find compiler \"{}\" in PATH", base); } if (compiler == argv[0]) { - throw FatalError( + throw Fatal( "Recursive invocation (the name of the ccache binary must be \"{}\")", CCACHE_NAME); } @@ -1977,7 +1977,7 @@ cache_compilation(int argc, const char* const* argv) log("Executing {}", Util::format_argv_for_logging(execv_argv.data())); ctx.reset(); // Dump debug logs last thing before executing. execv(execv_argv[0], const_cast(execv_argv.data())); - throw FatalError("execv of {} failed: {}", execv_argv[0], strerror(errno)); + throw Fatal("execv of {} failed: {}", execv_argv[0], strerror(errno)); } } diff --git a/src/exceptions.hpp b/src/exceptions.hpp index 3434af63b..defb1205c 100644 --- a/src/exceptions.hpp +++ b/src/exceptions.hpp @@ -38,7 +38,7 @@ class ErrorBase : public std::runtime_error // Throw an Error to indicate a potentially non-fatal error that may be caught // and handled by callers. An uncaught Error that reaches the top level will be -// treated similar to FatalError. +// treated similar to Fatal. class Error : public ErrorBase { public: @@ -59,24 +59,24 @@ inline Error::Error(T&&... args) { } -// Throw a FatalError to make ccache print the error message to stderr and exit +// Throw a Fatal to make ccache print the error message to stderr and exit // with a non-zero exit code. -class FatalError : public ErrorBase +class Fatal : public ErrorBase { public: // Special case: If given only one string, don't parse it as a format string. - FatalError(const std::string& message); + Fatal(const std::string& message); // `args` are forwarded to `fmt::format`. - template inline FatalError(T&&... args); + template inline Fatal(T&&... args); }; -inline FatalError::FatalError(const std::string& message) : ErrorBase(message) +inline Fatal::Fatal(const std::string& message) : ErrorBase(message) { } template -inline FatalError::FatalError(T&&... args) +inline Fatal::Fatal(T&&... args) : ErrorBase(fmt::format(std::forward(args)...)) { } diff --git a/src/execute.cpp b/src/execute.cpp index 7b647b7b1..c650c8525 100644 --- a/src/execute.cpp +++ b/src/execute.cpp @@ -166,7 +166,7 @@ execute(const char* const* argv, Fd&& fd_out, Fd&& fd_err, pid_t* pid) } if (*pid == -1) { - throw FatalError("Failed to fork: {}", strerror(errno)); + throw Fatal("Failed to fork: {}", strerror(errno)); } if (*pid == 0) { @@ -183,7 +183,7 @@ execute(const char* const* argv, Fd&& fd_out, Fd&& fd_err, pid_t* pid) int status; if (waitpid(*pid, &status, 0) != *pid) { - throw FatalError("waitpid failed: {}", strerror(errno)); + throw Fatal("waitpid failed: {}", strerror(errno)); } { diff --git a/src/hashutil.cpp b/src/hashutil.cpp index c8d13aaa5..67f6a5b2f 100644 --- a/src/hashutil.cpp +++ b/src/hashutil.cpp @@ -466,12 +466,12 @@ hash_command_output(Hash& hash, #else int pipefd[2]; if (pipe(pipefd) == -1) { - throw FatalError("pipe failed: {}", strerror(errno)); + throw Fatal("pipe failed: {}", strerror(errno)); } pid_t pid = fork(); if (pid == -1) { - throw FatalError("fork failed: {}", strerror(errno)); + throw Fatal("fork failed: {}", strerror(errno)); } if (pid == 0) {