Skip to content

Commit 15e1fd7

Browse files
author
Halliday, Gavin (RIS-HBE)
authored
Merge pull request #36411 from risk-hsy/hallidgx/jliberrorcodes
chore(jlib): Ensure all jlib exceptions have unique error codes Reviewed-by: Jake Smith <jake.smith@lexisnexisrisk.com> Merged-by: Gavin Halliday <gavin.halliday@lexisnexisrisk.com>
2 parents 62c145b + de741fa commit 15e1fd7

43 files changed

Lines changed: 664 additions & 324 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

system/include/errorlist.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@
108108
#define QUERYREGISTRY_ERROR_START 9600
109109
#define QUERYREGISTRY_ERROR_END 9799
110110

111+
#define UNEXPECTED_ERROR_CODE 9999
112+
111113
#define JVM_API_ERROR_START 10000
112114
#define JVM_API_ERROR_END 10499
113115

system/jlib/jarray.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "jsort.hpp"
2222
#include "jmisc.hpp"
2323
#include "jlib.hpp"
24+
#include "jerror.hpp"
2425

2526
#include <assert.h>
2627

@@ -62,7 +63,7 @@ void Allocator::_reallocate(aindex_t newLen, size32_t itemSize)
6263
if (newLen >= newMax) // wraparound
6364
{
6465
IERRLOG("Out of memory (overflow) in Array allocator: itemSize = %u, trying to allocate %u items", itemSize, newLen);
65-
throw MakeStringException(0, "Out of memory (overflow) in Array allocator: itemSize = %u, trying to allocate %u items",itemSize, newLen);
66+
throw MakeStringException(JLIBERR_ArrayOverflow, "Out of memory (overflow) in Array allocator: itemSize = %u, trying to allocate %u items",itemSize, newLen);
6667
}
6768
}
6869
else
@@ -74,13 +75,13 @@ void Allocator::_reallocate(aindex_t newLen, size32_t itemSize)
7475
if (allocSize < newMax)
7576
{
7677
IERRLOG("Out of memory (overflow) in Array allocator: itemSize = %u, trying to allocate %u items", itemSize, newLen);
77-
throw MakeStringException(0, "Out of memory (overflow) in Array allocator: itemSize = %u, trying to allocate %u items",itemSize, newLen);
78+
throw MakeStringException(JLIBERR_ArrayOverflow, "Out of memory (overflow) in Array allocator: itemSize = %u, trying to allocate %u items",itemSize, newLen);
7879
}
7980
void *newhead = realloc(_head, allocSize);
8081
if (!newhead)
8182
{
8283
IERRLOG("Out of memory in Array allocator: itemSize = %u, trying to allocate %u items", itemSize, max);
83-
throw MakeStringException(0, "Out of memory in Array allocator: itemSize = %u, trying to allocate %u items",itemSize, max);
84+
throw MakeStringException(JLIBERR_ArrayAllocationFailed, "Out of memory in Array allocator: itemSize = %u, trying to allocate %u items",itemSize, max);
8485
}
8586
max = newMax;
8687
_head = newhead;
@@ -93,14 +94,14 @@ void Allocator::_reallocateExact(aindex_t newLen, size32_t itemSize)
9394
return;
9495

9596
if (used > newLen)
96-
throw MakeStringException(0, "Reallocate an array would contain too few items: itemSize = %u, trying to allocate %u items contains %u",itemSize, newLen, used);
97+
throw MakeStringException(JLIBERR_ArrayTooFewItems, "Reallocate an array would contain too few items: itemSize = %u, trying to allocate %u items contains %u",itemSize, newLen, used);
9798

9899
size_t allocSize = (size_t)itemSize * newLen;
99100
void *newhead = realloc(_head, allocSize);
100101
if (!newhead)
101102
{
102103
IERRLOG("Out of memory in Array allocator: itemSize = %u, trying to allocate %u items", itemSize, max);
103-
throw MakeStringException(0, "Out of memory in Array allocator: itemSize = %u, trying to allocate %u items",itemSize, max);
104+
throw MakeStringException(JLIBERR_ArrayAllocationFailed, "Out of memory in Array allocator: itemSize = %u, trying to allocate %u items",itemSize, max);
104105
}
105106
max = newLen;
106107
_head = newhead;

system/jlib/jbsocket.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "jlog.hpp"
2020
#include "jsocket.hpp"
21+
#include "jerror.hpp"
2122

