Skip to content

Commit

Permalink
Replacing error code macros with enum classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
jholloc committed Nov 5, 2024
1 parent f84b0d6 commit 939b1cb
Show file tree
Hide file tree
Showing 18 changed files with 288 additions and 283 deletions.
8 changes: 4 additions & 4 deletions source/client/makeClientRequestBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ int make_request_data(const char* data_object, const char* data_source, RequestD
//! Test Input Arguments comply with string length limits, then copy to the request structure without modification

if (strlen(data_object) >= MaxMeta) {
UDA_THROW_ERROR(SIGNAL_ARG_TOO_LONG, "The Signal/Data Object Argument string is too long!");
UDA_THROW_ERROR((int)RequestError::SignalArgTooLong, "The Signal/Data Object Argument string is too long!");
} else {
strcpy(request->signal, data_object); // Passed to the server without modification
}

if (strlen(data_source) >= StringLength) {
UDA_THROW_ERROR(SOURCE_ARG_TOO_LONG, "The Data Source Argument string is too long!");
UDA_THROW_ERROR((int)RequestError::SourceArgTooLong, "The Data Source Argument string is too long!");
} else {
strcpy(request->source, data_source); // Passed to the server without modification
}
Expand Down Expand Up @@ -81,7 +81,7 @@ int make_request_data(const char* data_object, const char* data_source, RequestD
if (!device.empty() && strstr(request->source, request->api_delim) == nullptr) {
size_t lstr = strlen(request->source) + device.size() + strlen(request->api_delim);
if (lstr >= StringLength) {
UDA_THROW_ERROR(SOURCE_ARG_TOO_LONG,
UDA_THROW_ERROR((int)RequestError::SourceArgTooLong,
"The Data Source Argument, prefixed with the Device Name, is too long!");
}
std::string test = fmt::format("{}{}{}", device, request->api_delim, request->source);
Expand All @@ -91,7 +91,7 @@ int make_request_data(const char* data_object, const char* data_source, RequestD
if (!archive.empty() && strstr(request->signal, request->api_delim) == nullptr) {
size_t lstr = strlen(request->signal) + archive.size() + strlen(request->api_delim);
if (lstr >= StringLength) {
UDA_THROW_ERROR(SIGNAL_ARG_TOO_LONG,
UDA_THROW_ERROR((int)RequestError::SignalArgTooLong,
"The Signal/Data Object Argument, prefixed with the Archive Name, is too long!");
}
std::string test = fmt::format("{}{}{}", archive, request->api_delim, request->signal);
Expand Down
10 changes: 5 additions & 5 deletions source/client/udaClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ static int allocMeta(DataSystem** data_system, SystemConfig** system_config, Dat

if (*data_system == nullptr || *system_config == nullptr || *data_source == nullptr || *signal_rec == nullptr ||
*signal_desc == nullptr) {
err = ERROR_ALLOCATING_META_DATA_HEAP;
err = (int)ServerSideError::ErrorAllocatingMetaDataHeap;
add_error(ErrorType::Code, __func__, err, "Error Allocating Heap for Meta Data");
return err;
}
Expand Down Expand Up @@ -820,7 +820,7 @@ int uda::client::udaClient(RequestBlock* request_block, int* indices)
}

if (!(xdrrec_endofrecord(client_output, 1))) { // Send data now
err = UDA_PROTOCOL_ERROR_7;
err = (int)ProtocolError::Error7;
add_error(ErrorType::Code, __func__, err, "Protocol 7 Error (Client Block)");
UDA_LOG(UDA_LOG_DEBUG, "Error xdrrec_endofrecord after Client Block");
break;
Expand All @@ -830,7 +830,7 @@ int uda::client::udaClient(RequestBlock* request_block, int* indices)

// Wait for data, then position buffer reader to the start of a new record
if (!(xdrrec_skiprecord(client_input))) {
err = UDA_PROTOCOL_ERROR_5;
err = (int)ProtocolError::Error5;
add_error(ErrorType::Code, __func__, err, "Protocol 5 Error (Server Block)");
UDA_LOG(UDA_LOG_DEBUG, "Error xdrrec_skiprecord prior to Server Block");
break;
Expand Down Expand Up @@ -973,15 +973,15 @@ int uda::client::udaClient(RequestBlock* request_block, int* indices)
// Send the Full TCP packet and wait for the returned data

if (!(rc = xdrrec_endofrecord(client_output, 1))) {
err = UDA_PROTOCOL_ERROR_7;
err = (int)ProtocolError::Error7;
add_error(ErrorType::Code, __func__, err, "Protocol 7 Error (Request Block & putDataBlockList)");
break;
}

UDA_LOG(UDA_LOG_DEBUG, "****** Outgoing tcp packet sent without error. Waiting for data.");

if (!xdrrec_skiprecord(client_input)) {
err = UDA_PROTOCOL_ERROR_5;
err = (int)ProtocolError::Error5;
add_error(ErrorType::Code, __func__, err, " Protocol 5 Error (Server & Data Structures)");
break;
}
Expand Down
10 changes: 5 additions & 5 deletions source/client2/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ int alloc_meta(DataSystem** data_system, SystemConfig** system_config, DataSourc

if (*data_system == nullptr || *system_config == nullptr || *data_source == nullptr || *signal_rec == nullptr ||
*signal_desc == nullptr) {
err = ERROR_ALLOCATING_META_DATA_HEAP;
err = (int)ServerSideError::ErrorAllocatingMetaDataHeap;
add_error(ErrorType::Code, __func__, err, "Error Allocating Heap for Meta Data");
return err;
}
Expand Down Expand Up @@ -752,7 +752,7 @@ int uda::client::Client::perform_handshake()
}

if (!(xdrrec_endofrecord(_client_output, 1))) { // Send data now
err = UDA_PROTOCOL_ERROR_7;
err = (int)ProtocolError::Error7;
add_error(ErrorType::Code, __func__, err, "Protocol 7 Error (Client Block)");
UDA_LOG(UDA_LOG_DEBUG, "Error xdrrec_endofrecord after Client Block");
throw uda::exceptions::ClientError("Protocol 7 Error (Client Block)");
Expand All @@ -762,7 +762,7 @@ int uda::client::Client::perform_handshake()

// Wait for data, then position buffer reader to the start of a new record
if (!(xdrrec_skiprecord(_client_input))) {
err = UDA_PROTOCOL_ERROR_5;
err = (int)ProtocolError::Error5;
add_error(ErrorType::Code, __func__, err, "Protocol 5 Error (Server Block)");
UDA_LOG(UDA_LOG_DEBUG, "Error xdrrec_skiprecord prior to Server Block");
throw uda::exceptions::ClientError("Protocol 5 Error (Server Block)");
Expand Down Expand Up @@ -808,15 +808,15 @@ int uda::client::Client::flush_sockets()

int rc = 0;
if (!(rc = xdrrec_endofrecord(_client_output, 1))) {
int err = UDA_PROTOCOL_ERROR_7;
int err = (int)ProtocolError::Error7;
add_error(ErrorType::Code, __func__, err, "Protocol 7 Error (Request Block & putDataBlockList)");
return err;
}

UDA_LOG(UDA_LOG_DEBUG, "****** Outgoing tcp packet sent without error. Waiting for data.");

if (!xdrrec_skiprecord(_client_input)) {
int err = UDA_PROTOCOL_ERROR_5;
int err = (int)ProtocolError::Error5;
add_error(ErrorType::Code, __func__, err, " Protocol 5 Error (Server & Data Structures)");
return err;
}
Expand Down
8 changes: 4 additions & 4 deletions source/client2/make_request_block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ int make_request_data(const Config& config, const char* data_object, const char*
//! Test Input Arguments comply with string length limits, then copy to the request structure without modification

if (strlen(data_object) >= MaxMeta) {
UDA_THROW_ERROR(SIGNAL_ARG_TOO_LONG, "The Signal/Data Object Argument string is too long!");
UDA_THROW_ERROR((int)RequestError::SignalArgTooLong, "The Signal/Data Object Argument string is too long!");
} else {
strcpy(request->signal, data_object); // Passed to the server without modification
}

if (strlen(data_source) >= StringLength) {
UDA_THROW_ERROR(SOURCE_ARG_TOO_LONG, "The Data Source Argument string is too long!");
UDA_THROW_ERROR((int)RequestError::SourceArgTooLong, "The Data Source Argument string is too long!");
} else {
strcpy(request->source, data_source); // Passed to the server without modification
}
Expand Down Expand Up @@ -56,7 +56,7 @@ int make_request_data(const Config& config, const char* data_object, const char*
if (!device.empty() && strstr(request->source, request->api_delim) == nullptr) {
auto source = fmt::format("{}{}{}", device, request->api_delim, request->source);
if (source.length() >= StringLength) {
UDA_THROW_ERROR(SOURCE_ARG_TOO_LONG,
UDA_THROW_ERROR((int)RequestError::SourceArgTooLong,
"The Data Source Argument, prefixed with the Device Name, is too long!");
}
strcpy(request->source, source.c_str());
Expand All @@ -65,7 +65,7 @@ int make_request_data(const Config& config, const char* data_object, const char*
if (!archive.empty() && strstr(request->signal, request->api_delim) == nullptr) {
auto signal = fmt::format("{}{}{}", archive, request->api_delim, request->signal);
if (signal.length() >= StringLength) {
UDA_THROW_ERROR(SIGNAL_ARG_TOO_LONG,
UDA_THROW_ERROR((int)RequestError::SignalArgTooLong,
"The Signal/Data Object Argument, prefixed with the Archive Name, is too long!");
}
strcpy(request->signal, signal.c_str());
Expand Down
20 changes: 10 additions & 10 deletions source/clientserver/allocData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ int uda::client_server::alloc_array(int data_type, size_t n_data, char** ap)
if (data_size > 0) {
*ap = (char*)realloc((void*)*ap, n_data * data_size);
} else if (data_type != UDA_TYPE_COMPOUND) {
return UNKNOWN_DATA_TYPE;
return (int)ServerSideError::UnknownDataType;
}

if (*ap == nullptr && data_type != UDA_TYPE_COMPOUND) {
return ERROR_ALLOCATING_HEAP;
return (int)ServerSideError::ErrorAllocatingHeap;
}

return 0;
Expand All @@ -60,7 +60,7 @@ int uda::client_server::alloc_data(DataBlock* data_block)
if (data_block->rank > 0) {
data_block->dims = (Dims*)malloc(data_block->rank * sizeof(Dims));
if (data_block->dims == nullptr) {
return ERROR_ALLOCATING_HEAP;
return (int)ServerSideError::ErrorAllocatingHeap;
}
for (unsigned int i = 0; i < data_block->rank; i++) {
init_dim_block(&data_block->dims[i]);
Expand Down Expand Up @@ -90,7 +90,7 @@ int uda::client_server::alloc_data(DataBlock* data_block)
}
}
} else if (data_block->data_type != UDA_TYPE_COMPOUND) {
return UNKNOWN_DATA_TYPE;
return (int)ServerSideError::UnknownDataType;
}

UDA_LOG(UDA_LOG_DEBUG, "allocData :");
Expand All @@ -104,7 +104,7 @@ int uda::client_server::alloc_data(DataBlock* data_block)

if (db == nullptr && data_block->data_type != UDA_TYPE_COMPOUND) {
UDA_LOG(UDA_LOG_DEBUG, "allocData: Unable to Allocate Heap Memory for Data");
return ERROR_ALLOCATING_HEAP;
return (int)ServerSideError::ErrorAllocatingHeap;
}

size_t error_size = getSizeOf((UDA_TYPE)data_block->error_type);
Expand All @@ -117,7 +117,7 @@ int uda::client_server::alloc_data(DataBlock* data_block)

if ((ebh == nullptr || (ebl == nullptr && data_block->errasymmetry)) &&
(data_block->error_type != UDA_TYPE_COMPOUND && data_block->error_type != UDA_TYPE_UNKNOWN)) {
return ERROR_ALLOCATING_HEAP;
return (int)ServerSideError::ErrorAllocatingHeap;
}

data_block->data = db;
Expand Down Expand Up @@ -167,10 +167,10 @@ int uda::client_server::alloc_dim(DataBlock* data_block)
}

if (db == nullptr) {
return ERROR_ALLOCATING_HEAP;
return (int)ServerSideError::ErrorAllocatingHeap;
}
if (ebh == nullptr || (ebl == nullptr && data_block->dims[i].errasymmetry)) {
return ERROR_ALLOCATING_HEAP;
return (int)ServerSideError::ErrorAllocatingHeap;
}

data_block->dims[i].dim = db;
Expand Down Expand Up @@ -226,7 +226,7 @@ int uda::client_server::alloc_put_data(PutDataBlock* putData)
if (data_size > 0) {
db = (char*)malloc(count * data_size);
} else {
return UNKNOWN_DATA_TYPE;
return (int)ServerSideError::UnknownDataType;
}

UDA_LOG(UDA_LOG_DEBUG, "allocPutData :");
Expand All @@ -237,7 +237,7 @@ int uda::client_server::alloc_put_data(PutDataBlock* putData)

if (db == nullptr && putData->data_type != UDA_TYPE_COMPOUND) {
UDA_LOG(UDA_LOG_DEBUG, "allocPutData: Unable to Allocate Heap Memory for Data");
return ERROR_ALLOCATING_HEAP;
return (int)ServerSideError::ErrorAllocatingHeap;
}

putData->data = db;
Expand Down
6 changes: 4 additions & 2 deletions source/clientserver/compressDim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#include "udaErrors.h"

using namespace uda::client_server;

namespace
{

Expand Down Expand Up @@ -67,7 +69,7 @@ template <typename T> int decompress(uda::client_server::Dims* ddim)

if (ddim->dim == nullptr) {
if ((ddim->dim = (char*)malloc(ndata * sizeof(T))) == nullptr) {
return UNCOMPRESS_ALLOCATING_HEAP;
return (int)ServerSideError::UncompressAllocatingHeap;
}
}
T* dim_data = (T*)ddim->dim;
Expand Down Expand Up @@ -208,6 +210,6 @@ int uda::client_server::uncompress_dim(Dims* ddim)
// case UDA_TYPE_UNSIGNED_LONG64:
// return decompress<uint64_t>(ddim);
default:
return UNKNOWN_DATA_TYPE;
return (int)ServerSideError::UnknownDataType;
}
}
4 changes: 2 additions & 2 deletions source/clientserver/makeRequestBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ int uda::client_server::make_request_data(const config::Config& config, RequestD
}

if (err != 0) {
UDA_THROW_ERROR(NO_SERVER_SPECIFIED, "The MDSPlus Data Source does not comply with the naming models: "
UDA_THROW_ERROR((int)RequestError::NoServerSpecified, "The MDSPlus Data Source does not comply with the naming models: "
"server/tree/number or server/path/to/data/tree/number")
}
}
Expand Down Expand Up @@ -1108,7 +1108,7 @@ int extract_archive(const uda::config::Config& config, RequestData* request, int
if ((test = strstr(request->signal, request->api_delim)) != nullptr) {

if (test - request->signal >= StringLength - 1 || strlen(test + ldelim) >= MaxMeta - 1) {
UDA_ADD_ERROR(ARCHIVE_NAME_TOO_LONG, "The ARCHIVE Name is too long!");
UDA_ADD_ERROR((int)RequestError::ArchiveNameTooLong, "The ARCHIVE Name is too long!");
return err;
}
copy_string(request->signal, request->archive, test - request->signal + 1);
Expand Down
Loading

0 comments on commit 939b1cb

Please sign in to comment.