const auto st = Stat::stat(resolved_path);
if (!st) {
core::ensure_dir_exists(Util::dir_name(resolved_path));
- const auto result = util::write_file(resolved_path, "");
- if (!result) {
- throw core::Error(
- FMT("failed to write to {}: {}", resolved_path, result.error()));
- }
+ util::throw_on_error<core::Error>(
+ util::write_file(resolved_path, ""),
+ FMT("failed to write to {}: ", resolved_path));
}
AtomicFile output(resolved_path, AtomicFile::Mode::text);
case ConfigItem::umask:
if (!value.empty()) {
- const auto umask = util::parse_umask(value);
- if (!umask) {
- throw core::Error(umask.error());
- }
- m_umask = *umask;
+ m_umask = util::value_or_throw<core::Error>(util::parse_umask(value));
}
break;
}
#include <core/exceptions.hpp>
#include <core/wincompat.hpp>
#include <fmtmacros.hpp>
+#include <util/expected.hpp>
#include <util/file.hpp>
#include <util/filesystem.hpp>
#include <util/path.hpp>
text_to_send = modified_text;
}
- const auto result =
- util::write_fd(fd, text_to_send.data(), text_to_send.length());
- if (!result) {
- throw core::Error(FMT("Failed to write to {}: {}", fd, result.error()));
- }
+ util::throw_on_error<core::Error>(
+ util::write_fd(fd, text_to_send.data(), text_to_send.length()),
+ FMT("Failed to write to fd {}: ", fd));
}
std::string
CacheEntry::Header::Header(const std::string& path)
{
- const auto data = util::read_file_part<util::Bytes>(path, 0, 1000);
- if (!data) {
- throw core::Error(data.error());
- }
- parse(*data);
+ parse(util::value_or_throw<core::Error>(
+ util::read_file_part<util::Bytes>(path, 0, 1000)));
}
std::string