mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[commands] CommandCompositionError: Include stacktrace of original composition (#5984)
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "frc2/command/Command.h"
|
||||
|
||||
#include <wpi/StackTrace.h>
|
||||
#include <wpi/sendable/SendableBuilder.h>
|
||||
#include <wpi/sendable/SendableRegistry.h>
|
||||
|
||||
@@ -31,7 +32,7 @@ Command::~Command() {
|
||||
}
|
||||
|
||||
Command& Command::operator=(const Command& rhs) {
|
||||
m_isComposed = false;
|
||||
SetComposed(false);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -156,11 +157,19 @@ bool Command::HasRequirement(Subsystem* requirement) const {
|
||||
}
|
||||
|
||||
bool Command::IsComposed() const {
|
||||
return m_isComposed;
|
||||
return GetPreviousCompositionSite().has_value();
|
||||
}
|
||||
|
||||
void Command::SetComposed(bool isComposed) {
|
||||
m_isComposed = isComposed;
|
||||
if (isComposed) {
|
||||
m_previousComposition = wpi::GetStackTrace(1);
|
||||
} else {
|
||||
m_previousComposition.reset();
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<std::string> Command::GetPreviousCompositionSite() const {
|
||||
return m_previousComposition;
|
||||
}
|
||||
|
||||
void Command::InitSendable(wpi::SendableBuilder& builder) {
|
||||
|
||||
@@ -27,10 +27,17 @@ CommandPtr::CommandPtr(std::unique_ptr<Command>&& command)
|
||||
AssertValid();
|
||||
}
|
||||
|
||||
CommandPtr::CommandPtr(CommandPtr&& rhs) {
|
||||
m_ptr = std::move(rhs.m_ptr);
|
||||
AssertValid();
|
||||
rhs.m_moveOutSite = wpi::GetStackTrace(1);
|
||||
}
|
||||
|
||||
void CommandPtr::AssertValid() const {
|
||||
if (!m_ptr) {
|
||||
throw FRC_MakeError(frc::err::CommandIllegalUse,
|
||||
"Moved-from CommandPtr object used!");
|
||||
"Moved-from CommandPtr object used!\nMoved out at:\n{}",
|
||||
m_moveOutSite);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -453,11 +453,13 @@ void CommandScheduler::OnCommandFinish(Action action) {
|
||||
}
|
||||
|
||||
void CommandScheduler::RequireUngrouped(const Command* command) {
|
||||
if (command->IsComposed()) {
|
||||
auto stacktrace = command->GetPreviousCompositionSite();
|
||||
if (stacktrace.has_value()) {
|
||||
throw FRC_MakeError(frc::err::CommandIllegalUse,
|
||||
"Commands that have been composed may not be added to "
|
||||
"another composition or scheduled "
|
||||
"individually!");
|
||||
"another composition or scheduled individually!"
|
||||
"\nOriginally composed at:\n{}",
|
||||
stacktrace.value());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user