2223
#define BSOCKET_BUFSIZE 1024
2324

@@ -53,7 +54,7 @@ BufferedSocket::BufferedSocket(ISocket* socket)
5354

5455
if(socket == NULL)
5556
{
56-
throw MakeStringException(-1, "can't create BufferedSocket from NULL socket");
57+
throw MakeStringException(JLIBERR_BufferedSocketFromNull, "can't create BufferedSocket from NULL socket");
5758
}
5859

5960
m_socket = socket;

system/jlib/jbuff.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "jexcept.hpp"
3838
#include "jmisc.hpp"
3939
#include "jutil.hpp"
40+
#include "jerror.hpp"
4041

4142
#ifdef _DEBUG
4243
#define KILL_CLEARS_MEMORY
@@ -698,7 +699,7 @@ MemoryBuffer &MemoryBuffer::appendFile(const char *fileName)
698699
int h = _open(fileName, _O_BINARY | _O_RDONLY | _O_SEQUENTIAL);
699700

700701
if (h == HFILE_ERROR)
701-
throw MakeStringException(0, "MemoryBuffer: Error reading file : %s", fileName);
702+
throw MakeStringException(JLIBERR_BufferErrorReadingFile, "MemoryBuffer: Error reading file : %s", fileName);
702703

703704
append(fileName);
704705

@@ -935,20 +936,20 @@ MemoryBuffer &MemoryBuffer::readFile(StringAttr &fileName)
935936

936937
int h = _open(fileName.get(), _O_WRONLY|_O_CREAT|_O_TRUNC|_O_BINARY|_O_SEQUENTIAL, _S_IREAD | _S_IWRITE);
937938
if (h == HFILE_ERROR)
938-
throw MakeStringException(0, "MemoryBuffer: Unable to create file : %s, error=%d", fileName.get(), GetLastError());
939+
throw MakeStringException(JLIBERR_BufferUnableToCreateFile, "MemoryBuffer: Unable to create file : %s, error=%d", fileName.get(), GetLastError());
939940

