mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
Rate-limit duplicate error messages to avoid flooding console.
Fixes artf4809. In both C++ and Java, error messages are being sent to both the console (via stdout/stderr) and being reported via the HAL. We don't want to remove the stdout/stderr reporting at present because users debugging only via netconsole (e.g. using riolog) won't see the HAL-reported errors. Until there's an alternative means to getting the HAL-reported errors to those users, instead store the previous 5 error messages and don't duplicate them more often than once per second. Changes the error reporting from setErrorData() to sendError(), which improves driver station error reporting. The "location" in C++ is given as the immediate caller (e.g. the WPILib function). The "location" in Java is given as the first user function in the call stack. Note the full call stack is provided in both instances. Change-Id: I590dd63dcb66825301ebb260aff00cd8d7d501ed
This commit is contained in:
@@ -66,24 +66,21 @@ void Error::Set(Code code, llvm::StringRef contextMessage,
|
||||
}
|
||||
|
||||
void Error::Report() {
|
||||
std::stringstream errorStream;
|
||||
std::stringstream locStream;
|
||||
locStream << m_function << " [";
|
||||
|
||||
errorStream << "Error on line " << m_lineNumber << " ";
|
||||
#if defined(_UNIX)
|
||||
errorStream << "of " << basename(m_filename.c_str()) << ": ";
|
||||
#elif defined(_WIN32)
|
||||
#if defined(_WIN32)
|
||||
const int MAX_DIR = 100;
|
||||
char basename[MAX_DIR];
|
||||
_splitpath_s(m_filename.c_str(), NULL, 0, basename, MAX_DIR, NULL, 0, NULL, 0);
|
||||
errorStream << "of " << basename << ": ";
|
||||
locStream << basename;
|
||||
#else
|
||||
locStream << basename(m_filename.c_str());
|
||||
#endif
|
||||
locStream << ":" << m_lineNumber << "]";
|
||||
|
||||
errorStream << m_message << std::endl;
|
||||
errorStream << GetStackTrace(4);
|
||||
|
||||
std::string error = errorStream.str();
|
||||
|
||||
DriverStation::ReportError(error);
|
||||
DriverStation::ReportError(true, m_code, m_message, locStream.str(),
|
||||
GetStackTrace(4));
|
||||
}
|
||||
|
||||
void Error::Clear() {
|
||||
|
||||
Reference in New Issue
Block a user