Merge "Fixes a bug with ErrorBase where the correct error code would not be set when using wpi_setWPIErrorWithContext()"

This commit is contained in:
Thomas Clark (WPI)
2014-07-21 08:23:59 -07:00
committed by Gerrit Code Review
3 changed files with 8 additions and 6 deletions

View File

@@ -19,7 +19,7 @@
#define wpi_setStaticError(object, code) (wpi_setStaticErrorWithContext(object, code, ""))
#define wpi_setGlobalErrorWithContext(code, context) (ErrorBase::SetGlobalError((code), (context), __FILE__, __FUNCTION__, __LINE__))
#define wpi_setGlobalError(code) (wpi_setGlobalErrorWithContext(code, ""))
#define wpi_setWPIErrorWithContext(error, context) (this->SetWPIError((wpi_error_s_##error), (context), __FILE__, __FUNCTION__, __LINE__))
#define wpi_setWPIErrorWithContext(error, context) (this->SetWPIError((wpi_error_s_##error), (wpi_error_value_##error), (context), __FILE__, __FUNCTION__, __LINE__))
#define wpi_setWPIError(error) (wpi_setWPIErrorWithContext(error, ""))
#define wpi_setStaticWPIErrorWithContext(object, error, context) (object->SetWPIError((wpi_error_s_##error), (context), __FILE__, __FUNCTION__, __LINE__))
#define wpi_setStaticWPIError(object, error) (wpi_setStaticWPIErrorWithContext(object, error, ""))
@@ -44,7 +44,7 @@ public:
const char* function, uint32_t lineNumber) const;
virtual void SetError(Error::Code code, const char *contextMessage, const char* filename,
const char* function, uint32_t lineNumber) const;
virtual void SetWPIError(const char *errorMessage, const char *contextMessage,
virtual void SetWPIError(const char *errorMessage, Error::Code code, const char *contextMessage,
const char* filename, const char* function, uint32_t lineNumber) const;
virtual void CloneError(ErrorBase *rhs) const;
virtual void ClearError() const;

View File

@@ -6,9 +6,11 @@
#pragma once
#ifdef WPI_ERRORS_DEFINE_STRINGS
#define S(label, offset, message) const char *wpi_error_s_##label = message ;
#define S(label, offset, message) const char *wpi_error_s_##label = message ; \
const int32_t wpi_error_value_##label = offset ;
#else
#define S(label, offset, message) extern const char *wpi_error_s_##label;
#define S(label, offset, message) extern const char *wpi_error_s_##label ; \
const int32_t wpi_error_value_##label = offset ;
#endif
/*

View File

@@ -145,14 +145,14 @@ void ErrorBase::SetError(Error::Code code, const char *contextMessage,
* @param function Function of the error source
* @param lineNumber Line number of the error source
*/
void ErrorBase::SetWPIError(const char *errorMessage, const char *contextMessage,
void ErrorBase::SetWPIError(const char *errorMessage, Error::Code code , const char *contextMessage,
const char* filename, const char* function, uint32_t lineNumber) const
{
char err[256];
sprintf(err, "%s: %s", errorMessage, contextMessage);
// Set the current error information for this object.
m_error.Set(-1, err, filename, function, lineNumber, this);
m_error.Set(code, err, filename, function, lineNumber, this);
// Update the global error if there is not one already set.
Synchronized mutex(_globalErrorMutex);