940941
CHECKREADPOS(fileSize);
941942
int w;
942943
while (fileSize) {
943944
w = _write(h, buffer+readPos, fileSize);
944945
if (w == 0) {
945946
_close(h);
946-
throw MakeStringException(0, "MemoryBuffer: Disk full writing %d to file : %s", fileSize, fileName.get());
947+
throw MakeStringException(JLIBERR_BufferDiskFull, "MemoryBuffer: Disk full writing %d to file : %s", fileSize, fileName.get());
947948
}
948949
if (w == -1)
949950
{
950951
_close(h);
951-
throw MakeStringException(0, "MemoryBuffer: Error writing to file : %s, error=%d", fileName.get(), GetLastError());
952+
throw MakeStringException(JLIBERR_BufferErrorWritingFile, "MemoryBuffer: Error writing to file : %s, error=%d", fileName.get(), GetLastError());
952953
}
953954
readPos += (size32_t)w;
954955
fileSize -= (size32_t)w;
@@ -1302,7 +1303,7 @@ MemoryBuffer &CLargeMemoryAllocator::serialize(MemoryBuffer &mb)
13021303
memsize_t al = allocated();
13031304
size32_t sz = (size32_t)al;
13041305
if (sz!=al)
1305-
throw MakeStringException(-1,"CLargeMemoryAllocator::serialize overflow");
1306+
throw MakeStringException(JLIBERR_UtilClargememoryallocatorSerializeOverflow,"CLargeMemoryAllocator::serialize overflow");
13061307
byte *d = (byte *)mb.reserveTruncate(sz)+sz;
13071308
Chunk *p = &chunk;
13081309
while (sz&&p) {

system/jlib/jcomp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ void CppCompiler::addCompileOption(const char * option)
369369
void CppCompiler::setPrecompileHeader(bool _pch)
370370
{
371371
if (targetCompiler==Vs6CppCompiler)
372-
throw MakeStringException(0, "precompiled header generation only supported for g++ and compatible compilers");
372+
throw MakeStringException(JLIBERR_UtilPrecompiledHeaderNotSupported, "precompiled header generation only supported for g++ and compatible compilers");
373373
precompileHeader = _pch;
374374
}
375375

system/jlib/jcontainerized.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ void waitJob(const char *componentName, const char *resourceType, const char *jo
145145
checkExitCodes(errMsg, output);
146146
}
147147
OERRLOG("%s", errMsg.str()); // report all k8s job failures to operator
148-
throw makeStringException(0, errMsg);
148+
throw makeStringException(JLIBERR_UtilKubernetesJobFailed, errMsg);
149149
}
150150
// Check for success: k8s <1.31 uses "Complete: True", k8s >=1.31 produces "SuccessCriteriaMet: True" 1st
151151
// followed by "Complete: True"
@@ -160,7 +160,7 @@ void waitJob(const char *componentName, const char *resourceType, const char *jo
160160
DBGLOG("UNKNOWN: kubectl output (from %s): %s", checkJobExitStatus.str(), output.str());
161161
// Non-empty status but not a recognized success or failure condition
162162
if (getExpertOptBool("k8sFailOnUnknownErr", true))
163-
throw makeStringExceptionV(0, "Job %s completed with unknown status condition [%s]", jobName.str(), output.str());
163+
throw makeStringExceptionV(JLIBERR_UtilJobSCompletedWithUnknownStatusCondition, "Job %s completed with unknown status condition [%s]", jobName.str(), output.str());
164164
else
165165
{
166166
WARNLOG("Job %s completed with unknown status condition [%s] - assuming success based on expert/@k8sFailOnUnknownErr=false", jobName.str(), output.str());
@@ -185,15 +185,15 @@ void waitJob(const char *componentName, const char *resourceType, const char *jo
185185
schedulingTimeout = true;
186186
VStringBuffer getReason("kubectl get pods --selector=job-name=%s \"--output=jsonpath={range .items[*].status.conditions[?(@.type=='PodScheduled')]}{.reason}{': '}{.message}{end}\"", jobName.str());
187187
runKubectlCommand(componentName, getReason, nullptr, &output.clear());
188-
throw makeStringExceptionV(0, "Failed to run %s - pod not scheduled after %u seconds: %s ", jobName.str(), pendingTimeoutSecs, output.str());
188+
throw makeStringExceptionV(JLIBERR_UtilFailedToRunSPodNot, "Failed to run %s - pod not scheduled after %u seconds: %s ", jobName.str(), pendingTimeoutSecs, output.str());
189189
}
190190
else if (streq(output, "True"))
191191
wasScheduled = true;
192192
}
193193
if (0 == totalWaitTimeSecs)
194194
break;
195195
if ((INFINITE != totalWaitTimeSecs) && msTick()-start > totalWaitTimeSecs*1000)
196-
throw makeStringExceptionV(0, "Wait job timeout (%u secs) expired, whilst running: %s", totalWaitTimeSecs, jobName.str());
196+
throw makeStringExceptionV(JLIBERR_UtilWaitJobTimeoutUSecsExpiredWhilst, "Wait job timeout (%u secs) expired, whilst running: %s", totalWaitTimeSecs, jobName.str());
197197

198198
MilliSleep(delay);
199199
if (delay < 10000)
@@ -373,7 +373,7 @@ std::vector<std::vector<std::string>> getPodNodes(const char *selector)
373373
runKubectlCommand("get-worker-nodes", getWorkerNodes, nullptr, &result);
374374

375375
if (result.isEmpty())
376-
throw makeStringExceptionV(-1, "No worker nodes found for selector '%s'", selector);
376+
throw makeStringExceptionV(JLIBERR_UtilNoWorkerNodesFoundForSelectorS, "No worker nodes found for selector '%s'", selector);
377377

378378
const char *start = result.str();
379379
const char *finger = start;
@@ -387,7 +387,7 @@ std::vector<std::vector<std::string>> getPodNodes(const char *selector)
387387
case ',':
388388
{
389389
if (start == finger)
390-
throw makeStringException(-1, "getPodNodes: Missing node name(s) in output");
390+
throw makeStringException(JLIBERR_UtilGetpodnodesMissingNodeNameSInOutput, "getPodNodes: Missing node name(s) in output");
391391
fieldName.assign(start, finger-start);
392392
current.emplace_back(std::move(fieldName));
393393
finger++;
@@ -398,7 +398,7 @@ std::vector<std::vector<std::string>> getPodNodes(const char *selector)
398398
case '\0':
399399
{
400400
if (start == finger)
401-
throw makeStringException(-1, "getPodNodes: Missing pod name(s) in output");
401+
throw makeStringException(JLIBERR_UtilGetpodnodesMissingPodNameSInOutput, "getPodNodes: Missing pod name(s) in output");
402402
fieldName.assign(start, finger-start);
403403
current.emplace_back(std::move(fieldName));
404404
results.emplace_back(std::move(current));
@@ -443,7 +443,7 @@ void runKubectlCommand(const char *title, const char *cmd, const char *input, St
443443
{
444444
if (input)
445445
MLOG(MCdebugError, "Using input %s", input);
446-
throw makeStringExceptionV(0, "Failed to run %s: error %u: %s", cmd, ret, error.str());
446+
throw makeStringExceptionV(JLIBERR_UtilFailedToRunSErrorUS, "Failed to run %s: error %u: %s", cmd, ret, error.str());
447447
}
448448
return;
449449
}
@@ -491,7 +491,7 @@ std::pair<std::string, unsigned> getExternalService(const char *serviceName)
491491
VStringBuffer exceptionText("Failed to get external service for '%s'. Error: [%d, ", serviceName, e->errorCode());
492492
e->errorMessage(exceptionText).append("]");
493493
e->Release();
494-
throw makeStringException(-1, exceptionText);
494+
throw makeStringException(JLIBERR_UtilK8sServiceQueryFailed, exceptionText);
495495
}
496496
StringArray fields;
497497
fields.appendList(output, ",");

system/jlib/jcrc.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ unsigned crc32(const char *buf, unsigned len, unsigned crc)
148148

149149
#else // _USE_OLD_CRC32
150150

151+
//LNRSPII:LINES_3:NON_IDENTIFYING:PERSON,DL_OR_DOB:hallidgx_risk
151152
/////////////////////////////////////////////////////////////
152153
// Copyright (c) 2011-2013 Stephan Brumme. All rights reserved.
153154
// see http://create.stephan-brumme.com/disclaimer.html

system/jlib/jdebug.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <time.h>
3434
#include <atomic>
3535
#include <cmath>
36+
#include "jerror.hpp"
3637

3738
#ifdef _WIN32
3839
#define DPSAPI_VERSION 1
@@ -527,7 +528,7 @@ class DefaultTimeReporter : implements ITimeReporter, public CInterface
527528
if (!idx--)
528529
return (TimeSectionInfo &) iter.query();
529530
}
530-
throw MakeStringException(2, "Invalid index to DefaultTimeReporter");
531+
throw MakeStringException(JLIBERR_UtilInvalidIndexToDefaulttimereporter, "Invalid index to DefaultTimeReporter");
531532
}
532533
public:
533534
IMPLEMENT_IINTERFACE
@@ -1784,7 +1785,7 @@ bool applyResourcedCPUAffinity(const IPropertyTree *resourceSection)
17841785
return false;
17851786
double cpus = friendlyCPUToDecimal(cpusText);
17861787
if (0.0 == cpus)
1787-
throw makeStringExceptionV(0, "Invalid number of resources cpus: %s", cpusText);
1788+
throw makeStringExceptionV(JLIBERR_UtilInvalidNumberOfResourcesCpusS, "Invalid number of resources cpus: %s", cpusText);
17881789
unsigned __int64 cpusI = (unsigned __int64)std::ceil(cpus);
17891790
if (cpus != (double)cpusI)
17901791
OWARNLOG("Fractional number of CPUs '%s' specified can cause poor performance, rounding up to: %" I64F "u", cpusText, cpusI);

system/jlib/jencrypt.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818

1919
#include "jencrypt.hpp"
20+
#include "jerror.hpp"
2021

2122
#ifdef _USE_OPENSSL
2223

@@ -1778,7 +1779,7 @@ inline Rijndael::KeyLength getAesKeyType(size_t keylen)
17781779
if (keylen==24)
17791780
return Rijndael::Key24Bytes;
17801781
if (keylen < 32)
1781-
throw MakeStringException(-1,"AES Encryption error: %d is not a valid key length", (unsigned)keylen);
1782+
throw MakeStringException(JLIBERR_UtilAesEncryptionErrorDIsNotA,"AES Encryption error: %d is not a valid key length", (unsigned)keylen);
17821783

17831784
return Rijndael::Key32Bytes;
17841785
}
@@ -1798,7 +1799,7 @@ MemoryBuffer &aesEncrypt(const void *key, size_t keylen, const void *input, size
17981799
if(len >= 0)
17991800
output.setLength(origLen+len);
18001801
else
1801-
throw MakeStringException(-1,"AES Encryption error: %d, %s", len, getAesErrorText(len));
1802+
throw MakeStringException(JLIBERR_UtilAesEncryptionErrorDS,"AES Encryption error: %d, %s", len, getAesErrorText(len));
18021803
return output;
18031804
}
18041805

