[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

@@ -94,18 +94,17 @@ bool ReadCameraConfig(const wpi::json& config) {
bool ReadConfig() {
// open config file
std::error_code ec;
std::unique_ptr<wpi::MemoryBuffer> fileBuffer =
wpi::MemoryBuffer::GetFile(configFile, ec);
if (fileBuffer == nullptr || ec) {
wpi::print(stderr, "could not open '{}': {}\n", configFile, ec.message());
auto fileBuffer = wpi::MemoryBuffer::GetFile(configFile);
if (!fileBuffer) {
wpi::print(stderr, "could not open '{}': {}\n", configFile,
fileBuffer.error().message());
return false;
}
// parse file
wpi::json j;
try {
j = wpi::json::parse(fileBuffer->GetCharBuffer());
j = wpi::json::parse(fileBuffer.value()->GetCharBuffer());
} catch (const wpi::json::parse_error& e) {
wpi::print(stderr, "config error in '{}': byte {}: {}\n", configFile,
e.byte, e.what());