diff --git a/hal/src/main/native/athena/LEDs.cpp b/hal/src/main/native/athena/LEDs.cpp index 8fa603e0fa0..0091602f4c9 100644 --- a/hal/src/main/native/athena/LEDs.cpp +++ b/hal/src/main/native/athena/LEDs.cpp @@ -8,8 +8,11 @@ #include +#include +#include #include +#include "HALInternal.h" #include "hal/Errors.h" namespace hal::init { @@ -34,13 +37,20 @@ void HAL_SetRadioLEDState(HAL_RadioLEDState state, int32_t* status) { fs::file_t greenFile = fs::OpenFileForWrite(radioLEDGreenFilePath, ec, fs::CD_OpenExisting, fs::OF_Text); if (ec) { + // not opened, nothing to clean up *status = INCOMPATIBLE_STATE; + hal::SetLastError(status, fmt::format("Could not open '{}' for write: {}", + greenFile, ec.message())); return; } fs::file_t redFile = fs::OpenFileForWrite(radioLEDRedFilePath, ec, fs::CD_OpenExisting, fs::OF_Text); if (ec) { + // green file opened successfully, need to close it + fs::CloseFile(greenFile); *status = INCOMPATIBLE_STATE; + hal::SetLastError(status, fmt::format("Could not open '{}' for write: {}", + greenFile, ec.message())); return; } @@ -55,6 +65,8 @@ bool ReadStateFromFile(fs::path path, int32_t* status) { std::error_code ec; fs::file_t file = fs::OpenFileForRead(path, ec, fs::OF_Text); if (ec) { + hal::SetLastError(status, fmt::format("Could not open '{}' for read: {}", + path, ec.message())); *status = INCOMPATIBLE_STATE; return false; }