#include "Util.hpp"
+#include <core/exceptions.hpp>
#include <util/string.hpp>
using nonstd::nullopt;
std::string argtext;
try {
argtext = Util::read_file(filename);
- } catch (Error&) {
+ } catch (core::Error&) {
return nullopt;
}
-// Copyright (C) 2019-2020 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2021 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
#include "TemporaryFile.hpp"
#include "Util.hpp"
#include "assertions.hpp"
-#include "exceptions.hpp"
+
+#include <core/exceptions.hpp>
AtomicFile::AtomicFile(const std::string& path, Mode mode) : m_path(path)
{
AtomicFile::write(const std::string& data)
{
if (fwrite(data.data(), data.size(), 1, m_stream) != 1) {
- throw Error("failed to write data to {}: {}", m_path, strerror(errno));
+ throw core::Error(
+ "failed to write data to {}: {}", m_path, strerror(errno));
}
}
AtomicFile::write(const std::vector<uint8_t>& data)
{
if (fwrite(data.data(), data.size(), 1, m_stream) != 1) {
- throw Error("failed to write data to {}: {}", m_path, strerror(errno));
+ throw core::Error(
+ "failed to write data to {}: {}", m_path, strerror(errno));
}
}
m_stream = nullptr;
if (result == EOF) {
Util::unlink_tmp(m_tmp_path);
- throw Error("failed to write data to {}: {}", m_path, strerror(errno));
+ throw core::Error(
+ "failed to write data to {}: {}", m_path, strerror(errno));
}
Util::rename(m_tmp_path, m_path);
}
#include "CacheEntryReader.hpp"
#include "Compressor.hpp"
-#include "exceptions.hpp"
#include "fmtmacros.hpp"
+#include <core/exceptions.hpp>
+
#include "third_party/fmt/core.h"
CacheEntryReader::CacheEntryReader(FILE* stream,
{
uint8_t header_bytes[15];
if (fread(header_bytes, sizeof(header_bytes), 1, stream) != 1) {
- throw Error("Error reading header");
+ throw core::Error("Error reading header");
}
memcpy(m_magic, header_bytes, sizeof(m_magic));
Util::big_endian_to_int(header_bytes + 7, m_content_size);
if (memcmp(m_magic, expected_magic, sizeof(m_magic)) != 0) {
- throw Error("Bad magic value 0x{:02x}{:02x}{:02x}{:02x}",
- m_magic[0],
- m_magic[1],
- m_magic[2],
- m_magic[3]);
+ throw core::Error("Bad magic value 0x{:02x}{:02x}{:02x}{:02x}",
+ m_magic[0],
+ m_magic[1],
+ m_magic[2],
+ m_magic[3]);
}
if (m_version != expected_version) {
- throw Error(
+ throw core::Error(
"Unknown version (actual {}, expected {})", m_version, expected_version);
}
Util::big_endian_to_int(buffer, expected_digest);
if (actual_digest != expected_digest) {
- throw Error("Incorrect checksum (actual 0x{:016x}, expected 0x{:016x})",
- actual_digest,
- expected_digest);
+ throw core::Error(
+ "Incorrect checksum (actual 0x{:016x}, expected 0x{:016x})",
+ actual_digest,
+ expected_digest);
}
m_decompressor->finalize();
#include "CacheEntryWriter.hpp"
+#include <core/exceptions.hpp>
+
CacheEntryWriter::CacheEntryWriter(FILE* stream,
const uint8_t* magic,
uint8_t version,
uint64_t content_size = 15 + payload_size + 8;
Util::int_to_big_endian(content_size, header_bytes + 7);
if (fwrite(header_bytes, sizeof(header_bytes), 1, stream) != 1) {
- throw Error("Failed to write cache entry header");
+ throw core::Error("Failed to write cache entry header");
}
m_checksum.update(header_bytes, sizeof(header_bytes));
}
-// Copyright (C) 2019-2020 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2021 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
#include "Config.hpp"
#include "Context.hpp"
#include "assertions.hpp"
-#include "exceptions.hpp"
+
+#include <core/exceptions.hpp>
namespace Compression {
return Type::zstd;
}
- throw Error("Unknown type: {}", type);
+ throw core::Error("Unknown type: {}", type);
}
std::string
#include "Sloppiness.hpp"
#include "Util.hpp"
#include "assertions.hpp"
-#include "exceptions.hpp"
#include "fmtmacros.hpp"
+#include <core/exceptions.hpp>
#include <core/wincompat.hpp>
#include <util/expected.hpp>
#include <util/path.hpp>
std::string lower_value = Util::to_lowercase(value);
if (value == "0" || lower_value == "false" || lower_value == "disable"
|| lower_value == "no") {
- throw Error(
+ throw core::Error(
"invalid boolean environment variable value \"{}\" (did you mean to"
" set \"CCACHE_{}{}=true\"?)",
value,
} else if (value == "false") {
return false;
} else {
- throw Error("not a boolean value: \"{}\"", value);
+ throw core::Error("not a boolean value: \"{}\"", value);
}
}
try {
result = std::stod(value, &end);
} catch (std::exception& e) {
- throw Error(e.what());
+ throw core::Error(e.what());
}
if (end != value.size()) {
- throw Error("invalid floating point: \"{}\"", value);
+ throw core::Error("invalid floating point: \"{}\"", value);
}
return result;
}
verify_absolute_path(const std::string& value)
{
if (!util::is_absolute_path(value)) {
- throw Error("not an absolute path: \"{}\"", value);
+ throw core::Error("not an absolute path: \"{}\"", value);
}
}
std::string value;
std::string error_message;
if (!parse_line(line, &key, &value, &error_message)) {
- throw Error(error_message);
+ throw core::Error(error_message);
}
config_line_handler(line, key, value);
- } catch (const Error& e) {
- throw Error("{}:{}: {}", path, line_number, e.what());
+ } catch (const core::Error& e) {
+ throw core::Error("{}:{}: {}", path, line_number, e.what());
}
}
return true;
try {
set_item(config_key, value, key, negate, "environment");
- } catch (const Error& e) {
- throw Error("CCACHE_{}{}: {}", negate ? "NO" : "", key, e.what());
+ } catch (const core::Error& e) {
+ throw core::Error("CCACHE_{}{}: {}", negate ? "NO" : "", key, e.what());
}
}
}
{
auto it = k_config_key_table.find(key);
if (it == k_config_key_table.end()) {
- throw Error("unknown configuration option \"{}\"", key);
+ throw core::Error("unknown configuration option \"{}\"", key);
}
switch (it->second) {
const std::string& value)
{
if (k_config_key_table.find(key) == k_config_key_table.end()) {
- throw Error("unknown configuration option \"{}\"", key);
+ throw core::Error("unknown configuration option \"{}\"", key);
}
// Verify that the value is valid; set_item will throw if not.
Util::ensure_dir_exists(Util::dir_name(resolved_path));
try {
Util::write_file(resolved_path, "");
- } catch (const Error& e) {
- throw Error("failed to write to {}: {}", resolved_path, e.what());
+ } catch (const core::Error& e) {
+ throw core::Error("failed to write to {}: {}", resolved_path, e.what());
}
}
output.write(FMT("{}\n", c_line));
}
})) {
- throw Error("failed to open {}: {}", path, strerror(errno));
+ throw core::Error("failed to open {}: {}", path, strerror(errno));
}
if (!found) {
break;
case ConfigItem::compression_level:
- m_compression_level = util::value_or_throw<Error>(
+ m_compression_level = util::value_or_throw<core::Error>(
util::parse_signed(value, INT8_MIN, INT8_MAX, "compression_level"));
break;
break;
case ConfigItem::max_files:
- m_max_files = util::value_or_throw<Error>(
+ m_max_files = util::value_or_throw<core::Error>(
util::parse_unsigned(value, nullopt, nullopt, "max_files"));
break;
if (!value.empty()) {
const auto umask = util::parse_umask(value);
if (!umask) {
- throw Error(umask.error());
+ throw core::Error(umask.error());
}
m_umask = *umask;
}
{
for (const auto& item : k_env_variable_table) {
if (k_config_key_table.find(item.second) == k_config_key_table.end()) {
- throw Error(
+ throw core::Error(
"env var {} mapped to {} which is missing from k_config_key_table",
item.first,
item.second);
#include "Logging.hpp"
#include "assertions.hpp"
+#include <core/exceptions.hpp>
#include <util/path.hpp>
static inline bool
std::string file_content;
try {
file_content = Util::read_file(output_dep);
- } catch (const Error& e) {
+ } catch (const core::Error& e) {
LOG("Cannot open dependency file {}: {}", output_dep, e.what());
return;
}
#include "File.hpp"
#include "Util.hpp"
#include "Win32Util.hpp"
-#include "exceptions.hpp"
#include "execute.hpp"
#include "fmtmacros.hpp"
#include "fmtmacros.hpp"
#include "hashutil.hpp"
+#include <core/exceptions.hpp>
+
#include <memory>
// Manifest data format
LOG_RAW("No such manifest file");
return nullopt;
}
- } catch (const Error& e) {
+ } catch (const core::Error& e) {
LOG("Error: {}", e.what());
return nullopt;
}
// Manifest file didn't exist.
mf = std::make_unique<ManifestData>();
}
- } catch (const Error& e) {
+ } catch (const core::Error& e) {
LOG("Error: {}", e.what());
// Manifest file was corrupt, ignore.
mf = std::make_unique<ManifestData>();
try {
write_manifest(config, path, *mf);
return true;
- } catch (const Error& e) {
+ } catch (const core::Error& e) {
LOG("Error: {}", e.what());
}
} else {
std::unique_ptr<ManifestData> mf;
try {
mf = read_manifest(path, stream);
- } catch (const Error& e) {
+ } catch (const core::Error& e) {
PRINT(stream, "Error: {}\n", e.what());
return false;
}
-// Copyright (C) 2019-2020 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2021 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
#include "NullCompressor.hpp"
-#include "exceptions.hpp"
+#include <core/exceptions.hpp>
NullCompressor::NullCompressor(FILE* stream) : m_stream(stream)
{
NullCompressor::write(const void* data, size_t count)
{
if (fwrite(data, 1, count, m_stream) != count) {
- throw Error("failed to write to uncompressed stream");
+ throw core::Error("failed to write to uncompressed stream");
}
}
NullCompressor::finalize()
{
if (fflush(m_stream) != 0) {
- throw Error("failed to finalize uncompressed stream");
+ throw core::Error("failed to finalize uncompressed stream");
}
}
-// Copyright (C) 2019 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2021 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
#include "NullDecompressor.hpp"
-#include "exceptions.hpp"
+#include <core/exceptions.hpp>
NullDecompressor::NullDecompressor(FILE* stream) : m_stream(stream)
{
NullDecompressor::read(void* data, size_t count)
{
if (fread(data, count, 1, m_stream) != 1) {
- throw Error("failed to read from uncompressed stream");
+ throw core::Error("failed to read from uncompressed stream");
}
}
NullDecompressor::finalize()
{
if (fgetc(m_stream) != EOF) {
- throw Error("garbage data at end of uncompressed stream");
+ throw core::Error("garbage data at end of uncompressed stream");
}
}
#include "Stat.hpp"
#include "Statistic.hpp"
#include "Util.hpp"
-#include "exceptions.hpp"
#include "fmtmacros.hpp"
+#include <core/exceptions.hpp>
#include <core/wincompat.hpp>
#include <util/path.hpp>
} else {
return "No such result file";
}
- } catch (const Error& e) {
+ } catch (const core::Error& e) {
return e.what();
}
}
}
if (i != n_entries) {
- throw Error("Too few entries (read {}, expected {})", i, n_entries);
+ throw core::Error("Too few entries (read {}, expected {})", i, n_entries);
}
cache_entry_reader.finalize();
break;
default:
- throw Error("Unknown entry type: {}", marker);
+ throw core::Error("Unknown entry type: {}", marker);
}
UnderlyingFileTypeInt type;
auto raw_path = get_raw_file_path(m_result_path, entry_number);
auto st = Stat::stat(raw_path, Stat::OnError::throw_error);
if (st.size() != file_len) {
- throw Error("Bad file size of {} (actual {} bytes, expected {} bytes)",
- raw_path,
- st.size(),
- file_len);
+ throw core::Error(
+ "Bad file size of {} (actual {} bytes, expected {} bytes)",
+ raw_path,
+ st.size(),
+ file_len);
}
consumer.on_entry_start(entry_number, file_type, file_len, raw_path);
{
try {
return do_finalize();
- } catch (const Error& e) {
+ } catch (const core::Error& e) {
return nonstd::make_unexpected(e.what());
}
}
{
Fd file(open(path.c_str(), O_RDONLY | O_BINARY));
if (!file) {
- throw Error("Failed to open {} for reading", path);
+ throw core::Error("Failed to open {} for reading", path);
}
uint64_t remain = file_size;
if (errno == EINTR) {
continue;
}
- throw Error("Error reading from {}: {}", path, strerror(errno));
+ throw core::Error("Error reading from {}: {}", path, strerror(errno));
}
if (bytes_read == 0) {
- throw Error("Error reading from {}: end of file", path);
+ throw core::Error("Error reading from {}: end of file", path);
}
writer.write(buf, bytes_read);
remain -= bytes_read;
const auto old_stat = Stat::stat(raw_file);
try {
Util::clone_hard_link_or_copy_file(m_ctx, path, raw_file, true);
- } catch (Error& e) {
- throw Error(
+ } catch (core::Error& e) {
+ throw core::Error(
"Failed to store {} as raw file {}: {}", path, raw_file, e.what());
}
const auto new_stat = Stat::stat(raw_file);
#include "Util.hpp"
#include "fmtmacros.hpp"
+#include <core/exceptions.hpp>
#include <core/wincompat.hpp>
#include <fcntl.h>
m_dest_fd = Fd(
open(m_dest_path.c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666));
if (!m_dest_fd) {
- throw Error(
+ throw core::Error(
"Failed to open {} for writing: {}", m_dest_path, strerror(errno));
}
} else {
try {
Util::copy_file(*raw_file, m_dest_path, false);
- } catch (Error& e) {
- throw Error(
+ } catch (core::Error& e) {
+ throw core::Error(
"Failed to copy {} to {}: {}", *raw_file, m_dest_path, e.what());
}
}
try {
Util::write_fd(*m_dest_fd, data, size);
- } catch (Error& e) {
- throw Error("Failed to write to {}: {}", m_dest_path, e.what());
+ } catch (core::Error& e) {
+ throw core::Error("Failed to write to {}: {}", m_dest_path, e.what());
}
}
#include "Depfile.hpp"
#include "Logging.hpp"
+#include <core/exceptions.hpp>
#include <core/wincompat.hpp>
#include <fcntl.h>
m_dest_fd = Fd(
open(dest_path.c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666));
if (!m_dest_fd) {
- throw Error(
+ throw core::Error(
"Failed to open {} for writing: {}", dest_path, strerror(errno));
}
m_dest_path = dest_path;
} else if (m_dest_fd) {
try {
Util::write_fd(*m_dest_fd, data, size);
- } catch (Error& e) {
- throw Error("Failed to write to {}: {}", m_dest_path, e.what());
+ } catch (core::Error& e) {
+ throw core::Error("Failed to write to {}: {}", m_dest_path, e.what());
}
}
}
Util::write_fd(*m_dest_fd,
m_dest_data.data() + start_pos,
m_dest_data.length() - start_pos);
- } catch (Error& e) {
- throw Error("Failed to write to {}: {}", m_dest_path, e.what());
+ } catch (core::Error& e) {
+ throw core::Error("Failed to write to {}: {}", m_dest_path, e.what());
}
}
#include "Logging.hpp"
#include "Win32Util.hpp"
+#include <core/exceptions.hpp>
#include <core/wincompat.hpp>
#ifdef _WIN32
} else {
m_errno = errno;
if (on_error == OnError::throw_error) {
- throw Error("failed to stat {}: {}", path, strerror(errno));
+ throw core::Error("failed to stat {}: {}", path, strerror(errno));
}
if (on_error == OnError::log) {
LOG("Failed to stat {}: {}", path, strerror(errno));
#pragma once
-#include "exceptions.hpp"
+#include <core/wincompat.hpp>
#include <sys/stat.h>
#include <sys/types.h>
+#include <ctime>
#include <string>
#ifdef _WIN32
#include "Logging.hpp"
#include "Util.hpp"
#include "assertions.hpp"
-#include "exceptions.hpp"
#include "fmtmacros.hpp"
+#include <core/exceptions.hpp>
+
#include <fstream>
#include <unordered_map>
std::string data;
try {
data = Util::read_file(path);
- } catch (const Error&) {
+ } catch (const core::Error&) {
// Ignore.
return counters;
}
}
try {
file.commit();
- } catch (const Error& e) {
+ } catch (const core::Error& e) {
// Make failure to write a stats file a soft error since it's not
// important enough to fail whole the process and also because it is
// called in the Context destructor.
#include "Util.hpp"
+#include <core/exceptions.hpp>
+
#ifdef _WIN32
# include "third_party/win32/mktemp.h"
#endif
fd = Fd(mkstemp(&path[0]));
#endif
if (!fd) {
- throw Fatal(
+ throw core::Fatal(
"Failed to create temporary file for {}: {}", path, strerror(errno));
}
#include "Config.hpp"
#include "Context.hpp"
#include "Fd.hpp"
-#include "FormatNonstdStringView.hpp"
#include "Logging.hpp"
#include "TemporaryFile.hpp"
#include "Win32Util.hpp"
#include "fmtmacros.hpp"
+#include <core/exceptions.hpp>
#include <core/wincompat.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 Error("{}: {}", src, strerror(errno));
+ throw core::Error("{}: {}", 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 Error("{}: {}", src, strerror(errno));
+ throw core::Error("{}: {}", src, strerror(errno));
}
}
if (ioctl(*dest_fd, FICLONE, *src_fd) != 0) {
- throw Error(strerror(errno));
+ throw core::Error(strerror(errno));
}
dest_fd.close();
# elif defined(__APPLE__)
(void)via_tmp_file;
if (clonefile(src.c_str(), dest.c_str(), CLONE_NOOWNERCOPY) != 0) {
- throw Error(strerror(errno));
+ throw core::Error(strerror(errno));
}
# else
(void)src;
(void)dest;
(void)via_tmp_file;
- throw Error(strerror(EOPNOTSUPP));
+ throw core::Error(strerror(EOPNOTSUPP));
# endif
}
#endif // FILE_CLONING_SUPPORTED
try {
clone_file(source, dest, via_tmp_file);
return;
- } catch (Error& e) {
+ } catch (core::Error& e) {
LOG("Failed to clone: {}", e.what());
}
#else
LOG("Failed to chmod: {}", strerror(errno));
}
return;
- } catch (const Error& e) {
+ } catch (const core::Error& e) {
LOG_RAW(e.what());
// Fall back to copying.
}
{
Fd src_fd(open(src.c_str(), O_RDONLY));
if (!src_fd) {
- throw Error("{}: {}", src, strerror(errno));
+ throw core::Error("{}: {}", 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 Error("{}: {}", dest, strerror(errno));
+ throw core::Error("{}: {}", dest, strerror(errno));
}
}
++right;
}
if (curly && *right != '}') {
- throw Error("syntax error: missing '}}' after \"{}\"", left);
+ throw core::Error("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 Error("environment variable \"{}\" not set", name);
+ throw core::Error("environment variable \"{}\" not set", name);
}
result += value;
if (!curly) {
int err = 0;
try {
write_fd(fd, buf, bytes_to_write);
- } catch (Error&) {
+ } catch (core::Error&) {
err = errno;
}
lseek(fd, saved_pos, SEEK_SET);
ensure_dir_exists(nonstd::string_view dir)
{
if (!create_dir(dir)) {
- throw Fatal("Failed to create directory {}: {}", dir, strerror(errno));
+ throw core::Fatal(
+ "Failed to create directory {}: {}", dir, strerror(errno));
}
}
}
}
#endif
- throw Fatal("Could not determine home directory from $HOME or getpwuid(3)");
+ throw core::Fatal(
+ "Could not determine home directory from $HOME or getpwuid(3)");
}
const char*
#ifndef _WIN32
if (link(oldpath.c_str(), newpath.c_str()) != 0) {
- throw Error(
+ throw core::Error(
"failed to link {} to {}: {}", oldpath, newpath, strerror(errno));
}
#else
if (!CreateHardLink(newpath.c_str(), oldpath.c_str(), nullptr)) {
DWORD error = GetLastError();
- throw Error("failed to link {} to {}: {}",
- oldpath,
- newpath,
- Win32Util::error_message(error));
+ throw core::Error("failed to link {} to {}: {}",
+ oldpath,
+ newpath,
+ Win32Util::error_message(error));
}
#endif
}
factor = 1;
break;
default:
- throw Error("invalid suffix (supported: d (day) and s (second)): \"{}\"",
- duration);
+ throw core::Error(
+ "invalid suffix (supported: d (day) and s (second)): \"{}\"", duration);
}
const auto value =
if (value) {
return factor * *value;
} else {
- throw Error(value.error());
+ throw core::Error(value.error());
}
}
char* p;
double result = strtod(value.c_str(), &p);
if (errno != 0 || result < 0 || p == value.c_str() || value.empty()) {
- throw Error("invalid size: \"{}\"", value);
+ throw core::Error("invalid size: \"{}\"", value);
}
while (isspace(*p)) {
result *= multiplier;
break;
default:
- throw Error("invalid size: \"{}\"", value);
+ throw core::Error("invalid size: \"{}\"", value);
}
} else {
// Default suffix: G.
if (size_hint == 0) {
auto stat = Stat::stat(path);
if (!stat) {
- throw Error(strerror(errno));
+ throw core::Error(strerror(errno));
}
size_hint = stat.size();
}
Fd fd(open(path.c_str(), O_RDONLY | O_BINARY));
if (!fd) {
- throw Error(strerror(errno));
+ throw core::Error(strerror(errno));
}
ssize_t ret = 0;
if (ret == -1) {
LOG("Failed reading {}", path);
- throw Error(strerror(errno));
+ throw core::Error(strerror(errno));
}
result.resize(pos);
{
#ifndef _WIN32
if (::rename(oldpath.c_str(), newpath.c_str()) != 0) {
- throw Error(
+ throw core::Error(
"failed to rename {} to {}: {}", oldpath, newpath, strerror(errno));
}
#else
if (!MoveFileExA(
oldpath.c_str(), newpath.c_str(), MOVEFILE_REPLACE_EXISTING)) {
DWORD error = GetLastError();
- throw Error("failed to rename {} to {}: {}",
- oldpath,
- newpath,
- Win32Util::error_message(error));
+ throw core::Error("failed to rename {} to {}: {}",
+ oldpath,
+ newpath,
+ Win32Util::error_message(error));
}
#endif
}
try {
modified_text = strip_ansi_csi_seqs(text);
text_to_send = &modified_text;
- } catch (const Error&) {
+ } catch (const core::Error&) {
// Fall through
}
}
try {
write_fd(STDERR_FILENO, text_to_send->data(), text_to_send->length());
- } catch (Error& e) {
- throw Error("Failed to write to stderr: {}", e.what());
+ } catch (core::Error& e) {
+ throw core::Error("Failed to write to stderr: {}", e.what());
}
}
if (stat.error_number() == ENOENT || stat.error_number() == ESTALE) {
continue;
}
- throw Error("failed to lstat {}: {}",
- entry_path,
- strerror(stat.error_number()));
+ throw core::Error("failed to lstat {}: {}",
+ entry_path,
+ strerror(stat.error_number()));
}
is_dir = stat.is_directory();
}
} else if (errno == ENOTDIR) {
visitor(path, false);
} else {
- throw Error("failed to open directory {}: {}", path, strerror(errno));
+ throw core::Error("failed to open directory {}: {}", path, strerror(errno));
}
}
} else if (std::filesystem::exists(path)) {
visitor(path, false);
} else {
- throw Error("failed to open directory {}: {}", path, strerror(errno));
+ throw core::Error("failed to open directory {}: {}", path, strerror(errno));
}
}
bool success = true;
try {
Util::rename(path, tmp_name);
- } catch (Error&) {
+ } catch (core::Error&) {
success = false;
saved_errno = errno;
}
traverse(path, [](const std::string& p, bool is_dir) {
if (is_dir) {
if (rmdir(p.c_str()) != 0 && errno != ENOENT && errno != ESTALE) {
- throw Error("failed to rmdir {}: {}", p, strerror(errno));
+ throw core::Error("failed to rmdir {}: {}", p, strerror(errno));
}
} else if (unlink(p.c_str()) != 0 && errno != ENOENT && errno != ESTALE) {
- throw Error("failed to unlink {}: {}", p, strerror(errno));
+ throw core::Error("failed to unlink {}: {}", p, strerror(errno));
}
});
}
write(fd, static_cast<const uint8_t*>(data) + written, size - written);
if (count == -1) {
if (errno != EAGAIN && errno != EINTR) {
- throw Error(strerror(errno));
+ throw core::Error(strerror(errno));
}
} else {
written += count;
std::ios_base::openmode open_mode)
{
if (path.empty()) {
- throw Error("No such file or directory");
+ throw core::Error("No such file or directory");
}
open_mode |= std::ios::out;
std::ofstream file(path, open_mode);
if (!file) {
- throw Error(strerror(errno));
+ throw core::Error(strerror(errno));
}
file << data;
}
}
// Clone a file from `src` to `dest`. If `via_tmp_file` is true, `src` is cloned
-// to a temporary file and then renamed to `dest`. Throws `Error` on error.
+// to a temporary file and then renamed to `dest`. Throws `core::Error` on
+// error.
void clone_file(const std::string& src,
const std::string& dest,
bool via_tmp_file = false);
// Clone, hard link or copy a file from `source` to `dest` depending on settings
// in `ctx`. If cloning or hard linking cannot and should not be done the file
-// will be copied instead. Throws `Error` on error.
+// will be copied instead. Throws `core::Error` on error.
void clone_hard_link_or_copy_file(const Context& ctx,
const std::string& source,
const std::string& dest,
size_t common_dir_prefix_length(nonstd::string_view dir,
nonstd::string_view path);
-// Copy all data from `fd_in` to `fd_out`. Throws `Error` on error.
+// Copy all data from `fd_in` to `fd_out`. Throws `core::Error` on error.
void copy_fd(int fd_in, int fd_out);
// Copy a file from `src` to `dest`. If via_tmp_file is true, `src` is copied to
-// a temporary file and then renamed to dest. Throws `Error` on error.
+// a temporary file and then renamed to dest. Throws `core::Error` on error.
void copy_file(const std::string& src,
const std::string& dest,
bool via_tmp_file = false);
void ensure_dir_exists(nonstd::string_view dir);
// Expand all instances of $VAR or ${VAR}, where VAR is an environment variable,
-// in `str`. Throws `Error` if one of the environment variables.
+// in `str`. Throws `core::Error` if one of the environment variables.
[[nodiscard]] std::string expand_environment_variables(const std::string& str);
// Extends file size to at least new_size by calling posix_fallocate() if
std::string get_relative_path(nonstd::string_view dir,
nonstd::string_view path);
-// Hard-link `oldpath` to `newpath`. Throws `Error` on error.
+// Hard-link `oldpath` to `newpath`. Throws `core::Error` on error.
void hard_link(const std::string& oldpath, const std::string& newpath);
// Write bytes in big endian order from an integer value.
std::string normalize_absolute_path(nonstd::string_view path);
// Parse `duration`, an unsigned integer with d (days) or s (seconds) suffix,
-// into seconds. Throws `Error` on error.
+// into seconds. Throws `core::Error` on error.
uint64_t parse_duration(const std::string& duration);
// Parse a "size value", i.e. a string that can end in k, M, G, T (10-based
// suffixes) or Ki, Mi, Gi, Ti (2-based suffixes). For backward compatibility, K
-// is also recognized as a synonym of k. Throws `Error` on parse error.
+// is also recognized as a synonym of k. Throws `core::Error` on parse error.
uint64_t parse_size(const std::string& value);
// Read data from `fd` until end of file and call `data_receiver` with the read
// Return `path`'s content as a string. If `size_hint` is not 0 then assume that
// `path` has this size (this saves system calls).
//
-// Throws `Error` on error. The description contains the error message without
-// the path.
+// Throws `core::Error` on error. The description contains the error message
+// without the path.
std::string read_file(const std::string& path, size_t size_hint = 0);
#ifndef _WIN32
// extension as determined by `get_extension()`.
nonstd::string_view remove_extension(nonstd::string_view path);
-// Rename `oldpath` to `newpath` (deleting `newpath`). Throws `Error` on error.
+// Rename `oldpath` to `newpath` (deleting `newpath`). Throws `core::Error` on
+// error.
void rename(const std::string& oldpath, const std::string& newpath);
// Detmine if `program_name` is equal to `canonical_program_name`. On Windows,
// Send `text` to STDERR_FILENO, optionally stripping ANSI color sequences if
// `ctx.args_info.strip_diagnostics_colors` is true and rewriting paths to
-// absolute if `ctx.config.absolute_paths_in_stderr` is true. Throws `Error` on
-// error.
+// absolute if `ctx.config.absolute_paths_in_stderr` is true. Throws
+// `core::Error` on error.
void send_to_stderr(const Context& ctx, const std::string& text);
// Set the FD_CLOEXEC on file descriptor `fd`. This is a NOP on Windows.
// Traverse `path` recursively (postorder, i.e. files are visited before their
// parent directory).
//
-// Throws Error on error.
+// Throws core::Error on error.
void traverse(const std::string& path, const TraverseVisitor& visitor);
// Remove `path` (non-directory), NFS safe. Logs according to `unlink_log`.
// Remove `path` (and its contents if it's a directory). A nonexistent path is
// not considered an error.
//
-// Throws Error on error.
+// Throws core::Error on error.
void wipe_path(const std::string& path);
-// Write `size` bytes from `data` to `fd`. Throws `Error` on error.
+// Write `size` bytes from `data` to `fd`. Throws `core::Error` on error.
void write_fd(int fd, const void* data, size_t size);
// Write `data` to `path`. The file will be opened according to `open_mode`,
// which always will include `std::ios::out` even if not specified at the call
// site.
//
-// Throws `Error` on error. The description contains the error message without
-// the path.
+// Throws `core::Error` on error. The description contains the error message
+// without the path.
void write_file(const std::string& path,
const std::string& data,
std::ios_base::openmode open_mode = std::ios::binary);
#include "Logging.hpp"
#include "assertions.hpp"
-#include "exceptions.hpp"
+
+#include <core/exceptions.hpp>
#include <algorithm>
size_t ret = ZSTD_initCStream(m_zstd_stream, m_compression_level);
if (ZSTD_isError(ret)) {
ZSTD_freeCStream(m_zstd_stream);
- throw Error("error initializing zstd compression stream");
+ throw core::Error("error initializing zstd compression stream");
}
}
size_t compressed_bytes = m_zstd_out.pos;
if (fwrite(buffer, 1, compressed_bytes, m_stream) != compressed_bytes
|| ferror(m_stream)) {
- throw Error("failed to write to zstd output stream ");
+ throw core::Error("failed to write to zstd output stream ");
}
}
ret = flush;
size_t compressed_bytes = m_zstd_out.pos;
if (fwrite(buffer, 1, compressed_bytes, m_stream) != compressed_bytes
|| ferror(m_stream)) {
- throw Error("failed to write to zstd output stream");
+ throw core::Error("failed to write to zstd output stream");
}
}
}
-// Copyright (C) 2019-2020 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2021 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
#include "ZstdDecompressor.hpp"
#include "assertions.hpp"
-#include "exceptions.hpp"
+
+#include <core/exceptions.hpp>
ZstdDecompressor::ZstdDecompressor(FILE* stream)
: m_stream(stream),
size_t ret = ZSTD_initDStream(m_zstd_stream);
if (ZSTD_isError(ret)) {
ZSTD_freeDStream(m_zstd_stream);
- throw Error("failed to initialize zstd decompression stream");
+ throw core::Error("failed to initialize zstd decompression stream");
}
}
if (m_input_size == m_input_consumed) {
m_input_size = fread(m_input_buffer, 1, sizeof(m_input_buffer), m_stream);
if (m_input_size == 0) {
- throw Error("failed to read from zstd input stream");
+ throw core::Error("failed to read from zstd input stream");
}
m_input_consumed = 0;
}
m_zstd_out.pos = 0;
size_t ret = ZSTD_decompressStream(m_zstd_stream, &m_zstd_out, &m_zstd_in);
if (ZSTD_isError(ret)) {
- throw Error("failed to read from zstd input stream");
+ throw core::Error("failed to read from zstd input stream");
}
if (ret == 0) {
m_reached_stream_end = true;
ZstdDecompressor::finalize()
{
if (!m_reached_stream_end) {
- throw Error("garbage data at end of zstd input stream");
+ throw core::Error("garbage data at end of zstd input stream");
}
}
#include "argprocessing.hpp"
#include "Context.hpp"
-#include "FormatNonstdStringView.hpp"
#include "Logging.hpp"
#include "assertions.hpp"
#include "compopt.hpp"
#include "cleanup.hpp"
#include "compopt.hpp"
#include "compress.hpp"
-#include "exceptions.hpp"
#include "execute.hpp"
#include "fmtmacros.hpp"
#include "hashutil.hpp"
#include "language.hpp"
+#include <core/exceptions.hpp>
#include <core/types.hpp>
#include <core/wincompat.hpp>
#include <storage/Storage.hpp>
for (const auto& word : Util::split_into_strings(prefix_command, " ")) {
std::string path = find_executable(ctx, word, CCACHE_NAME);
if (path.empty()) {
- throw Fatal("{}: {}", word, strerror(errno));
+ throw core::Fatal("{}: {}", word, strerror(errno));
}
prefix.push_back(path);
#endif
try {
Util::ensure_dir_exists(Util::dir_name(prefix));
- } catch (Error&) {
+ } catch (core::Error&) {
// Ignore since we can't handle an error in another way in this context. The
// caller takes care of logging when trying to open the path for writing.
}
std::string data;
try {
data = Util::read_file(path);
- } catch (Error&) {
+ } catch (core::Error&) {
return Statistic::internal_error;
}
std::string file_content;
try {
file_content = Util::read_file(ctx.args_info.output_dep);
- } catch (const Error& e) {
+ } catch (const core::Error& e) {
LOG(
"Cannot open dependency file {}: {}", ctx.args_info.output_dep, e.what());
return nullopt;
: find_executable_function(ctx, compiler, CCACHE_NAME);
if (resolved_compiler.empty()) {
- throw Fatal("Could not find compiler \"{}\" in PATH", compiler);
+ throw core::Fatal("Could not find compiler \"{}\" in PATH", compiler);
}
if (Util::same_program_name(Util::base_name(resolved_compiler),
CCACHE_NAME)) {
- throw Fatal(
+ throw core::Fatal(
"Recursive invocation (the name of the ccache binary must be \"{}\")",
CCACHE_NAME);
}
}
ctx.storage.finalize();
- } catch (const ErrorBase& e) {
+ } catch (const core::ErrorBase& e) {
// finalize_at_exit must not throw since it's called by a destructor.
LOG("Error while finalizing stats: {}", e.what());
}
}
auto execv_argv = saved_orig_args.to_argv();
execute_noreturn(execv_argv.data(), saved_temp_dir);
- throw Fatal(
+ throw core::Fatal(
"execute_noreturn of {} failed: {}", execv_argv[0], strerror(errno));
}
break;
case 'F': { // --max-files
- auto files = util::value_or_throw<Error>(util::parse_unsigned(arg));
+ auto files = util::value_or_throw<core::Error>(util::parse_unsigned(arg));
Config::set_value_in_file(
ctx.config.primary_config_path(), "max_files", arg);
if (files == 0) {
// 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 core::Error("missing equal sign in \"{}\"", arg);
}
std::string key = arg.substr(0, eq_pos);
std::string value = arg.substr(eq_pos + 1);
case SHOW_LOG_STATS: {
if (ctx.config.stats_log().empty()) {
- throw Fatal("No stats log has been configured");
+ throw core::Fatal("No stats log has been configured");
}
PRINT_RAW(stdout, Statistics::format_stats_log(ctx.config));
Counters counters = Statistics::read_log(ctx.config.stats_log());
if (arg == "uncompressed") {
wanted_level = nullopt;
} else {
- wanted_level = util::value_or_throw<Error>(
+ wanted_level = util::value_or_throw<core::Error>(
util::parse_signed(arg, INT8_MIN, INT8_MAX, "compression level"));
}
}
return cache_compilation(argc, argv);
- } catch (const ErrorBase& e) {
+ } catch (const core::ErrorBase& e) {
PRINT(stderr, "ccache: error: {}\n", e.what());
return EXIT_FAILURE;
}
#include "assertions.hpp"
#include "fmtmacros.hpp"
+#include <core/exceptions.hpp>
#include <core/wincompat.hpp>
#include <util/string.hpp>
{
File f(path, mode);
if (!f) {
- throw Error("failed to open {} for reading: {}", path, strerror(errno));
+ throw core::Error(
+ "failed to open {} for reading: {}", path, strerror(errno));
}
return f;
}
create_reader(const CacheFile& cache_file, FILE* stream)
{
if (cache_file.type() == CacheFile::Type::unknown) {
- throw Error("unknown file type for {}", cache_file.path());
+ throw core::Error("unknown file type for {}", cache_file.path());
}
switch (cache_file.type()) {
auto reader = create_reader(cache_file, file.get());
compr_size += cache_file.lstat().size();
content_size += reader->content_size();
- } catch (Error&) {
+ } catch (core::Error&) {
incompr_size += cache_file.lstat().size();
}
thread_pool.enqueue([&statistics, stats_file, file, level] {
try {
recompress_file(statistics, stats_file, file, level);
- } catch (Error&) {
+ } catch (core::Error&) {
// Ignore for now.
}
});
#pragma once
-#include "FormatNonstdStringView.hpp"
+#include <FormatNonstdStringView.hpp>
-#include "third_party/fmt/core.h"
-#include "third_party/nonstd/optional.hpp"
+#include <third_party/fmt/core.h>
+#include <third_party/nonstd/optional.hpp>
#include <stdexcept>
#include <string>
#include <utility>
+namespace core {
+
// Don't throw or catch ErrorBase directly, use a subclass.
class ErrorBase : public std::runtime_error
{
: ErrorBase(fmt::format(std::forward<T>(args)...))
{
}
+
+} // namespace core
#include "Win32Util.hpp"
#include "fmtmacros.hpp"
+#include <core/exceptions.hpp>
#include <core/wincompat.hpp>
#include <util/path.hpp>
}
if (ctx.compiler_pid == -1) {
- throw Fatal("Failed to fork: {}", strerror(errno));
+ throw core::Fatal("Failed to fork: {}", strerror(errno));
}
if (ctx.compiler_pid == 0) {
if (result == -1 && errno == EINTR) {
continue;
}
- throw Fatal("waitpid failed: {}", strerror(errno));
+ throw core::Fatal("waitpid failed: {}", strerror(errno));
}
{
-// Copyright (C) 2019-2020 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2021 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
#pragma once
-#include "third_party/fmt/core.h"
-#include "third_party/fmt/format.h"
+#include <FormatNonstdStringView.hpp>
+
+#include <third_party/fmt/core.h>
+#include <third_party/fmt/format.h>
// Convenience macro for calling `fmt::format` with `FMT_STRING` around the
// format string literal.
#include "fmtmacros.hpp"
#include "macroskip.hpp"
+#include <core/exceptions.hpp>
#include <core/wincompat.hpp>
#include <util/string.hpp>
std::string data;
try {
data = Util::read_file(path, size_hint);
- } catch (Error&) {
+ } catch (core::Error&) {
return HASH_SOURCE_CODE_ERROR;
}
int result = hash_source_code_string(ctx, hash, data, path);
#else
int pipefd[2];
if (pipe(pipefd) == -1) {
- throw Fatal("pipe failed: {}", strerror(errno));
+ throw core::Fatal("pipe failed: {}", strerror(errno));
}
pid_t pid = fork();
if (pid == -1) {
- throw Fatal("fork failed: {}", strerror(errno));
+ throw core::Fatal("fork failed: {}", strerror(errno));
}
if (pid == 0) {
#include <TemporaryFile.hpp>
#include <Util.hpp>
#include <assertions.hpp>
+#include <core/exceptions.hpp>
#include <fmtmacros.hpp>
#include <storage/secondary/FileStorage.hpp>
#include <storage/secondary/HttpStorage.hpp>
Util::split_into_views(entry, "|", util::Tokenizer::Mode::include_empty);
if (parts.empty() || parts.front().empty()) {
- throw Error("secondary storage config must provide a URL: {}", entry);
+ throw core::Error("secondary storage config must provide a URL: {}", entry);
}
SecondaryStorageConfig result;
try {
std::ignore = result.params.url.host();
} catch (const Url::parse_error& e) {
- throw Error("Cannot parse URL: {}", e.what());
+ throw core::Error("Cannot parse URL: {}", e.what());
}
if (result.params.url.scheme().empty()) {
- throw Error("URL scheme must not be empty: {}", entry);
+ throw core::Error("URL scheme must not be empty: {}", entry);
}
for (size_t i = 1; i < parts.size(); ++i) {
const auto& key = kv_pair.first;
const auto& raw_value = kv_pair.second.value_or("true");
const auto value =
- util::value_or_throw<Error>(util::percent_decode(raw_value));
+ util::value_or_throw<core::Error>(util::percent_decode(raw_value));
if (key == "read-only" && value == "true") {
result.read_only = true;
}
m_tmp_files.push_back(tmp_file.path);
try {
Util::write_file(tmp_file.path, *value);
- } catch (const Error& e) {
- throw Fatal("Error writing to {}: {}", tmp_file.path, e.what());
+ } catch (const core::Error& e) {
+ throw core::Fatal("Error writing to {}: {}", tmp_file.path, e.what());
}
m_primary_storage.put(key, type, [&](const std::string& path) {
try {
Util::copy_file(tmp_file.path, path);
- } catch (const Error& e) {
+ } catch (const core::Error& e) {
LOG("Failed to copy {} to {}: {}", tmp_file.path, path, e.what());
// Don't indicate failure since get from primary storage was OK.
}
std::string value;
try {
value = Util::read_file(*path);
- } catch (const Error& e) {
+ } catch (const core::Error& e) {
LOG("Failed to read {}: {}", *path, e.what());
return true; // Don't indicate failure since primary storage was OK.
}
url_for_logging.user_info("");
const auto storage = get_storage(config.params.url);
if (!storage) {
- throw Error("unknown secondary storage URL: {}", url_for_logging.str());
+ throw core::Error("unknown secondary storage URL: {}",
+ url_for_logging.str());
}
m_secondary_storages.emplace_back(
std::make_unique<SecondaryStorageEntry>(SecondaryStorageEntry{
#include <Util.hpp>
#include <assertions.hpp>
#include <cleanup.hpp>
+#include <core/exceptions.hpp>
#include <core/wincompat.hpp>
-#include <exceptions.hpp>
#include <fmtmacros.hpp>
#include <util/file.hpp>
LOG("Moving {} to {}", current_path, wanted_path);
try {
Util::rename(current_path, wanted_path);
- } catch (const Error&) {
+ } catch (const core::Error&) {
// Two ccache processes may move the file at the same time, so failure
// to rename is OK.
}
#include <UmaskScope.hpp>
#include <Util.hpp>
#include <assertions.hpp>
-#include <exceptions.hpp>
+#include <core/exceptions.hpp>
#include <fmtmacros.hpp>
#include <util/expected.hpp>
#include <util/file.hpp>
{
ASSERT(params.url.scheme() == "file");
if (!params.url.host().empty()) {
- throw Fatal(FMT(
+ throw core::Fatal(FMT(
"invalid file path \"{}\": specifying a host (\"{}\") is not supported",
params.url.str(),
params.url.host()));
for (const auto& attr : params.attributes) {
if (attr.key == "umask") {
- m_umask = util::value_or_throw<Fatal>(util::parse_umask(attr.value));
+ m_umask =
+ util::value_or_throw<core::Fatal>(util::parse_umask(attr.value));
} else if (attr.key == "update-mtime") {
m_update_mtime = attr.value == "true";
} else if (!is_framework_attribute(attr.key)) {
try {
LOG("Reading {}", path);
return Util::read_file(path);
- } catch (const Error& e) {
+ } catch (const core::Error& e) {
LOG("Failed to read {}: {}", path, e.what());
return nonstd::make_unexpected(Failure::error);
}
file.write(value);
file.commit();
return true;
- } catch (const Error& e) {
+ } catch (const core::Error& e) {
LOG("Failed to write {}: {}", path, e.what());
return nonstd::make_unexpected(Failure::error);
}
#include <Digest.hpp>
#include <Logging.hpp>
#include <ccache.hpp>
-#include <exceptions.hpp>
+#include <core/exceptions.hpp>
#include <fmtmacros.hpp>
#include <util/expected.hpp>
#include <util/string.hpp>
// slashes must be stripped.
const auto prefix = nonstd::string_view{"//"};
if (!util::starts_with(rendered_value, prefix)) {
- throw Fatal(R"(Expected partial URL "{}" to start with "{}")",
- rendered_value,
- prefix);
+ throw core::Fatal(R"(Expected partial URL "{}" to start with "{}")",
+ rendered_value,
+ prefix);
}
return rendered_value.substr(prefix.size());
}
get_url(const Url& url)
{
if (url.host().empty()) {
- throw Fatal("A host is required in HTTP storage URL \"{}\"", url.str());
+ throw core::Fatal("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 pair = util::split_once(params.url.user_info(), ':');
if (!pair.second) {
- throw Fatal("Expected username:password in URL but got \"{}\"",
- params.url.user_info());
+ throw core::Fatal("Expected username:password in URL but got \"{}\"",
+ params.url.user_info());
}
m_http_client.set_basic_auth(to_string(pair.first).c_str(),
to_string(*pair.second).c_str());
#include <Digest.hpp>
#include <Logging.hpp>
-#include <exceptions.hpp>
+#include <core/exceptions.hpp>
#include <fmtmacros.hpp>
#include <util/expected.hpp>
#include <util/string.hpp>
const std::string host = url.host().empty() ? "localhost" : url.host();
const uint32_t port = url.port().empty()
? DEFAULT_PORT
- : util::value_or_throw<Fatal>(
+ : util::value_or_throw<core::Fatal>(
util::parse_unsigned(url.port(), 1, 65535, "port"));
ASSERT(url.path().empty() || url.path()[0] == '/');
{
const uint32_t db_number =
url.path().empty() ? 0
- : util::value_or_throw<Fatal>(util::parse_unsigned(
+ : util::value_or_throw<core::Fatal>(util::parse_unsigned(
url.path().substr(1),
0,
std::numeric_limits<uint32_t>::max(),
// Create an instance of the backend. The instance is created just before the
// first call to a backend method, so the backend constructor can open a
- // connection or similar right away if wanted. The method should throw `Fatal`
- // on fatal configuration error or `Backend::Failed` on connection error or
- // timeout.
+ // connection or similar right away if wanted. The method should throw
+ // `core::Fatal` on fatal configuration error or `Backend::Failed` on
+ // connection error or timeout.
virtual std::unique_ptr<Backend>
create_backend(const Backend::Params& parameters) const = 0;
#include <Logging.hpp>
#include <Util.hpp>
+#include <core/exceptions.hpp>
#include <fmtmacros.hpp>
namespace util {
}
try {
Util::write_file(path, cachedir_tag);
- } catch (const Error& e) {
+ } catch (const core::Error& e) {
LOG("Failed to create {}: {}", path, e.what());
}
}
#include "string.hpp"
-#include <FormatNonstdStringView.hpp>
#include <fmtmacros.hpp>
#include <cctype>
#include "TestUtil.hpp"
#include "../src/Util.hpp"
-#include "../src/exceptions.hpp"
#include "../src/fmtmacros.hpp"
+#include <core/exceptions.hpp>
#include <core/wincompat.hpp>
#ifdef HAVE_UNISTD_H
TestContext::TestContext() : m_test_dir(Util::get_actual_cwd())
{
if (Util::base_name(Util::dir_name(m_test_dir)) != "testdir") {
- throw Error("TestContext instantiated outside test directory");
+ throw core::Error("TestContext instantiated outside test directory");
}
++m_subdir_counter;
std::string subtest_dir = FMT("{}/test_{}", m_test_dir, m_subdir_counter);
check_chdir(const std::string& dir)
{
if (chdir(dir.c_str()) != 0) {
- throw Error("failed to change directory to {}: {}", dir, strerror(errno));
+ throw core::Error(
+ "failed to change directory to {}: {}", dir, strerror(errno));
}
}
#include "../src/Config.hpp"
#include "../src/Sloppiness.hpp"
#include "../src/Util.hpp"
-#include "../src/exceptions.hpp"
#include "../src/fmtmacros.hpp"
#include "TestUtil.hpp"
+#include <core/exceptions.hpp>
+
#include "third_party/doctest.h"
#include "third_party/fmt/core.h"
try {
Config::set_value_in_file("ccache.conf", "foo", "bar");
CHECK(false);
- } catch (const Error& e) {
+ } catch (const core::Error& e) {
CHECK(std::string(e.what()) == "unknown configuration option \"foo\"");
}
try {
config.get_string_value("foo");
CHECK(false);
- } catch (const Error& e) {
+ } catch (const core::Error& e) {
CHECK(std::string(e.what()) == "unknown configuration option \"foo\"");
}
}
#include "../src/Util.hpp"
#include "TestUtil.hpp"
+#include <core/exceptions.hpp>
#include <core/wincompat.hpp>
#include "third_party/doctest.h"
Finalizer cleanup([&] { CloseHandle(handle); });
// Sanity check we can't open the file for read/write access.
- REQUIRE_THROWS_AS(Util::read_file("file"), const Error&);
+ REQUIRE_THROWS_AS(Util::read_file("file"), const core::Error&);
SUBCASE("stat file no sharing")
{
#include "../src/fmtmacros.hpp"
#include "TestUtil.hpp"
+#include <core/exceptions.hpp>
#include <core/wincompat.hpp>
#include "third_party/doctest.h"
SUBCASE("Link nonexistent file")
{
- CHECK_THROWS_AS(Util::hard_link("old", "new"), Error);
+ CHECK_THROWS_AS(Util::hard_link("old", "new"), core::Error);
}
}