[hal] Add HAL_GetLastError to enable better error messages from HAL calls (#3320)

This uses thread local storage so a full error string can be provided, not just an error code.
This commit is contained in:
Thad House
2021-04-29 09:56:54 -07:00
committed by GitHub
parent ced654880c
commit 5127380727
10 changed files with 81 additions and 13 deletions

View File

@@ -36,10 +36,10 @@ void RuntimeError::Report() const {
m_data->stack.c_str(), 1);
}
const char* frc::GetErrorMessage(int32_t code) {
const char* frc::GetErrorMessage(int32_t* code) {
using namespace err;
using namespace warn;
switch (code) {
switch (*code) {
#define S(label, offset, message) \
case label: \
return message;
@@ -47,7 +47,7 @@ const char* frc::GetErrorMessage(int32_t code) {
#include "frc/WPIWarnings.mac"
#undef S
default:
return HAL_GetErrorMessage(code);
return HAL_GetLastError(code);
}
}
@@ -57,7 +57,7 @@ void frc::ReportError(int32_t status, const wpi::Twine& message,
if (status == 0) {
return;
}
const char* statusMessage = GetErrorMessage(status);
const char* statusMessage = GetErrorMessage(&status);
auto stack = wpi::GetStackTrace(2);
wpi::SmallString<128> buf;
HAL_SendError(status < 0, status, 0,
@@ -70,7 +70,7 @@ void frc::ReportError(int32_t status, const wpi::Twine& message,
RuntimeError frc::MakeError(int32_t status, const wpi::Twine& message,
const char* fileName, int lineNumber,
const char* funcName) {
const char* statusMessage = GetErrorMessage(status);
const char* statusMessage = GetErrorMessage(&status);
auto stack = wpi::GetStackTrace(2);
return RuntimeError{status, statusMessage + wpi::Twine{": "} + message,
fileName, lineNumber,