mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[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:
@@ -2,6 +2,8 @@
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include <frc/Errors.h>
|
||||
|
||||
#include "CommandTestBase.h"
|
||||
#include "frc2/command/CommandScheduler.h"
|
||||
#include "frc2/command/ConditionalCommand.h"
|
||||
@@ -71,11 +73,9 @@ TEST_F(CommandRequirementsTest, RequirementUninterruptibleTest) {
|
||||
|
||||
TEST_F(CommandRequirementsTest, DefaultCommandRequirementErrorTest) {
|
||||
TestSubsystem requirement1;
|
||||
ErrorConfirmer confirmer("require");
|
||||
|
||||
MockCommand command1;
|
||||
|
||||
requirement1.SetDefaultCommand(std::move(command1));
|
||||
|
||||
EXPECT_TRUE(requirement1.GetDefaultCommand() == nullptr);
|
||||
ASSERT_THROW(requirement1.SetDefaultCommand(std::move(command1)),
|
||||
frc::RuntimeError);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
#include <frc/simulation/DriverStationSim.h>
|
||||
|
||||
#include "ErrorConfirmer.h"
|
||||
#include "frc2/command/CommandGroupBase.h"
|
||||
#include "frc2/command/CommandScheduler.h"
|
||||
#include "frc2/command/SetUtilities.h"
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include "ErrorConfirmer.h"
|
||||
|
||||
#include <regex>
|
||||
|
||||
ErrorConfirmer* ErrorConfirmer::instance;
|
||||
|
||||
int32_t ErrorConfirmer::HandleError(HAL_Bool isError, int32_t errorCode,
|
||||
HAL_Bool isLVCode, const char* details,
|
||||
const char* location, const char* callStack,
|
||||
HAL_Bool printMsg) {
|
||||
if (std::regex_search(details, std::regex(instance->m_msg))) {
|
||||
instance->ConfirmError();
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <hal/simulation/MockHooks.h>
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
class ErrorConfirmer {
|
||||
public:
|
||||
explicit ErrorConfirmer(const char* msg) : m_msg(msg) {
|
||||
if (instance != nullptr) {
|
||||
return;
|
||||
}
|
||||
HALSIM_SetSendError(HandleError);
|
||||
EXPECT_CALL(*this, ConfirmError());
|
||||
instance = this;
|
||||
}
|
||||
|
||||
~ErrorConfirmer() {
|
||||
HALSIM_SetSendError(nullptr);
|
||||
instance = nullptr;
|
||||
}
|
||||
|
||||
MOCK_METHOD0(ConfirmError, void());
|
||||
|
||||
const char* m_msg;
|
||||
|
||||
static int32_t HandleError(HAL_Bool isError, int32_t errorCode,
|
||||
HAL_Bool isLVCode, const char* details,
|
||||
const char* location, const char* callStack,
|
||||
HAL_Bool printMsg);
|
||||
|
||||
private:
|
||||
static ErrorConfirmer* instance;
|
||||
};
|
||||
Reference in New Issue
Block a user