#include "assertions.hpp"
#include <core/exceptions.hpp>
+#include <fmtmacros.hpp>
AtomicFile::AtomicFile(const std::string& path, Mode mode) : m_path(path)
{
{
if (fwrite(data.data(), data.size(), 1, m_stream) != 1) {
throw core::Error(
- "failed to write data to {}: {}", m_path, strerror(errno));
+ FMT("failed to write data to {}: {}", m_path, strerror(errno)));
}
}
{
if (fwrite(data.data(), data.size(), 1, m_stream) != 1) {
throw core::Error(
- "failed to write data to {}: {}", m_path, strerror(errno));
+ FMT("failed to write data to {}: {}", m_path, strerror(errno)));
}
}
if (result == EOF) {
Util::unlink_tmp(m_tmp_path);
throw core::Error(
- "failed to write data to {}: {}", m_path, strerror(errno));
+ FMT("failed to write data to {}: {}", m_path, strerror(errno)));
}
Util::rename(m_tmp_path, m_path);
}
#include "MiniTrace.hpp"
#include "Util.hpp"
#include "assertions.hpp"
-#include "fmtmacros.hpp"
#include <UmaskScope.hpp>
#include <compression/types.hpp>
#include <core/exceptions.hpp>
#include <core/wincompat.hpp>
+#include <fmtmacros.hpp>
#include <util/expected.hpp>
#include <util/file.hpp>
#include <util/path.hpp>
if (value == "0" || lower_value == "false" || lower_value == "disable"
|| lower_value == "no") {
throw core::Error(
- "invalid boolean environment variable value \"{}\" (did you mean to"
- " set \"CCACHE_{}{}=true\"?)",
- value,
- negate ? "" : "NO",
- *env_var_key);
+ FMT("invalid boolean environment variable value \"{}\" (did you mean to"
+ " set \"CCACHE_{}{}=true\"?)",
+ value,
+ negate ? "" : "NO",
+ *env_var_key));
}
return !negate;
} else if (value == "true") {
} else if (value == "false") {
return false;
} else {
- throw core::Error("not a boolean value: \"{}\"", value);
+ throw core::Error(FMT("not a boolean value: \"{}\"", value));
}
}
verify_absolute_path(const std::string& value)
{
if (!util::is_absolute_path(value)) {
- throw core::Error("not an absolute path: \"{}\"", value);
+ throw core::Error(FMT("not an absolute path: \"{}\"", value));
}
}
}
config_line_handler(line, key, value);
} catch (const core::Error& e) {
- throw core::Error("{}:{}: {}", path, line_number, e.what());
+ throw core::Error(FMT("{}:{}: {}", path, line_number, e.what()));
}
}
return true;
try {
set_item(config_key, value, key, negate, "environment");
} catch (const core::Error& e) {
- throw core::Error("CCACHE_{}{}: {}", negate ? "NO" : "", key, e.what());
+ throw core::Error(
+ FMT("CCACHE_{}{}: {}", negate ? "NO" : "", key, e.what()));
}
}
}
{
auto it = k_config_key_table.find(key);
if (it == k_config_key_table.end()) {
- throw core::Error("unknown configuration option \"{}\"", key);
+ throw core::Error(FMT("unknown configuration option \"{}\"", key));
}
switch (it->second) {
UmaskScope umask_scope(m_umask);
if (k_config_key_table.find(key) == k_config_key_table.end()) {
- throw core::Error("unknown configuration option \"{}\"", key);
+ throw core::Error(FMT("unknown configuration option \"{}\"", key));
}
// Verify that the value is valid; set_item will throw if not.
const auto result = util::write_file(resolved_path, "");
if (!result) {
throw core::Error(
- "failed to write to {}: {}", resolved_path, result.error());
+ FMT("failed to write to {}: {}", resolved_path, result.error()));
}
}
output.write(FMT("{}\n", c_line));
}
})) {
- throw core::Error("failed to open {}: {}", path, strerror(errno));
+ throw core::Error(FMT("failed to open {}: {}", path, strerror(errno)));
}
if (!found) {
for (const auto& [key, value] : k_env_variable_table) {
if (k_config_key_table.find(value) == k_config_key_table.end()) {
throw core::Error(
- "env var {} mapped to {} which is missing from k_config_key_table",
- key,
- value);
+ FMT("env var {} mapped to {} which is missing from k_config_key_table",
+ key,
+ value));
}
}
}
#include "Logging.hpp"
#include "Stat.hpp"
#include "Util.hpp"
-#include "fmtmacros.hpp"
#include <ccache.hpp>
#include <core/CacheEntryReader.hpp>
#include <core/Statistic.hpp>
#include <core/exceptions.hpp>
#include <core/wincompat.hpp>
+#include <fmtmacros.hpp>
#include <util/path.hpp>
#include <fcntl.h>
// To support more entries in the future, encode to [0-9a-z]. Note that
// PrimaryStorage::evict currently assumes that the entry number is
// represented as one character.
- throw core::Error("Too high raw file entry number: {}", entry_number);
+ throw core::Error(FMT("Too high raw file entry number: {}", entry_number));
}
const auto prefix = result_path.substr(
Reader::read(Consumer& consumer)
{
if (m_reader.header().entry_type != core::CacheEntryType::result) {
- throw core::Error("Unexpected cache entry type: {}",
- to_string(m_reader.header().entry_type));
+ throw core::Error(FMT("Unexpected cache entry type: {}",
+ to_string(m_reader.header().entry_type)));
}
const auto result_format_version = m_reader.read_int<uint8_t>();
if (result_format_version != k_result_format_version) {
- throw core::Error("Unknown result format version: {}",
- result_format_version);
+ throw core::Error(
+ FMT("Unknown result format version: {}", result_format_version));
}
const auto n_entries = m_reader.read_int<uint8_t>();
if (n_entries >= k_max_raw_file_entries) {
- throw core::Error(
- "Too many raw file entries: {} > {}", n_entries, k_max_raw_file_entries);
+ throw core::Error(FMT(
+ "Too many raw file entries: {} > {}", n_entries, k_max_raw_file_entries));
}
uint8_t i;
}
if (i != n_entries) {
- throw core::Error("Too few entries (read {}, expected {})", i, n_entries);
+ throw core::Error(
+ FMT("Too few entries (read {}, expected {})", i, n_entries));
}
m_reader.finalize();
break;
default:
- throw core::Error("Unknown entry type: {}", marker);
+ throw core::Error(FMT("Unknown entry type: {}", marker));
}
const auto type = m_reader.read_int<UnderlyingFileTypeInt>();
auto st = Stat::stat(raw_path, Stat::OnError::throw_error);
if (st.size() != file_len) {
throw core::Error(
- "Bad file size of {} (actual {} bytes, expected {} bytes)",
- raw_path,
- st.size(),
- file_len);
+ FMT("Bad file size of {} (actual {} bytes, expected {} bytes)",
+ raw_path,
+ st.size(),
+ file_len));
}
}
{
Fd file(open(path.c_str(), O_RDONLY | O_BINARY));
if (!file) {
- throw core::Error("Failed to open {} for reading", path);
+ throw core::Error(FMT("Failed to open {} for reading", path));
}
uint64_t remain = file_size;
if (errno == EINTR) {
continue;
}
- throw core::Error("Error reading from {}: {}", path, strerror(errno));
+ throw core::Error(
+ FMT("Error reading from {}: {}", path, strerror(errno)));
}
if (bytes_read == 0) {
- throw core::Error("Error reading from {}: end of file", path);
+ throw core::Error(FMT("Error reading from {}: end of file", path));
}
writer.write(buf, bytes_read);
remain -= bytes_read;
Util::clone_hard_link_or_copy_file(m_ctx, path, raw_file, true);
} catch (core::Error& e) {
throw core::Error(
- "Failed to store {} as raw file {}: {}", path, raw_file, e.what());
+ FMT("Failed to store {} as raw file {}: {}", path, raw_file, e.what()));
}
const auto new_stat = Stat::stat(raw_file);
return {
#include <core/exceptions.hpp>
#include <core/wincompat.hpp>
+#include <fmtmacros.hpp>
#include <util/file.hpp>
#include <fcntl.h>
open(m_dest_path.c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666));
if (!m_dest_fd) {
throw core::Error(
- "Failed to open {} for writing: {}", m_dest_path, strerror(errno));
+ FMT("Failed to open {} for writing: {}", m_dest_path, strerror(errno)));
}
} else if (raw_file->empty()) {
PRINT_RAW(stderr,
Util::copy_file(*raw_file, m_dest_path, false);
} catch (core::Error& e) {
throw core::Error(
- "Failed to copy {} to {}: {}", *raw_file, m_dest_path, e.what());
+ FMT("Failed to copy {} to {}: {}", *raw_file, m_dest_path, e.what()));
}
}
}
const auto result = util::write_fd(*m_dest_fd, data, size);
if (!result) {
- throw core::Error("Failed to write to {}: {}", m_dest_path, result.error());
+ throw core::Error(
+ FMT("Failed to write to {}: {}", m_dest_path, result.error()));
}
}
-// Copyright (C) 2019-2021 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2022 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
#include <core/exceptions.hpp>
#include <core/wincompat.hpp>
+#include <fmtmacros.hpp>
#ifdef _WIN32
# include <third_party/win32/winerror_to_errno.h>
} else {
m_errno = errno;
if (on_error == OnError::throw_error) {
- throw core::Error("failed to stat {}: {}", path, strerror(errno));
+ throw core::Error(FMT("failed to stat {}: {}", path, strerror(errno)));
}
if (on_error == OnError::log) {
LOG("Failed to stat {}: {}", path, strerror(errno));
#endif
if (!fd) {
throw core::Fatal(
- "Failed to create temporary file for {}: {}", path, strerror(errno));
+ FMT("Failed to create temporary file for {}: {}", path, strerror(errno)));
}
Util::set_cloexec_flag(*fd);
#include "Logging.hpp"
#include "TemporaryFile.hpp"
#include "Win32Util.hpp"
-#include "fmtmacros.hpp"
#include <Finalizer.hpp>
#include <core/exceptions.hpp>
#include <core/wincompat.hpp>
+#include <fmtmacros.hpp>
#include <util/file.hpp>
#include <util/path.hpp>
#include <util/string.hpp>
# if defined(__linux__)
Fd src_fd(open(src.c_str(), O_RDONLY));
if (!src_fd) {
- throw core::Error("{}: {}", src, strerror(errno));
+ throw core::Error(FMT("{}: {}", src, strerror(errno)));
}
Fd dest_fd;
dest_fd =
Fd(open(dest.c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666));
if (!dest_fd) {
- throw core::Error("{}: {}", src, strerror(errno));
+ throw core::Error(FMT("{}: {}", src, strerror(errno)));
}
}
{
Fd src_fd(open(src.c_str(), O_RDONLY | O_BINARY));
if (!src_fd) {
- throw core::Error("{}: {}", src, strerror(errno));
+ throw core::Error(FMT("{}: {}", src, strerror(errno)));
}
Fd dest_fd;
dest_fd =
Fd(open(dest.c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666));
if (!dest_fd) {
- throw core::Error("{}: {}", dest, strerror(errno));
+ throw core::Error(FMT("{}: {}", dest, strerror(errno)));
}
}
++right;
}
if (curly && *right != '}') {
- throw core::Error("syntax error: missing '}}' after \"{}\"", left);
+ throw core::Error(FMT("syntax error: missing '}}' after \"{}\"", left));
}
if (right == left) {
// Special case: don't consider a single $ the left of a variable.
std::string name(left, right - left);
const char* value = getenv(name.c_str());
if (!value) {
- throw core::Error("environment variable \"{}\" not set", name);
+ throw core::Error(FMT("environment variable \"{}\" not set", name));
}
result += value;
if (!curly) {
{
if (!create_dir(dir)) {
throw core::Fatal(
- "Failed to create directory {}: {}", dir, strerror(errno));
+ FMT("Failed to create directory {}: {}", dir, strerror(errno)));
}
}
#ifndef _WIN32
if (link(oldpath.c_str(), newpath.c_str()) != 0) {
throw core::Error(
- "failed to link {} to {}: {}", oldpath, newpath, strerror(errno));
+ FMT("failed to link {} to {}: {}", oldpath, newpath, strerror(errno)));
}
#else
if (!CreateHardLink(newpath.c_str(), oldpath.c_str(), nullptr)) {
DWORD error = GetLastError();
- throw core::Error("failed to link {} to {}: {}",
- oldpath,
- newpath,
- Win32Util::error_message(error));
+ throw core::Error(FMT("failed to link {} to {}: {}",
+ oldpath,
+ newpath,
+ Win32Util::error_message(error)));
}
#endif
}
factor = 1;
break;
default:
- throw core::Error(
- "invalid suffix (supported: d (day) and s (second)): \"{}\"", duration);
+ throw core::Error(FMT(
+ "invalid suffix (supported: d (day) and s (second)): \"{}\"", duration));
}
const auto value =
char* p;
double result = strtod(value.c_str(), &p);
if (errno != 0 || result < 0 || p == value.c_str() || value.empty()) {
- throw core::Error("invalid size: \"{}\"", value);
+ throw core::Error(FMT("invalid size: \"{}\"", value));
}
while (isspace(*p)) {
result *= multiplier;
break;
default:
- throw core::Error("invalid size: \"{}\"", value);
+ throw core::Error(FMT("invalid size: \"{}\"", value));
}
} else {
// Default suffix: G.
#ifndef _WIN32
if (::rename(oldpath.c_str(), newpath.c_str()) != 0) {
throw core::Error(
- "failed to rename {} to {}: {}", oldpath, newpath, strerror(errno));
+ FMT("failed to rename {} to {}: {}", oldpath, newpath, strerror(errno)));
}
#else
// Windows' rename() won't overwrite an existing file, so need to use
if (!MoveFileExA(
oldpath.c_str(), newpath.c_str(), MOVEFILE_REPLACE_EXISTING)) {
DWORD error = GetLastError();
- throw core::Error("failed to rename {} to {}: {}",
- oldpath,
- newpath,
- Win32Util::error_message(error));
+ throw core::Error(FMT("failed to rename {} to {}: {}",
+ oldpath,
+ newpath,
+ Win32Util::error_message(error)));
}
#endif
}
const auto result =
util::write_fd(fd, text_to_send->data(), text_to_send->length());
if (!result) {
- throw core::Error("Failed to write to {}: {}", fd, result.error());
+ throw core::Error(FMT("Failed to write to {}: {}", fd, result.error()));
}
}
if (stat.error_number() == ENOENT || stat.error_number() == ESTALE) {
continue;
}
- throw core::Error("failed to lstat {}: {}",
- entry_path,
- strerror(stat.error_number()));
+ throw core::Error(FMT("failed to lstat {}: {}",
+ entry_path,
+ strerror(stat.error_number())));
}
is_dir = stat.is_directory();
}
} else if (errno == ENOTDIR) {
visitor(path, false);
} else {
- throw core::Error("failed to open directory {}: {}", path, strerror(errno));
+ throw core::Error(
+ FMT("failed to open directory {}: {}", path, strerror(errno)));
}
}
} else if (std::filesystem::exists(path)) {
visitor(path, false);
} else {
- throw core::Error("failed to open directory {}: {}", path, strerror(errno));
+ throw core::Error(
+ FMT("failed to open directory {}: {}", path, strerror(errno)));
}
}
traverse(path, [](const std::string& p, bool is_dir) {
if (is_dir) {
if (rmdir(p.c_str()) != 0 && errno != ENOENT && errno != ESTALE) {
- throw core::Error("failed to rmdir {}: {}", p, strerror(errno));
+ throw core::Error(FMT("failed to rmdir {}: {}", p, strerror(errno)));
}
} else if (unlink(p.c_str()) != 0 && errno != ENOENT && errno != ESTALE) {
- throw core::Error("failed to unlink {}: {}", p, strerror(errno));
+ throw core::Error(FMT("failed to unlink {}: {}", p, strerror(errno)));
}
});
}
for (const auto& word : Util::split_into_strings(prefix_command, " ")) {
std::string path = find_executable(ctx, word, ctx.orig_args[0]);
if (path.empty()) {
- throw core::Fatal("{}: {}", word, strerror(errno));
+ throw core::Fatal(FMT("{}: {}", word, strerror(errno)));
}
prefix.push_back(path);
try {
File file(*result_path, "rb");
if (!file) {
- throw core::Error("Failed to open {}: {}", *result_path, strerror(errno));
+ throw core::Error(
+ FMT("Failed to open {}: {}", *result_path, strerror(errno)));
}
core::FileReader file_reader(file.get());
core::CacheEntryReader cache_entry_reader(file_reader);
: find_executable_function(ctx, compiler, ctx.orig_args[0]);
if (resolved_compiler.empty()) {
- throw core::Fatal("Could not find compiler \"{}\" in PATH", compiler);
+ throw core::Fatal(FMT("Could not find compiler \"{}\" in PATH", compiler));
}
if (Util::is_ccache_executable(resolved_compiler)) {
auto execv_argv = saved_orig_args.to_argv();
execute_noreturn(execv_argv.data(), saved_temp_dir);
throw core::Fatal(
- "execute_noreturn of {} failed: {}", execv_argv[0], strerror(errno));
+ FMT("execute_noreturn of {} failed: {}", execv_argv[0], strerror(errno)));
}
return EXIT_SUCCESS;
-// Copyright (C) 2019-2021 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2022 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
#include <Context.hpp>
#include <assertions.hpp>
#include <core/exceptions.hpp>
+#include <fmtmacros.hpp>
namespace compression {
return Type::zstd;
}
- throw core::Error("Unknown type: {}", type);
+ throw core::Error(FMT("Unknown type: {}", type));
}
std::string
-// Copyright (C) 2019-2021 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2022 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
#include "CacheEntryReader.hpp"
#include <core/exceptions.hpp>
+#include <fmtmacros.hpp>
namespace {
return core::CacheEntryType::manifest;
break;
default:
- throw core::Error("Unknown entry type: {}", entry_type);
+ throw core::Error(FMT("Unknown entry type: {}", entry_type));
}
}
{
const auto magic = m_checksumming_reader.read_int<uint16_t>();
if (magic != core::k_ccache_magic) {
- throw core::Error("Bad magic value: 0x{:04x}", magic);
+ throw core::Error(FMT("Bad magic value: 0x{:04x}", magic));
}
const auto entry_format_version = m_checksumming_reader.read_int<uint8_t>();
if (entry_format_version != core::k_entry_format_version) {
- throw core::Error("Unknown entry format version: {}", entry_format_version);
+ throw core::Error(
+ FMT("Unknown entry format version: {}", entry_format_version));
}
const auto entry_type = m_checksumming_reader.read_int<uint8_t>();
const util::XXH3_128::Digest null_digest;
if (actual != expected && actual != null_digest && expected != null_digest) {
- throw core::Error("Incorrect checksum (actual {}, expected {})",
- Util::format_base16(actual.bytes(), actual.size()),
- Util::format_base16(expected.bytes(), expected.size()));
+ throw core::Error(
+ FMT("Incorrect checksum (actual {}, expected {})",
+ Util::format_base16(actual.bytes(), actual.size()),
+ Util::format_base16(expected.bytes(), expected.size())));
}
m_decompressor->finalize();
const auto format_version = reader.read_int<uint8_t>();
if (format_version != k_format_version) {
- throw core::Error(
- "Unknown format version: {} != {}", format_version, k_format_version);
+ throw core::Error(FMT(
+ "Unknown format version: {} != {}", format_version, k_format_version));
}
const auto file_count = reader.read_int<uint32_t>();
// treated similar to Fatal.
class Error : public ErrorBase
{
-public:
- // Special case: If given only one string, don't parse it as a format string.
- Error(const std::string& message);
-
- // `args` are forwarded to `fmt::format`.
- template<typename... T> inline Error(const char* format, T&&... args);
+ using ErrorBase::ErrorBase;
};
-inline Error::Error(const std::string& message) : ErrorBase(message)
-{
-}
-
-template<typename... T>
-inline Error::Error(const char* format, T&&... args)
- : ErrorBase(fmt::format(format, std::forward<T>(args)...))
-{
-}
-
// Throw a Fatal to make ccache print the error message to stderr and exit
// with a non-zero exit code.
class Fatal : public ErrorBase
{
-public:
- // Special case: If given only one string, don't parse it as a format string.
- Fatal(const std::string& message);
-
- // `args` are forwarded to `fmt::format`.
- template<typename... T> inline Fatal(const char* format, T&&... args);
+ using ErrorBase::ErrorBase;
};
-inline Fatal::Fatal(const std::string& message) : ErrorBase(message)
-{
-}
-
-template<typename... T>
-inline Fatal::Fatal(const char* format, T&&... args)
- : ErrorBase(fmt::format(format, std::forward<T>(args)...))
-{
-}
-
} // namespace core
if (!is_dir) {
const auto name = Util::base_name(path);
if (name == "ccache.conf" || name == "stats") {
- throw Fatal("this looks like a primary cache directory (found {})",
- path);
+ throw Fatal(
+ FMT("this looks like a primary cache directory (found {})", path));
}
files.push_back({path, stat});
}
// 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 Error(FMT("missing equal sign in \"{}\"", arg));
}
std::string key = arg.substr(0, eq_pos);
std::string value = arg.substr(eq_pos + 1);
#include "TemporaryFile.hpp"
#include "Util.hpp"
#include "Win32Util.hpp"
-#include "fmtmacros.hpp"
#include <core/exceptions.hpp>
#include <core/wincompat.hpp>
+#include <fmtmacros.hpp>
#include <util/file.hpp>
#include <util/path.hpp>
}
if (ctx.compiler_pid == -1) {
- throw core::Fatal("Failed to fork: {}", strerror(errno));
+ throw core::Fatal(FMT("Failed to fork: {}", strerror(errno)));
}
if (ctx.compiler_pid == 0) {
if (result == -1 && errno == EINTR) {
continue;
}
- throw core::Fatal("waitpid failed: {}", strerror(errno));
+ throw core::Fatal(FMT("waitpid failed: {}", strerror(errno)));
}
{
#include "Util.hpp"
#include "Win32Util.hpp"
#include "execute.hpp"
-#include "fmtmacros.hpp"
#include "macroskip.hpp"
#include <core/exceptions.hpp>
#include <core/wincompat.hpp>
+#include <fmtmacros.hpp>
#include <util/file.hpp>
#include <util/string.hpp>
#else
int pipefd[2];
if (pipe(pipefd) == -1) {
- throw core::Fatal("pipe failed: {}", strerror(errno));
+ throw core::Fatal(FMT("pipe failed: {}", strerror(errno)));
}
pid_t pid = fork();
if (pid == -1) {
- throw core::Fatal("fork failed: {}", strerror(errno));
+ throw core::Fatal(FMT("fork failed: {}", strerror(errno)));
}
if (pid == 0) {
Util::split_into_views(entry, "|", util::Tokenizer::Mode::include_empty);
if (parts.empty() || parts.front().empty()) {
- throw core::Error("secondary storage config must provide a URL: {}", entry);
+ throw core::Error(
+ FMT("secondary storage config must provide a URL: {}", entry));
}
SecondaryStorageConfig result;
try {
std::ignore = result.params.url.str();
} catch (const std::exception& e) {
- throw core::Error("Cannot parse URL {}: {}", url_str, e.what());
+ throw core::Error(FMT("Cannot parse URL {}: {}", url_str, e.what()));
}
if (result.params.url.scheme().empty()) {
- throw core::Error("URL scheme must not be empty: {}", entry);
+ throw core::Error(FMT("URL scheme must not be empty: {}", entry));
}
for (size_t i = 1; i < parts.size(); ++i) {
result.read_only = (value == "true");
} else if (key == "shards") {
if (url_str.find('*') == std::string::npos) {
- throw core::Error(R"(Missing "*" in URL when using shards: "{}")",
- url_str);
+ throw core::Error(
+ FMT(R"(Missing "*" in URL when using shards: "{}")", url_str));
}
for (const auto& shard : util::Tokenizer(value, ",")) {
double weight = 1.0;
const auto lp_pos = shard.find('(');
if (lp_pos != std::string_view::npos) {
if (shard.back() != ')') {
- throw core::Error("Invalid shard name: \"{}\"", shard);
+ throw core::Error(FMT("Invalid shard name: \"{}\"", shard));
}
weight =
util::value_or_throw<core::Error>(util::parse_double(std::string(
shard.substr(lp_pos + 1, shard.length() - lp_pos - 2))));
if (weight < 0.0) {
- throw core::Error("Invalid shard weight: \"{}\"", weight);
+ throw core::Error(FMT("Invalid shard weight: \"{}\"", weight));
}
name = shard.substr(0, lp_pos);
} else {
try {
util::write_file(tmp_file.path, value);
} catch (const core::Error& e) {
- throw core::Fatal("Error writing to {}: {}", tmp_file.path, e.what());
+ throw core::Fatal(FMT("Error writing to {}: {}", tmp_file.path, e.what()));
}
if (share_hits) {
redact_url_for_logging(url_for_logging);
const auto storage = get_storage(config.params.url);
if (!storage) {
- throw core::Error("unknown secondary storage URL: {}",
- url_for_logging.str());
+ throw core::Error(
+ FMT("unknown secondary storage URL: {}", url_for_logging.str()));
}
m_secondary_storages.push_back(std::make_unique<SecondaryStorageEntry>(
SecondaryStorageEntry{config, url_for_logging.str(), storage, {}}));
File f(path, mode);
if (!f) {
throw core::Error(
- "failed to open {} for reading: {}", path, strerror(errno));
+ FMT("failed to open {} for reading: {}", path, strerror(errno)));
}
return f;
}
create_reader(const CacheFile& cache_file, core::Reader& reader)
{
if (cache_file.type() == CacheFile::Type::unknown) {
- throw core::Error("unknown file type for {}", cache_file.path());
+ throw core::Error(FMT("unknown file type for {}", cache_file.path()));
}
return std::make_unique<core::CacheEntryReader>(reader);
get_url(const Url& url)
{
if (url.host().empty()) {
- throw core::Fatal("A host is required in HTTP storage URL \"{}\"",
- url.str());
+ throw core::Fatal(
+ FMT("A host is required in HTTP storage URL \"{}\"", url.str()));
}
// httplib requires a partial URL with just scheme, host and port.
if (!params.url.user_info().empty()) {
const auto [user, password] = util::split_once(params.url.user_info(), ':');
if (!password) {
- throw core::Fatal("Expected username:password in URL but got \"{}\"",
- params.url.user_info());
+ throw core::Fatal(FMT("Expected username:password in URL but got \"{}\"",
+ params.url.user_info()));
}
m_http_client.set_basic_auth(std::string(user), std::string(*password));
}
-// Copyright (C) 2020-2021 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2022 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
#include "TestUtil.hpp"
#include "../src/Util.hpp"
-#include "../src/fmtmacros.hpp"
#include <core/exceptions.hpp>
#include <core/wincompat.hpp>
+#include <fmtmacros.hpp>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
{
if (chdir(dir.c_str()) != 0) {
throw core::Error(
- "failed to change directory to {}: {}", dir, strerror(errno));
+ FMT("failed to change directory to {}: {}", dir, strerror(errno)));
}
}