[wpilibc] Remove ErrorBase (#3306)

Replace with new exception-based error reporting, consistent with Java.
This also builds stacktraces into the reporting/exceptions.
This commit is contained in:
Peter Johnson
2021-04-18 20:35:29 -07:00
committed by GitHub
parent 0abf6c9045
commit 8d961dfd25
113 changed files with 993 additions and 2200 deletions

View File

@@ -12,8 +12,8 @@
#include <hal/Relay.h>
#include <wpi/raw_ostream.h>
#include "frc/Errors.h"
#include "frc/SensorUtil.h"
#include "frc/WPIErrors.h"
#include "frc/smartdashboard/SendableBuilder.h"
#include "frc/smartdashboard/SendableRegistry.h"
@@ -22,8 +22,8 @@ using namespace frc;
Relay::Relay(int channel, Relay::Direction direction)
: m_channel(channel), m_direction(direction) {
if (!SensorUtil::CheckRelayChannel(m_channel)) {
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange,
"Relay Channel " + wpi::Twine(m_channel));
throw FRC_MakeError(err::ChannelIndexOutOfRange,
"Relay Channel " + wpi::Twine{m_channel});
return;
}
@@ -32,45 +32,24 @@ Relay::Relay(int channel, Relay::Direction direction)
if (m_direction == kBothDirections || m_direction == kForwardOnly) {
int32_t status = 0;
m_forwardHandle = HAL_InitializeRelayPort(portHandle, true, &status);
if (status != 0) {
wpi_setHALErrorWithRange(status, 0, HAL_GetNumRelayChannels(), channel);
m_forwardHandle = HAL_kInvalidHandle;
m_reverseHandle = HAL_kInvalidHandle;
return;
}
FRC_CheckErrorStatus(status, "Relay Channel " + wpi::Twine{m_channel});
HAL_Report(HALUsageReporting::kResourceType_Relay, m_channel + 1);
}
if (m_direction == kBothDirections || m_direction == kReverseOnly) {
int32_t status = 0;
m_reverseHandle = HAL_InitializeRelayPort(portHandle, false, &status);
if (status != 0) {
wpi_setHALErrorWithRange(status, 0, HAL_GetNumRelayChannels(), channel);
m_forwardHandle = HAL_kInvalidHandle;
m_reverseHandle = HAL_kInvalidHandle;
return;
}
FRC_CheckErrorStatus(status, "Relay Channel " + wpi::Twine{m_channel});
HAL_Report(HALUsageReporting::kResourceType_Relay, m_channel + 128);
}
int32_t status = 0;
if (m_forwardHandle != HAL_kInvalidHandle) {
HAL_SetRelay(m_forwardHandle, false, &status);
if (status != 0) {
wpi_setHALError(status);
m_forwardHandle = HAL_kInvalidHandle;
m_reverseHandle = HAL_kInvalidHandle;
return;
}
FRC_CheckErrorStatus(status, "Relay Channel " + wpi::Twine{m_channel});
}
if (m_reverseHandle != HAL_kInvalidHandle) {
HAL_SetRelay(m_reverseHandle, false, &status);
if (status != 0) {
wpi_setHALError(status);
m_forwardHandle = HAL_kInvalidHandle;
m_reverseHandle = HAL_kInvalidHandle;
return;
}
FRC_CheckErrorStatus(status, "Relay Channel " + wpi::Twine{m_channel});
}
SendableRegistry::GetInstance().AddLW(this, "Relay", m_channel);
@@ -90,10 +69,6 @@ Relay::~Relay() {
}
void Relay::Set(Relay::Value value) {
if (StatusIsFatal()) {
return;
}
int32_t status = 0;
switch (value) {
@@ -115,7 +90,7 @@ void Relay::Set(Relay::Value value) {
break;
case kForward:
if (m_direction == kReverseOnly) {
wpi_setWPIError(IncompatibleMode);
FRC_ReportError(err::IncompatibleMode, "setting forward");
break;
}
if (m_direction == kBothDirections || m_direction == kForwardOnly) {
@@ -127,7 +102,7 @@ void Relay::Set(Relay::Value value) {
break;
case kReverse:
if (m_direction == kForwardOnly) {
wpi_setWPIError(IncompatibleMode);
FRC_ReportError(err::IncompatibleMode, "setting reverse");
break;
}
if (m_direction == kBothDirections) {
@@ -139,7 +114,7 @@ void Relay::Set(Relay::Value value) {
break;
}
wpi_setHALError(status);
FRC_CheckErrorStatus(status, "Set");
}
Relay::Value Relay::Get() const {
@@ -173,7 +148,7 @@ Relay::Value Relay::Get() const {
}
}
wpi_setHALError(status);
FRC_CheckErrorStatus(status, "Get");
}
int Relay::GetChannel() const {