[wpiutil] Return wpi::expected from MemoryBuffer::GetFile (#7069)

This commit is contained in:
Joseph Eng
2024-09-12 23:45:35 -07:00
committed by GitHub
parent d44b651558
commit 1f3ef019ce
15 changed files with 87 additions and 103 deletions

View File

@@ -180,17 +180,16 @@ InputFile::~InputFile() {
}
static std::unique_ptr<InputFile> LoadDataLog(std::string_view filename) {
std::error_code ec;
auto buf = wpi::MemoryBuffer::GetFile(filename, ec);
std::string fn{filename};
if (ec) {
auto fileBuffer = wpi::MemoryBuffer::GetFile(filename);
if (!fileBuffer) {
return std::make_unique<InputFile>(
fn, fmt::format("Could not open file: {}", ec.message()));
filename,
fmt::format("Could not open file: {}", fileBuffer.error().message()));
}
wpi::log::DataLogReader reader{std::move(buf)};
wpi::log::DataLogReader reader{std::move(*fileBuffer)};
if (!reader.IsValid()) {
return std::make_unique<InputFile>(fn, "Not a valid datalog file");
return std::make_unique<InputFile>(filename, "Not a valid datalog file");
}
return std::make_unique<InputFile>(