[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

@@ -28,14 +28,12 @@ void TrajectoryUtil::ToPathweaverJson(const Trajectory& trajectory,
}
Trajectory TrajectoryUtil::FromPathweaverJson(std::string_view path) {
std::error_code ec;
std::unique_ptr<wpi::MemoryBuffer> fileBuffer =
wpi::MemoryBuffer::GetFile(path, ec);
if (fileBuffer == nullptr || ec) {
auto fileBuffer = wpi::MemoryBuffer::GetFile(path);
if (!fileBuffer) {
throw std::runtime_error(fmt::format("Cannot open file: {}", path));
}
wpi::json json = wpi::json::parse(fileBuffer->GetCharBuffer());
wpi::json json = wpi::json::parse(fileBuffer.value()->GetCharBuffer());
return Trajectory{json.get<std::vector<Trajectory::State>>()};
}