[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

@@ -10,7 +10,6 @@
#include <fmt/format.h>
#include <units/angle.h>
#include <wpi/MathExtras.h>
#include <wpi/MemoryBuffer.h>
#include <wpi/StringExtras.h>
#include <wpi/StringMap.h>

View File

@@ -35,15 +35,15 @@ void LogLoader::Display() {
if (!m_opener->result().empty()) {
m_filename = m_opener->result()[0];
std::error_code ec;
auto buf = wpi::MemoryBuffer::GetFile(m_filename, ec);
if (ec) {
auto fileBuffer = wpi::MemoryBuffer::GetFile(m_filename);
if (!fileBuffer) {
ImGui::OpenPopup("Error");
m_error = fmt::format("Could not open file: {}", ec.message());
m_error = fmt::format("Could not open file: {}",
fileBuffer.error().message());
return;
}
wpi::log::DataLogReader reader{std::move(buf)};
wpi::log::DataLogReader reader{std::move(*fileBuffer)};
if (!reader.IsValid()) {
ImGui::OpenPopup("Error");
m_error = "Not a valid datalog file";