#include <core/wincompat.hpp>
#include <fmtmacros.hpp>
#include <util/Bytes.hpp>
+#include <util/expected.hpp>
#include <util/file.hpp>
#include <util/path.hpp>
#include <util/string.hpp>
std::get<std::string>(entry.data));
} else if (is_file_entry) {
const auto& path = std::get<std::string>(entry.data);
- const auto data = util::read_file<util::Bytes>(path);
- if (!data) {
- throw Error(FMT("Failed to read {}: {}", path, data.error()));
- }
- writer.write_bytes(*data);
+ const auto data = util::value_or_throw<Error>(
+ util::read_file<util::Bytes>(path), FMT("Failed to read {}: ", path));
+ writer.write_bytes(data);
} else {
writer.write_bytes(std::get<nonstd::span<const uint8_t>>(entry.data));
}
#include <core/wincompat.hpp>
#include <fmtmacros.hpp>
#include <util/Bytes.hpp>
+#include <util/expected.hpp>
#include <util/file.hpp>
#include <fcntl.h>
}
const auto dest_path = FMT("{}/ccache-result{}", m_output_directory, suffix);
- const auto result = util::write_file(dest_path, data);
- if (!result) {
- throw Error(FMT("Failed to write to {}: {}", dest_path, result.error()));
- }
+ util::throw_on_error<Error>(util::write_file(dest_path, data),
+ FMT("Failed to write to {}: ", dest_path));
}
void
file_size));
}
- const auto data = util::read_file<util::Bytes>(raw_file_path, file_size);
- if (!data) {
- throw Error(FMT("Failed to read {}: {}", raw_file_path, data.error()));
- }
- on_embedded_file(file_number, file_type, *data);
+ const auto data = util::value_or_throw<Error>(
+ util::read_file<util::Bytes>(raw_file_path, file_size),
+ FMT("Failed to read {}: ", raw_file_path));
+ on_embedded_file(file_number, file_type, data);
}
} // namespace core
#include <core/exceptions.hpp>
#include <core/wincompat.hpp>
#include <fmtmacros.hpp>
+#include <util/expected.hpp>
#include <util/file.hpp>
#include <util/string.hpp>
if (file_type == FileType::dependency) {
write_dependency_file(dest_path, data);
} else {
- const auto result = util::write_file(dest_path, data);
- if (!result) {
- throw WriteError(
- FMT("Failed to write to {}: {}", dest_path, result.error()));
- }
+ util::throw_on_error<WriteError>(
+ util::write_file(dest_path, data),
+ FMT("Failed to write to {}: ", dest_path));
}
}
}
}
auto write_data = [&](auto data, auto size) {
- const auto result = util::write_fd(*fd, data, size);
- if (!result) {
- throw WriteError(FMT("Failed to write to {}: {}", path, result.error()));
- }
+ util::throw_on_error<WriteError>(util::write_fd(*fd, data, size),
+ FMT("Failed to write to {}: ", path));
};
std::string_view str_data = util::to_string_view(data);