[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

@@ -540,16 +540,14 @@ bool FieldInfo::LoadJson(std::span<const char> is, std::string_view filename) {
}
void FieldInfo::LoadJsonFile(std::string_view jsonfile) {
std::error_code ec;
std::unique_ptr<wpi::MemoryBuffer> fileBuffer =
wpi::MemoryBuffer::GetFile(jsonfile, ec);
if (fileBuffer == nullptr || ec) {
auto fileBuffer = wpi::MemoryBuffer::GetFile(jsonfile);
if (!fileBuffer) {
std::fputs("GUI: could not open field JSON file\n", stderr);
return;
}
LoadJson(
{reinterpret_cast<const char*>(fileBuffer->begin()), fileBuffer->size()},
jsonfile);
LoadJson({reinterpret_cast<const char*>(fileBuffer.value()->begin()),
fileBuffer.value()->size()},
jsonfile);
}
bool FieldInfo::LoadImageImpl(const std::string& fn) {