@@ -1814,7 +1815,7 @@ MemoryBuffer &aesDecrypt(const void *key, size_t keylen, const void *input, size
18141815
if(len >= 0)
18151816
output.setLength(origLen+len);
18161817
else
1817-
throw MakeStringException(-1,"AES Decryption error: %d, %s", len, getAesErrorText(len));
1818+
throw MakeStringException(JLIBERR_UtilAesDecryptionErrorDS,"AES Decryption error: %d, %s", len, getAesErrorText(len));
18181819
return output;
18191820
}
18201821

@@ -1824,7 +1825,7 @@ size_t aesEncryptInPlace(const void *key, size_t keylen, void *buffer, size_t in
18241825
return 0;
18251826
// Make sure there is space for the padding. This is up to 16 bytes
18261827
if (maxlen - inlen < 16)
1827-
throw MakeStringException(-1,"AES Encryption error: Insufficient space in input buffer");
1828+
throw MakeStringException(JLIBERR_UtilAesEncryptionErrorInsufficientSpaceInInput,"AES Encryption error: Insufficient space in input buffer");
18281829
Rijndael rin;
18291830
Rijndael::KeyLength keyType = getAesKeyType(keylen);
18301831

@@ -1834,7 +1835,7 @@ size_t aesEncryptInPlace(const void *key, size_t keylen, void *buffer, size_t in
18341835
if(len >= 0)
18351836
return len;
18361837
else
1837-
throw MakeStringException(-1,"AES Encryption error: %d, %s", len, getAesErrorText(len));
1838+
throw MakeStringException(JLIBERR_UtilAesEncryptionErrorDS_1,"AES Encryption error: %d, %s", len, getAesErrorText(len));
18381839
}
18391840

18401841
size_t aesDecryptInPlace(const void *key, size_t keylen, void *data, size_t inlen)
@@ -1846,7 +1847,7 @@ size_t aesDecryptInPlace(const void *key, size_t keylen, void *data, size_t inle
18461847
size32_t truncInLen = (size32_t)inlen;
18471848
int len = rin.padDecrypt((const UINT8 *)data, truncInLen, (UINT8 *) data, inlen);
18481849
if(len < 0)
1849-
throw MakeStringException(-1,"AES Decryption error: %d, %s", len, getAesErrorText(len));
1850+
throw MakeStringException(JLIBERR_UtilAesDecryptionErrorDS_1,"AES Decryption error: %d, %s", len, getAesErrorText(len));
18501851
return len;
18511852
}
18521853

@@ -1859,7 +1860,7 @@ static void encryptError(const char *what)
18591860
{
18601861
char errorMessage[256];
18611862
ERR_error_string_n(ERR_get_error(), errorMessage, sizeof(errorMessage));
1862-
throw makeStringExceptionV(0, "openssl::aesEncrypt: unexpected failure in %s: %s", what, errorMessage);
1863+
throw makeStringExceptionV(JLIBERR_UtilOpensslAesencryptUnexpectedFailureInSS, "openssl::aesEncrypt: unexpected failure in %s: %s", what, errorMessage);
18631864
}
18641865

18651866
MemoryBuffer &aesEncrypt(const void *key, size_t keylen, const void *plaintext, size_t plaintext_len, MemoryBuffer &output)
@@ -1965,7 +1966,7 @@ static void decryptError(const char *what)
19651966
{
19661967
char errorMessage[256];
19671968
ERR_error_string_n(ERR_get_error(), errorMessage, sizeof(errorMessage));
1968-
throw makeStringExceptionV(0, "openssl::aesDecrypt: unexpected failure in %s: %s", what, errorMessage);
1969+
throw makeStringExceptionV(JLIBERR_UtilOpensslAesdecryptUnexpectedFailureInSS, "openssl::aesDecrypt: unexpected failure in %s: %s", what, errorMessage);
19691970
}
19701971

19711972
MemoryBuffer &aesDecrypt(const void *key, size_t keylen, const void *ciphertext, size_t ciphertext_len, MemoryBuffer &output)

0 commit comments

Comments
 (0)