[wpilibc] Errors: Use fmtlib

This commit is contained in:
Peter Johnson
2021-05-23 19:33:33 -07:00
parent 87603e400d
commit 831c10bdfc
55 changed files with 551 additions and 533 deletions

View File

@@ -32,7 +32,7 @@ Command::Command(Subsystem& subsystem) : Command("", -1.0) {
Command::Command(const wpi::Twine& name, double timeout) {
// We use -1.0 to indicate no timeout.
if (timeout < 0.0 && timeout != -1.0) {
throw FRC_MakeError(err::ParameterOutOfRange, "timeout < 0.0");
throw FRC_MakeError(err::ParameterOutOfRange, "timeout {} < 0.0", timeout);
}
m_timeout = timeout;
@@ -77,7 +77,7 @@ void Command::Requires(Subsystem* subsystem) {
if (subsystem != nullptr) {
m_requirements.insert(subsystem);
} else {
throw FRC_MakeError(err::NullParameter, "subsystem");
throw FRC_MakeError(err::NullParameter, "{}", "subsystem");
}
}
@@ -85,7 +85,7 @@ void Command::Start() {
LockChanges();
if (m_parent != nullptr) {
throw FRC_MakeError(
err::CommandIllegalUse,
err::CommandIllegalUse, "{}",
"Can not start a command that is part of a command group");
}
@@ -116,7 +116,7 @@ bool Command::Run() {
void Command::Cancel() {
if (m_parent != nullptr) {
throw FRC_MakeError(
err::CommandIllegalUse,
err::CommandIllegalUse, "{}",
"Can not cancel a command that is part of a command group");
}
@@ -173,7 +173,7 @@ int Command::GetID() const {
void Command::SetTimeout(double timeout) {
if (timeout < 0.0) {
throw FRC_MakeError(err::ParameterOutOfRange, "timeout < 0.0");
throw FRC_MakeError(err::ParameterOutOfRange, "timeout {} < 0.0", timeout);
} else {
m_timeout = timeout;
}
@@ -187,18 +187,16 @@ bool Command::AssertUnlocked(const std::string& message) {
if (m_locked) {
throw FRC_MakeError(
err::CommandIllegalUse,
message +
wpi::Twine{
" after being started or being added to a command group"});
"{} after being started or being added to a command group", message);
}
return true;
}
void Command::SetParent(CommandGroup* parent) {
if (parent == nullptr) {
throw FRC_MakeError(err::NullParameter, "parent");
throw FRC_MakeError(err::NullParameter, "{}", "parent");
} else if (m_parent != nullptr) {
throw FRC_MakeError(err::CommandIllegalUse,
throw FRC_MakeError(err::CommandIllegalUse, "{}",
"Can not give command to a command group after "
"already being put in a command group");
} else {

View File

@@ -12,7 +12,7 @@ CommandGroup::CommandGroup(const wpi::Twine& name) : Command(name) {}
void CommandGroup::AddSequential(Command* command) {
if (!command) {
throw FRC_MakeError(err::NullParameter, "command");
throw FRC_MakeError(err::NullParameter, "{}", "command");
}
if (!AssertUnlocked("Cannot add new command to command group")) {
return;
@@ -31,13 +31,13 @@ void CommandGroup::AddSequential(Command* command) {
void CommandGroup::AddSequential(Command* command, double timeout) {
if (!command) {
throw FRC_MakeError(err::NullParameter, "command");
throw FRC_MakeError(err::NullParameter, "{}", "command");
}
if (!AssertUnlocked("Cannot add new command to command group")) {
return;
}
if (timeout < 0.0) {
throw FRC_MakeError(err::ParameterOutOfRange, "timeout < 0.0");
throw FRC_MakeError(err::ParameterOutOfRange, "timeout {} < 0.0", timeout);
}
m_commands.emplace_back(command, CommandGroupEntry::kSequence_InSequence,
@@ -54,7 +54,7 @@ void CommandGroup::AddSequential(Command* command, double timeout) {
void CommandGroup::AddParallel(Command* command) {
if (!command) {
throw FRC_MakeError(err::NullParameter, "command");
throw FRC_MakeError(err::NullParameter, "{}", "command");
return;
}
if (!AssertUnlocked("Cannot add new command to command group")) {
@@ -74,13 +74,13 @@ void CommandGroup::AddParallel(Command* command) {
void CommandGroup::AddParallel(Command* command, double timeout) {
if (!command) {
throw FRC_MakeError(err::NullParameter, "command");
throw FRC_MakeError(err::NullParameter, "{}", "command");
}
if (!AssertUnlocked("Cannot add new command to command group")) {
return;
}
if (timeout < 0.0) {
throw FRC_MakeError(err::ParameterOutOfRange, "timeout < 0.0");
throw FRC_MakeError(err::ParameterOutOfRange, "timeout {} < 0.0", timeout);
}
m_commands.emplace_back(command, CommandGroupEntry::kSequence_BranchChild,

View File

@@ -65,7 +65,7 @@ void Scheduler::AddButton(ButtonScheduler* button) {
void Scheduler::RegisterSubsystem(Subsystem* subsystem) {
if (!subsystem) {
throw FRC_MakeError(err::NullParameter, "subsystem");
throw FRC_MakeError(err::NullParameter, "{}", "subsystem");
}
m_impl->subsystems.insert(subsystem);
}
@@ -108,7 +108,7 @@ void Scheduler::Run() {
for (auto& addition : m_impl->additions) {
// Check to make sure no adding during adding
if (m_impl->adding) {
FRC_ReportError(warn::IncompatibleState,
FRC_ReportError(warn::IncompatibleState, "{}",
"Can not start command from cancel method");
} else {
m_impl->ProcessCommandAddition(addition);
@@ -121,7 +121,7 @@ void Scheduler::Run() {
for (auto& subsystem : m_impl->subsystems) {
if (subsystem->GetCurrentCommand() == nullptr) {
if (m_impl->adding) {
FRC_ReportError(warn::IncompatibleState,
FRC_ReportError(warn::IncompatibleState, "{}",
"Can not start command from cancel method");
} else {
m_impl->ProcessCommandAddition(subsystem->GetDefaultCommand());
@@ -133,7 +133,7 @@ void Scheduler::Run() {
void Scheduler::Remove(Command* command) {
if (!command) {
throw FRC_MakeError(err::NullParameter, "command");
throw FRC_MakeError(err::NullParameter, "{}", "command");
}
m_impl->Remove(command);

View File

@@ -24,7 +24,7 @@ void Subsystem::SetDefaultCommand(Command* command) {
} else {
const auto& reqs = command->GetRequirements();
if (std::find(reqs.begin(), reqs.end(), this) == reqs.end()) {
throw FRC_MakeError(err::CommandIllegalUse,
throw FRC_MakeError(err::CommandIllegalUse, "{}",
"A default command must require the subsystem");
}