2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2017-01-01 01:05:57 -07:00
|
|
|
/* Copyright (c) FIRST 2008-2017. All Rights Reserved. */
|
2013-12-15 18:30:16 -05:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
2016-01-02 03:02:34 -08:00
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
#include "ErrorBase.h"
|
|
|
|
|
|
2016-06-05 07:33:37 -07:00
|
|
|
#include <cerrno>
|
2016-09-21 23:48:54 -07:00
|
|
|
#include <cstdio>
|
|
|
|
|
#include <cstring>
|
2016-06-01 00:12:55 -07:00
|
|
|
#include <iomanip>
|
artf4154: Get rid of raw pointers in C++.
This deals with the majority of the user-facing code
in wpilibC++Devices and a substantial portion of it in
wpilibC++. wpilibC++Sim and wpilibC++IntegrationTests
are untouched except where it is necessary to make them
work with the rest of the libraries.
There is still a lot to do in the following areas:
-The HAL (which we may not want to touch at all).
-The I2C, Serial, and SPI interfaces in wpilibC++Devices,
which I haven't gotten around to doing yet.
-Most wpilibC++Devices classes have void* pointers
for interacting with the HAL.
-InterruptableSensorBase passes a void *params for
the interrupt handler.
-I haven't converted all the const char* to std::strings.
-There are plenty of other cases of raw pointers still
existing.
-This doesn't fall directly under raw pointer stuff,
but move syntax and rvalue references could be introduced
in many places.
-I haven't touched vision code.
-The Resource classes conflict (one is in the hal, the other
in wpilibC++). Someone should figure out a more
permanent fix (eg, just renaming them), then doing
what I did (making a new namespace for one of them,
essentially the same as renaming it).
A few other things:
-I created a NullDeleter class which is marked as deprecated.
What this does is it can be passed as the deleter to a
std::shared_ptr so that when you are converting raw pointers
to shared_ptrs the shared_ptr doesn't do any deletion if
someone else owns the raw pointer. This should only be
used in making old raw pointer UIs.
-I had to alter the build.gradle so that it did not
emit errors when deprecated functions called deprecated
functions. Unfortunately, gradle doesn't appear to be
actually printing out gcc warnigns for some reason.
The best way I have found to fix this is to patch
the toolchains (https://bitbucket.org/byteit101/toolchain-builder/pull-request/5/make-gcc-not-throw-warnings-for-nested/diff)
so that a deprecated function calling a deprecated
function is fine but a non-deprecated function calling
a deprecated function will throw a warning (which we
then elevate with -Werror). I believe that clang
deals with this properly, although I have not
tried it myself.
Change-Id: Ib8090c66893576fe73654f4e9d268f9d37be06a2
2015-06-30 15:01:20 -04:00
|
|
|
#include <sstream>
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2016-05-25 22:38:11 -07:00
|
|
|
#define WPI_ERRORS_DEFINE_STRINGS
|
|
|
|
|
#include "WPIErrors.h"
|
|
|
|
|
|
2016-11-01 22:33:12 -07:00
|
|
|
using namespace frc;
|
|
|
|
|
|
2015-06-25 01:54:20 -07:00
|
|
|
priority_mutex ErrorBase::_globalErrorMutex;
|
2013-12-15 18:30:16 -05:00
|
|
|
Error ErrorBase::_globalError;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Retrieve the current error.
|
|
|
|
|
* Get the current error information associated with this sensor.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
Error& ErrorBase::GetError() { return m_error; }
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
const Error& ErrorBase::GetError() const { return m_error; }
|
2013-12-15 18:30:16 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Clear the current error information associated with this sensor.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
void ErrorBase::ClearError() const { m_error.Clear(); }
|
2013-12-15 18:30:16 -05:00
|
|
|
|
|
|
|
|
/**
|
2015-06-25 15:07:55 -04:00
|
|
|
* @brief Set error information associated with a C library call that set an
|
|
|
|
|
* error to the "errno" global variable.
|
2014-07-25 16:52:00 -04:00
|
|
|
*
|
2013-12-15 18:30:16 -05:00
|
|
|
* @param contextMessage A custom message from the code that set the error.
|
2016-05-20 17:30:37 -07:00
|
|
|
* @param filename Filename of the error source
|
|
|
|
|
* @param function Function of the error source
|
|
|
|
|
* @param lineNumber Line number of the error source
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2015-11-22 10:07:23 -08:00
|
|
|
void ErrorBase::SetErrnoError(llvm::StringRef contextMessage,
|
|
|
|
|
llvm::StringRef filename,
|
2016-09-06 00:01:45 -07:00
|
|
|
llvm::StringRef function, int lineNumber) const {
|
artf4154: Get rid of raw pointers in C++.
This deals with the majority of the user-facing code
in wpilibC++Devices and a substantial portion of it in
wpilibC++. wpilibC++Sim and wpilibC++IntegrationTests
are untouched except where it is necessary to make them
work with the rest of the libraries.
There is still a lot to do in the following areas:
-The HAL (which we may not want to touch at all).
-The I2C, Serial, and SPI interfaces in wpilibC++Devices,
which I haven't gotten around to doing yet.
-Most wpilibC++Devices classes have void* pointers
for interacting with the HAL.
-InterruptableSensorBase passes a void *params for
the interrupt handler.
-I haven't converted all the const char* to std::strings.
-There are plenty of other cases of raw pointers still
existing.
-This doesn't fall directly under raw pointer stuff,
but move syntax and rvalue references could be introduced
in many places.
-I haven't touched vision code.
-The Resource classes conflict (one is in the hal, the other
in wpilibC++). Someone should figure out a more
permanent fix (eg, just renaming them), then doing
what I did (making a new namespace for one of them,
essentially the same as renaming it).
A few other things:
-I created a NullDeleter class which is marked as deprecated.
What this does is it can be passed as the deleter to a
std::shared_ptr so that when you are converting raw pointers
to shared_ptrs the shared_ptr doesn't do any deletion if
someone else owns the raw pointer. This should only be
used in making old raw pointer UIs.
-I had to alter the build.gradle so that it did not
emit errors when deprecated functions called deprecated
functions. Unfortunately, gradle doesn't appear to be
actually printing out gcc warnigns for some reason.
The best way I have found to fix this is to patch
the toolchains (https://bitbucket.org/byteit101/toolchain-builder/pull-request/5/make-gcc-not-throw-warnings-for-nested/diff)
so that a deprecated function calling a deprecated
function is fine but a non-deprecated function calling
a deprecated function will throw a warning (which we
then elevate with -Werror). I believe that clang
deals with this properly, although I have not
tried it myself.
Change-Id: Ib8090c66893576fe73654f4e9d268f9d37be06a2
2015-06-30 15:01:20 -04:00
|
|
|
std::string err;
|
2015-06-25 15:07:55 -04:00
|
|
|
int errNo = errno;
|
|
|
|
|
if (errNo == 0) {
|
2015-11-22 10:07:23 -08:00
|
|
|
err = "OK: ";
|
|
|
|
|
err += contextMessage;
|
2015-06-25 15:07:55 -04:00
|
|
|
} else {
|
2016-06-01 00:12:55 -07:00
|
|
|
std::ostringstream oss;
|
2016-09-21 23:48:54 -07:00
|
|
|
oss << std::strerror(errNo) << " (0x" << std::setfill('0') << std::hex
|
2016-06-01 00:12:55 -07:00
|
|
|
<< std::uppercase << std::setw(8) << errNo << "): " << contextMessage;
|
|
|
|
|
err = oss.str();
|
2015-06-25 15:07:55 -04:00
|
|
|
}
|
|
|
|
|
|
2016-05-20 17:30:37 -07:00
|
|
|
// Set the current error information for this object.
|
2015-06-25 15:07:55 -04:00
|
|
|
m_error.Set(-1, err, filename, function, lineNumber, this);
|
|
|
|
|
|
|
|
|
|
// Update the global error if there is not one already set.
|
2015-09-01 16:47:57 -07:00
|
|
|
std::lock_guard<priority_mutex> mutex(_globalErrorMutex);
|
2015-06-25 15:07:55 -04:00
|
|
|
if (_globalError.GetCode() == 0) {
|
|
|
|
|
_globalError.Clone(m_error);
|
|
|
|
|
}
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-06-25 15:07:55 -04:00
|
|
|
* @brief Set the current error information associated from the nivision Imaq
|
|
|
|
|
* API.
|
2014-07-25 16:52:00 -04:00
|
|
|
*
|
2016-05-20 17:30:37 -07:00
|
|
|
* @param success The return from the function
|
2013-12-15 18:30:16 -05:00
|
|
|
* @param contextMessage A custom message from the code that set the error.
|
2016-05-20 17:30:37 -07:00
|
|
|
* @param filename Filename of the error source
|
|
|
|
|
* @param function Function of the error source
|
|
|
|
|
* @param lineNumber Line number of the error source
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2015-11-22 10:07:23 -08:00
|
|
|
void ErrorBase::SetImaqError(int success, llvm::StringRef contextMessage,
|
|
|
|
|
llvm::StringRef filename, llvm::StringRef function,
|
2016-09-06 00:01:45 -07:00
|
|
|
int lineNumber) const {
|
2016-05-20 17:30:37 -07:00
|
|
|
// If there was an error
|
2015-06-25 15:07:55 -04:00
|
|
|
if (success <= 0) {
|
artf4154: Get rid of raw pointers in C++.
This deals with the majority of the user-facing code
in wpilibC++Devices and a substantial portion of it in
wpilibC++. wpilibC++Sim and wpilibC++IntegrationTests
are untouched except where it is necessary to make them
work with the rest of the libraries.
There is still a lot to do in the following areas:
-The HAL (which we may not want to touch at all).
-The I2C, Serial, and SPI interfaces in wpilibC++Devices,
which I haven't gotten around to doing yet.
-Most wpilibC++Devices classes have void* pointers
for interacting with the HAL.
-InterruptableSensorBase passes a void *params for
the interrupt handler.
-I haven't converted all the const char* to std::strings.
-There are plenty of other cases of raw pointers still
existing.
-This doesn't fall directly under raw pointer stuff,
but move syntax and rvalue references could be introduced
in many places.
-I haven't touched vision code.
-The Resource classes conflict (one is in the hal, the other
in wpilibC++). Someone should figure out a more
permanent fix (eg, just renaming them), then doing
what I did (making a new namespace for one of them,
essentially the same as renaming it).
A few other things:
-I created a NullDeleter class which is marked as deprecated.
What this does is it can be passed as the deleter to a
std::shared_ptr so that when you are converting raw pointers
to shared_ptrs the shared_ptr doesn't do any deletion if
someone else owns the raw pointer. This should only be
used in making old raw pointer UIs.
-I had to alter the build.gradle so that it did not
emit errors when deprecated functions called deprecated
functions. Unfortunately, gradle doesn't appear to be
actually printing out gcc warnigns for some reason.
The best way I have found to fix this is to patch
the toolchains (https://bitbucket.org/byteit101/toolchain-builder/pull-request/5/make-gcc-not-throw-warnings-for-nested/diff)
so that a deprecated function calling a deprecated
function is fine but a non-deprecated function calling
a deprecated function will throw a warning (which we
then elevate with -Werror). I believe that clang
deals with this properly, although I have not
tried it myself.
Change-Id: Ib8090c66893576fe73654f4e9d268f9d37be06a2
2015-06-30 15:01:20 -04:00
|
|
|
std::stringstream err;
|
|
|
|
|
err << success << ": " << contextMessage;
|
2015-06-25 15:07:55 -04:00
|
|
|
|
2016-05-20 17:30:37 -07:00
|
|
|
// Set the current error information for this object.
|
artf4154: Get rid of raw pointers in C++.
This deals with the majority of the user-facing code
in wpilibC++Devices and a substantial portion of it in
wpilibC++. wpilibC++Sim and wpilibC++IntegrationTests
are untouched except where it is necessary to make them
work with the rest of the libraries.
There is still a lot to do in the following areas:
-The HAL (which we may not want to touch at all).
-The I2C, Serial, and SPI interfaces in wpilibC++Devices,
which I haven't gotten around to doing yet.
-Most wpilibC++Devices classes have void* pointers
for interacting with the HAL.
-InterruptableSensorBase passes a void *params for
the interrupt handler.
-I haven't converted all the const char* to std::strings.
-There are plenty of other cases of raw pointers still
existing.
-This doesn't fall directly under raw pointer stuff,
but move syntax and rvalue references could be introduced
in many places.
-I haven't touched vision code.
-The Resource classes conflict (one is in the hal, the other
in wpilibC++). Someone should figure out a more
permanent fix (eg, just renaming them), then doing
what I did (making a new namespace for one of them,
essentially the same as renaming it).
A few other things:
-I created a NullDeleter class which is marked as deprecated.
What this does is it can be passed as the deleter to a
std::shared_ptr so that when you are converting raw pointers
to shared_ptrs the shared_ptr doesn't do any deletion if
someone else owns the raw pointer. This should only be
used in making old raw pointer UIs.
-I had to alter the build.gradle so that it did not
emit errors when deprecated functions called deprecated
functions. Unfortunately, gradle doesn't appear to be
actually printing out gcc warnigns for some reason.
The best way I have found to fix this is to patch
the toolchains (https://bitbucket.org/byteit101/toolchain-builder/pull-request/5/make-gcc-not-throw-warnings-for-nested/diff)
so that a deprecated function calling a deprecated
function is fine but a non-deprecated function calling
a deprecated function will throw a warning (which we
then elevate with -Werror). I believe that clang
deals with this properly, although I have not
tried it myself.
Change-Id: Ib8090c66893576fe73654f4e9d268f9d37be06a2
2015-06-30 15:01:20 -04:00
|
|
|
m_error.Set(success, err.str(), filename, function, lineNumber, this);
|
2015-06-25 15:07:55 -04:00
|
|
|
|
|
|
|
|
// Update the global error if there is not one already set.
|
2015-09-01 16:47:57 -07:00
|
|
|
std::lock_guard<priority_mutex> mutex(_globalErrorMutex);
|
2015-06-25 15:07:55 -04:00
|
|
|
if (_globalError.GetCode() == 0) {
|
|
|
|
|
_globalError.Clone(m_error);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Set the current error information associated with this sensor.
|
2014-07-25 16:52:00 -04:00
|
|
|
*
|
2016-05-20 17:30:37 -07:00
|
|
|
* @param code The error code
|
2013-12-15 18:30:16 -05:00
|
|
|
* @param contextMessage A custom message from the code that set the error.
|
2016-05-20 17:30:37 -07:00
|
|
|
* @param filename Filename of the error source
|
|
|
|
|
* @param function Function of the error source
|
|
|
|
|
* @param lineNumber Line number of the error source
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2015-11-22 10:07:23 -08:00
|
|
|
void ErrorBase::SetError(Error::Code code, llvm::StringRef contextMessage,
|
|
|
|
|
llvm::StringRef filename, llvm::StringRef function,
|
2016-09-06 00:01:45 -07:00
|
|
|
int lineNumber) const {
|
2015-06-25 15:07:55 -04:00
|
|
|
// If there was an error
|
|
|
|
|
if (code != 0) {
|
|
|
|
|
// Set the current error information for this object.
|
|
|
|
|
m_error.Set(code, contextMessage, filename, function, lineNumber, this);
|
|
|
|
|
|
|
|
|
|
// Update the global error if there is not one already set.
|
2015-09-01 16:47:57 -07:00
|
|
|
std::lock_guard<priority_mutex> mutex(_globalErrorMutex);
|
2015-06-25 15:07:55 -04:00
|
|
|
if (_globalError.GetCode() == 0) {
|
|
|
|
|
_globalError.Clone(m_error);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2016-07-13 20:29:28 -07:00
|
|
|
/**
|
|
|
|
|
* @brief Set the current error information associated with this sensor.
|
|
|
|
|
* Range versions use for initialization code.
|
|
|
|
|
*
|
|
|
|
|
* @param code The error code
|
|
|
|
|
* @param minRange The minimum allowed allocation range
|
|
|
|
|
* @param maxRange The maximum allowed allocation range
|
|
|
|
|
* @param requestedValue The requested value to allocate
|
|
|
|
|
* @param contextMessage A custom message from the code that set the error.
|
|
|
|
|
* @param filename Filename of the error source
|
|
|
|
|
* @param function Function of the error source
|
|
|
|
|
* @param lineNumber Line number of the error source
|
|
|
|
|
*/
|
|
|
|
|
void ErrorBase::SetErrorRange(Error::Code code, int32_t minRange,
|
|
|
|
|
int32_t maxRange, int32_t requestedValue,
|
|
|
|
|
llvm::StringRef contextMessage,
|
|
|
|
|
llvm::StringRef filename,
|
2016-09-06 00:01:45 -07:00
|
|
|
llvm::StringRef function, int lineNumber) const {
|
2016-07-13 20:29:28 -07:00
|
|
|
// If there was an error
|
|
|
|
|
if (code != 0) {
|
|
|
|
|
size_t size = contextMessage.size() + 100;
|
|
|
|
|
char* buf = new char[size];
|
2016-09-21 23:48:54 -07:00
|
|
|
std::snprintf(
|
|
|
|
|
buf, size,
|
|
|
|
|
"%s, Minimum Value: %d, Maximum Value: %d, Requested Value: %d",
|
|
|
|
|
contextMessage.data(), minRange, maxRange, requestedValue);
|
2016-07-13 20:29:28 -07:00
|
|
|
// Set the current error information for this object.
|
|
|
|
|
m_error.Set(code, buf, filename, function, lineNumber, this);
|
|
|
|
|
delete[] buf;
|
|
|
|
|
|
|
|
|
|
// Update the global error if there is not one already set.
|
|
|
|
|
std::lock_guard<priority_mutex> mutex(_globalErrorMutex);
|
|
|
|
|
if (_globalError.GetCode() == 0) {
|
|
|
|
|
_globalError.Clone(m_error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-15 18:30:16 -05:00
|
|
|
/**
|
|
|
|
|
* @brief Set the current error information associated with this sensor.
|
2014-07-25 16:52:00 -04:00
|
|
|
*
|
2016-05-20 17:30:37 -07:00
|
|
|
* @param errorMessage The error message from WPIErrors.h
|
2013-12-15 18:30:16 -05:00
|
|
|
* @param contextMessage A custom message from the code that set the error.
|
2016-05-20 17:30:37 -07:00
|
|
|
* @param filename Filename of the error source
|
|
|
|
|
* @param function Function of the error source
|
|
|
|
|
* @param lineNumber Line number of the error source
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2015-11-22 10:07:23 -08:00
|
|
|
void ErrorBase::SetWPIError(llvm::StringRef errorMessage, Error::Code code,
|
|
|
|
|
llvm::StringRef contextMessage,
|
|
|
|
|
llvm::StringRef filename, llvm::StringRef function,
|
2016-09-06 00:01:45 -07:00
|
|
|
int lineNumber) const {
|
2015-11-22 10:07:23 -08:00
|
|
|
std::string err = errorMessage.str() + ": " + contextMessage.str();
|
2015-06-25 15:07:55 -04:00
|
|
|
|
|
|
|
|
// Set the current error information for this object.
|
|
|
|
|
m_error.Set(code, err, filename, function, lineNumber, this);
|
|
|
|
|
|
|
|
|
|
// Update the global error if there is not one already set.
|
2015-09-01 16:47:57 -07:00
|
|
|
std::lock_guard<priority_mutex> mutex(_globalErrorMutex);
|
2015-06-25 15:07:55 -04:00
|
|
|
if (_globalError.GetCode() == 0) {
|
|
|
|
|
_globalError.Clone(m_error);
|
|
|
|
|
}
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
artf4154: Get rid of raw pointers in C++.
This deals with the majority of the user-facing code
in wpilibC++Devices and a substantial portion of it in
wpilibC++. wpilibC++Sim and wpilibC++IntegrationTests
are untouched except where it is necessary to make them
work with the rest of the libraries.
There is still a lot to do in the following areas:
-The HAL (which we may not want to touch at all).
-The I2C, Serial, and SPI interfaces in wpilibC++Devices,
which I haven't gotten around to doing yet.
-Most wpilibC++Devices classes have void* pointers
for interacting with the HAL.
-InterruptableSensorBase passes a void *params for
the interrupt handler.
-I haven't converted all the const char* to std::strings.
-There are plenty of other cases of raw pointers still
existing.
-This doesn't fall directly under raw pointer stuff,
but move syntax and rvalue references could be introduced
in many places.
-I haven't touched vision code.
-The Resource classes conflict (one is in the hal, the other
in wpilibC++). Someone should figure out a more
permanent fix (eg, just renaming them), then doing
what I did (making a new namespace for one of them,
essentially the same as renaming it).
A few other things:
-I created a NullDeleter class which is marked as deprecated.
What this does is it can be passed as the deleter to a
std::shared_ptr so that when you are converting raw pointers
to shared_ptrs the shared_ptr doesn't do any deletion if
someone else owns the raw pointer. This should only be
used in making old raw pointer UIs.
-I had to alter the build.gradle so that it did not
emit errors when deprecated functions called deprecated
functions. Unfortunately, gradle doesn't appear to be
actually printing out gcc warnigns for some reason.
The best way I have found to fix this is to patch
the toolchains (https://bitbucket.org/byteit101/toolchain-builder/pull-request/5/make-gcc-not-throw-warnings-for-nested/diff)
so that a deprecated function calling a deprecated
function is fine but a non-deprecated function calling
a deprecated function will throw a warning (which we
then elevate with -Werror). I believe that clang
deals with this properly, although I have not
tried it myself.
Change-Id: Ib8090c66893576fe73654f4e9d268f9d37be06a2
2015-06-30 15:01:20 -04:00
|
|
|
void ErrorBase::CloneError(const ErrorBase& rhs) const {
|
|
|
|
|
m_error.Clone(rhs.GetError());
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2016-05-20 17:30:37 -07:00
|
|
|
* @brief Check if the current error code represents a fatal error.
|
|
|
|
|
*
|
|
|
|
|
* @return true if the current error is fatal.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
bool ErrorBase::StatusIsFatal() const { return m_error.GetCode() < 0; }
|
|
|
|
|
|
2015-11-22 10:07:23 -08:00
|
|
|
void ErrorBase::SetGlobalError(Error::Code code, llvm::StringRef contextMessage,
|
|
|
|
|
llvm::StringRef filename,
|
2016-09-06 00:01:45 -07:00
|
|
|
llvm::StringRef function, int lineNumber) {
|
2016-05-20 17:30:37 -07:00
|
|
|
// If there was an error
|
2015-06-25 15:07:55 -04:00
|
|
|
if (code != 0) {
|
2015-09-01 16:47:57 -07:00
|
|
|
std::lock_guard<priority_mutex> mutex(_globalErrorMutex);
|
2015-06-25 15:07:55 -04:00
|
|
|
|
2016-05-20 17:30:37 -07:00
|
|
|
// Set the current error information for this object.
|
2015-06-25 15:07:55 -04:00
|
|
|
_globalError.Set(code, contextMessage, filename, function, lineNumber,
|
2015-06-23 04:49:51 -07:00
|
|
|
nullptr);
|
2015-06-25 15:07:55 -04:00
|
|
|
}
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2015-11-22 10:07:23 -08:00
|
|
|
void ErrorBase::SetGlobalWPIError(llvm::StringRef errorMessage,
|
|
|
|
|
llvm::StringRef contextMessage,
|
|
|
|
|
llvm::StringRef filename,
|
2016-09-06 00:01:45 -07:00
|
|
|
llvm::StringRef function, int lineNumber) {
|
2015-11-22 10:07:23 -08:00
|
|
|
std::string err = errorMessage.str() + ": " + contextMessage.str();
|
2015-06-25 15:07:55 -04:00
|
|
|
|
2015-09-01 16:47:57 -07:00
|
|
|
std::lock_guard<priority_mutex> mutex(_globalErrorMutex);
|
2015-06-25 15:07:55 -04:00
|
|
|
if (_globalError.GetCode() != 0) {
|
|
|
|
|
_globalError.Clear();
|
|
|
|
|
}
|
2015-06-23 04:49:51 -07:00
|
|
|
_globalError.Set(-1, err, filename, function, lineNumber, nullptr);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2016-05-20 17:30:37 -07:00
|
|
|
* Retrieve the current global error.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
Error& ErrorBase::GetGlobalError() {
|
2015-09-01 16:47:57 -07:00
|
|
|
std::lock_guard<priority_mutex> mutex(_globalErrorMutex);
|
2015-06-25 15:07:55 -04:00
|
|
|
return _globalError;
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|