浏览代码

Merge pull request #9347 from richardkchapman/jenkins-errors

HPCC-16643 Improve reporting of assert failures

Reviewed-by: Gavin Halliday <ghalliday@hpccsystems.com>
Gavin Halliday 8 年之前
父节点
当前提交
06f11acddc

+ 1 - 1
ecl/eclagent/eclgraph.cpp

@@ -321,7 +321,7 @@ static IHThorActivity * createActivity(IAgentContext & agent, unsigned activityI
     case TAKstreamediterator:
         return createStreamedIteratorActivity(agent, activityId, subgraphId, (IHThorStreamedIteratorArg &)arg, kind);
     }
-    throw MakeStringException(-1, "UNIMPLEMENTED activity '%s'(kind=%d) at %s(%d)", activityKindStr(kind), kind, __FILE__, __LINE__);
+    throw MakeStringException(-1, "UNIMPLEMENTED activity '%s'(kind=%d) at %s(%d)", activityKindStr(kind), kind, sanitizeSourceFile(__FILE__), __LINE__);
 }
 
 //---------------------------------------------------------------------------

+ 2 - 2
ecl/hql/hqlerrors.hpp

@@ -544,7 +544,7 @@
 #define ERRORAT2(e, x, a, b)        reportError(e, x, x##_Text, a, b)
 #define ERRORAT3(e, x, a, b, c)     reportError(e, x, x##_Text, a, b, c)
 
-#define throwUnexpectedOp(op)       throw MakeStringException(ECODETEXT(HQLERR_UnexpectedOperator), getOpString(op), __FILE__, __LINE__)
-#define throwUnexpectedType(type)   throw MakeStringException(ECODETEXT(HQLERR_UnexpectedType), type->queryTypeName(), __FILE__, __LINE__)
+#define throwUnexpectedOp(op)       throw MakeStringException(ECODETEXT(HQLERR_UnexpectedOperator), getOpString(op), sanitizeSourceFile(__FILE__), __LINE__)
+#define throwUnexpectedType(type)   throw MakeStringException(ECODETEXT(HQLERR_UnexpectedType), type->queryTypeName(), sanitizeSourceFile(__FILE__), __LINE__)
 
 #endif // _HQLERRORS_HPP_

+ 1 - 1
roxie/ccd/ccd.hpp

@@ -445,7 +445,7 @@ extern StringBuffer tempDirectory;
 #undef throwUnexpected
 extern void doUNIMPLEMENTED(unsigned line, const char *file);
 #define UNIMPLEMENTED { doUNIMPLEMENTED(__LINE__, __FILE__); throw MakeStringException(ROXIE_UNIMPLEMENTED_ERROR, "UNIMPLEMENTED"); }
-#define throwUnexpected()          throw MakeStringException(ROXIE_INTERNAL_ERROR, "Internal Error at %s(%d)", __FILE__, __LINE__)
+#define throwUnexpected()          throw MakeStringException(ROXIE_INTERNAL_ERROR, "Internal Error at %s(%d)", sanitizeSourceFile(__FILE__), __LINE__)
 
 extern IRoxieQueryPacket *createRoxiePacket(void *data, unsigned length);
 extern IRoxieQueryPacket *createRoxiePacket(MemoryBuffer &donor); // note: donor is empty after call

+ 1 - 1
roxie/ccd/ccdmain.cpp

@@ -330,7 +330,7 @@ void addChannel(unsigned nodeNumber, unsigned channel, unsigned level)
 
 extern void doUNIMPLEMENTED(unsigned line, const char *file)
 {
-    throw MakeStringException(ROXIE_UNIMPLEMENTED_ERROR, "UNIMPLEMENTED at %s:%d", file, line);
+    throw MakeStringException(ROXIE_UNIMPLEMENTED_ERROR, "UNIMPLEMENTED at %s:%d", sanitizeSourceFile(file), line);
 }
 
 void FatalError(const char *format, ...)

+ 14 - 14
roxie/ccd/ccdserver.cpp

@@ -722,9 +722,9 @@ public:
     inline void setInput(unsigned idx, unsigned source, unsigned sourceidx)
     {
         if (idx != 0)
-            throw MakeStringException(ROXIE_SET_INPUT, "Internal error: id = %d : setInput() parameter out of bounds idx = %d at %s(%d)", id, idx, __FILE__, __LINE__); 
+            throw MakeStringException(ROXIE_SET_INPUT, "Internal error: id = %d : setInput() parameter out of bounds idx = %d at %s(%d)", id, idx, sanitizeSourceFile(__FILE__), __LINE__);
         if (input != -1)
-            throw MakeStringException(ROXIE_SET_INPUT, "Internal error: id = %d : setInput() called twice for input = %d source = %d  inputidx = %d  sourceidx = %d at %s(%d)", id, input, source, inputidx, sourceidx, __FILE__, __LINE__); 
+            throw MakeStringException(ROXIE_SET_INPUT, "Internal error: id = %d : setInput() called twice for input = %d source = %d  inputidx = %d  sourceidx = %d at %s(%d)", id, input, source, inputidx, sourceidx, sanitizeSourceFile(__FILE__), __LINE__);
         input = source;
         inputidx = sourceidx;
     }
@@ -2507,7 +2507,7 @@ public:
             sourceIdx1 = _sourceIdx;
             break;
         default:
-            throw MakeStringException(ROXIE_SET_INPUT, "Internal error: setInput() parameter out of bounds at %s(%d)", __FILE__, __LINE__); 
+            throw MakeStringException(ROXIE_SET_INPUT, "Internal error: setInput() parameter out of bounds at %s(%d)", sanitizeSourceFile(__FILE__), __LINE__);
         }   
     }
 
@@ -2742,7 +2742,7 @@ public:
             }
             catch (...)
             {
-                exception.set(MakeStringException(ROXIE_INTERNAL_ERROR, "Unknown exception caught at %s:%d", __FILE__, __LINE__));
+                exception.set(MakeStringException(ROXIE_INTERNAL_ERROR, "Unknown exception caught at %s:%d", sanitizeSourceFile(__FILE__), __LINE__));
                 abort();
                 throw;
             }
@@ -5755,7 +5755,7 @@ public:
         }
         catch(...)
         {
-            Owned<IException> E = MakeStringException(ROXIE_INTERNAL_ERROR, "Unknown exception caught at %s:%d", __FILE__, __LINE__);
+            Owned<IException> E = MakeStringException(ROXIE_INTERNAL_ERROR, "Unknown exception caught at %s:%d", sanitizeSourceFile(__FILE__), __LINE__);
             ctx->notifyAbort(E);
             abort();
             reset(); 
@@ -9314,7 +9314,7 @@ public:
     virtual void setInput(unsigned idx, unsigned _sourceIdx, IFinalRoxieInput *_in)
     {
         if (idx)
-            throw MakeStringException(ROXIE_SET_INPUT, "Internal error: setInput() parameter out of bounds at %s(%d)", __FILE__, __LINE__); 
+            throw MakeStringException(ROXIE_SET_INPUT, "Internal error: setInput() parameter out of bounds at %s(%d)", sanitizeSourceFile(__FILE__), __LINE__);
         puller.setInput(this, _sourceIdx, _in);
         inputMeta.set(_in->queryOutputMeta());
     }
@@ -13142,7 +13142,7 @@ public:
         if (pullers.isItem(idx))
             pullers.item(idx).setInput(_sourceIdx, _in);
         else
-            throw MakeStringException(ROXIE_SET_INPUT, "Internal error: setInput() parameter out of bounds at %s(%d)", __FILE__, __LINE__); 
+            throw MakeStringException(ROXIE_SET_INPUT, "Internal error: setInput() parameter out of bounds at %s(%d)", sanitizeSourceFile(__FILE__), __LINE__);
     }
 
     virtual IStrandJunction *getOutputStreams(IRoxieSlaveContext *ctx, unsigned idx, PointerArrayOf<IEngineRowStream> &streams, const StrandOptions * consumerOptions, bool consumerOrdered, IOrderedCallbackCollection * orderedCallbacks)
@@ -14378,7 +14378,7 @@ public:
     virtual void setInput(unsigned idx, unsigned _sourceIdx, IFinalRoxieInput *_in)
     {
         if (idx)
-            throw MakeStringException(ROXIE_SET_INPUT, "Internal error: setInput() parameter out of bounds at %s(%d)", __FILE__, __LINE__); 
+            throw MakeStringException(ROXIE_SET_INPUT, "Internal error: setInput() parameter out of bounds at %s(%d)", sanitizeSourceFile(__FILE__), __LINE__);
         puller.setInput(this, _sourceIdx, _in);
     }
 
@@ -14995,7 +14995,7 @@ public:
     virtual void setInput(unsigned idx, unsigned _sourceIdx, IFinalRoxieInput *_in)
     {
         if (idx)
-            throw MakeStringException(ROXIE_SET_INPUT, "Internal error: setInput() parameter out of bounds at %s(%d)", __FILE__, __LINE__); 
+            throw MakeStringException(ROXIE_SET_INPUT, "Internal error: setInput() parameter out of bounds at %s(%d)", sanitizeSourceFile(__FILE__), __LINE__);
         executor.setInput(this, _sourceIdx, _in, flags);
     }
 
@@ -24405,7 +24405,7 @@ public:
     virtual void setInput(unsigned idx, unsigned _sourceIdx, IFinalRoxieInput *_in)
     {
         if (idx)
-            throw MakeStringException(ROXIE_SET_INPUT, "Internal error: setInput() parameter out of bounds at %s(%d)", __FILE__, __LINE__); 
+            throw MakeStringException(ROXIE_SET_INPUT, "Internal error: setInput() parameter out of bounds at %s(%d)", sanitizeSourceFile(__FILE__), __LINE__);
         puller.setInput(this, _sourceIdx, _in);
     }
 
@@ -24650,7 +24650,7 @@ public:
         }
     }
 
-    virtual IRoxieServerActivity *createActivity(IRoxieSlaveContext *_ctx, IProbeManager *_probeManager) const { throw MakeStringException(ROXIE_INTERNAL_ERROR, "%s query %s is suspended and cannot be executed - error occurred at %s(%d)", (queryFactory.isQueryLibrary()) ? "Library" : " ", queryFactory.queryQueryName(), __FILE__, __LINE__); }
+    virtual IRoxieServerActivity *createActivity(IRoxieSlaveContext *_ctx, IProbeManager *_probeManager) const { throw MakeStringException(ROXIE_INTERNAL_ERROR, "%s query %s is suspended and cannot be executed - error occurred at %s(%d)", (queryFactory.isQueryLibrary()) ? "Library" : " ", queryFactory.queryQueryName(), sanitizeSourceFile(__FILE__), __LINE__); }
 
     virtual void getXrefInfo(IPropertyTree &reply, const IRoxieContextLogger &logctx) const
     {
@@ -25109,7 +25109,7 @@ public:
             indexReadIdx = _sourceIdx;
         }
         else
-            throw MakeStringException(ROXIE_SET_INPUT, "Internal error: setInput() parameter out of bounds at %s(%d)", __FILE__, __LINE__); 
+            throw MakeStringException(ROXIE_SET_INPUT, "Internal error: setInput() parameter out of bounds at %s(%d)", sanitizeSourceFile(__FILE__), __LINE__);
     }
 
     virtual IStrandJunction *getOutputStreams(IRoxieSlaveContext *ctx, unsigned idx, PointerArrayOf<IEngineRowStream> &streams, const StrandOptions * consumerOptions, bool consumerOrdered, IOrderedCallbackCollection * orderedCallbacks)
@@ -25465,7 +25465,7 @@ public:
             indexReadIdx = _sourceIdx;
         }
         else
-            throw MakeStringException(ROXIE_SET_INPUT, "Internal error: setInput() parameter out of bounds at %s(%d)", __FILE__, __LINE__); 
+            throw MakeStringException(ROXIE_SET_INPUT, "Internal error: setInput() parameter out of bounds at %s(%d)", sanitizeSourceFile(__FILE__), __LINE__);
     }
 
     virtual void connectInputStreams(bool consumerOrdered)
@@ -26581,7 +26581,7 @@ public:
         }
         catch(...)
         {
-            Owned<IException> E = MakeStringException(ROXIE_INTERNAL_ERROR, "Unknown exception caught at %s:%d", __FILE__, __LINE__);
+            Owned<IException> E = MakeStringException(ROXIE_INTERNAL_ERROR, "Unknown exception caught at %s:%d", sanitizeSourceFile(__FILE__), __LINE__);
             ctx->notifyAbort(E);
             abort();
             throw;

+ 20 - 4
system/jlib/jexcept.cpp

@@ -496,16 +496,32 @@ void userBreakpoint()
 #endif
 }
 
+const char *sanitizeSourceFile(const char *file)
+{
+    if (file)
+    {
+        const char *tail = strrchr(file, '/');
+        if (tail)
+            return tail+1;
+#ifdef _WIN32
+        tail = strrchr(file, '\\');
+        if (tail)
+            return tail+1;
+#endif
+    }
+    return file;
+}
+
 void throwUnexpectedException(const char * file, unsigned line)
 {
     printStackReport();
-    throw makeStringExceptionV(9999, "Internal Error at %s(%d)", file, line);
+    throw makeStringExceptionV(9999, "Internal Error at %s(%d)", sanitizeSourceFile(file), line);
 }
 
 void throwUnexpectedException(const char * where, const char * file, unsigned line)
 {
     printStackReport();
-    throw makeStringExceptionV(9999, "Internal Error '%s' at %s(%d)", where, file, line);
+    throw makeStringExceptionV(9999, "Internal Error '%s' at %s(%d)", where, sanitizeSourceFile(file), line);
 }
 
 void raiseAssertException(const char *assertion, const char *file, unsigned line)
@@ -514,7 +530,7 @@ void raiseAssertException(const char *assertion, const char *file, unsigned line
     s.append("assert(");
     s.append(assertion);
     s.append(") failed - file: ");
-    s.append(file);
+    s.append(sanitizeSourceFile(file));
     s.append(", line ");
     s.append(line);
 
@@ -550,7 +566,7 @@ void raiseAssertCore(const char *assertion, const char *file, unsigned line)
     s.append("assert(");
     s.append(assertion);
     s.append(") failed - file: ");
-    s.append(file);
+    s.append(sanitizeSourceFile(file));
     s.append(", line ");
     s.append(line);
     ERRLOG("%s",s.str());       // make sure doesn't get lost!

+ 8 - 6
system/jlib/jexcept.hpp

@@ -130,14 +130,16 @@ void jlib_decl setTerminateOnSEH(bool set=true);
 __declspec(noreturn) void jlib_decl throwUnexpectedException(const char * file, unsigned line) __attribute__((noreturn));
 __declspec(noreturn) void jlib_decl throwUnexpectedException(const char * where, const char * file, unsigned line) __attribute__((noreturn));
 
-#define makeUnexpectedException()  makeStringExceptionV(9999, "Internal Error at %s(%d)", __FILE__, __LINE__)
-#define throwUnexpected()          throwUnexpectedException(__FILE__, __LINE__)
-#define throwUnexpectedX(x)        throwUnexpectedException(x, __FILE__, __LINE__)
+const char jlib_decl *sanitizeSourceFile(const char *file);
+
+#define makeUnexpectedException()  makeStringExceptionV(9999, "Internal Error at %s(%d)", sanitizeSourceFile(__FILE__), __LINE__)
+#define throwUnexpected()          throwUnexpectedException(sanitizeSourceFile(__FILE__), __LINE__)
+#define throwUnexpectedX(x)        throwUnexpectedException(x, sanitizeSourceFile(__FILE__), __LINE__)
 #define assertThrow(x)             assertex(x)
 
-#define UNIMPLEMENTED throw makeStringExceptionV(-1, "UNIMPLEMENTED feature at %s(%d)", __FILE__, __LINE__)
-#define UNIMPLEMENTED_X(reason) throw makeStringExceptionV(-1, "UNIMPLEMENTED '" reason "' at %s(%d)", __FILE__, __LINE__)
-#define UNIMPLEMENTED_XY(a,b) throw makeStringExceptionV(-1, "UNIMPLEMENTED " a " %s at %s(%d)", b, __FILE__, __LINE__)
+#define UNIMPLEMENTED throw makeStringExceptionV(-1, "UNIMPLEMENTED feature at %s(%d)", sanitizeSourceFile(__FILE__), __LINE__)
+#define UNIMPLEMENTED_X(reason) throw makeStringExceptionV(-1, "UNIMPLEMENTED '" reason "' at %s(%d)", sanitizeSourceFile(__FILE__), __LINE__)
+#define UNIMPLEMENTED_XY(a,b) throw makeStringExceptionV(-1, "UNIMPLEMENTED " a " %s at %s(%d)", b, sanitizeSourceFile(__FILE__), __LINE__)
 
 IException jlib_decl * deserializeException(MemoryBuffer & in); 
 void jlib_decl serializeException(IException * e, MemoryBuffer & out); 

+ 1 - 1
system/jlib/jlog.cpp

@@ -2568,7 +2568,7 @@ public:
         if (E)
             ss.append(": ").append(E->errorCode());
         if (file)
-            ss.appendf(": %s(%d) ", file, line);
+            ss.appendf(": %s(%d) ", sanitizeSourceFile(file), line);
         if (E)
             E->errorMessage(ss.append(": "));
         if (format)

+ 1 - 1
system/jlib/jlog.hpp

@@ -610,7 +610,7 @@ private:
 class jlib_decl LogMsgPrepender
 {
 public:
-    LogMsgPrepender(LogMsgComponentReporter * r, char const * f, unsigned l) : reporter(r), file(f), line(l) { }
+    LogMsgPrepender(LogMsgComponentReporter * r, char const * f, unsigned l) : reporter(r), file(sanitizeSourceFile(f)), line(l) { }
     void                      report(const LogMsgCategory & cat, const char * format, ...) __attribute__((format(printf, 3, 4)));
     void                      report_va(const LogMsgCategory & cat, const char * format, va_list args);
     void                      report(const LogMsgCategory & cat, LogMsgCode code, const char * format, ...) __attribute__((format(printf, 4, 5)));

+ 4 - 4
system/jlib/jsocket.cpp

@@ -110,12 +110,12 @@
 #ifdef _TRACE
 #define THROWJSOCKEXCEPTION(exc) \
   { StringBuffer msg; \
-    msg.appendf("Target: %s, Raised in: %s, line %d",tracename ,__FILE__, __LINE__); \
+    msg.appendf("Target: %s, Raised in: %s, line %d",tracename ,sanitizeSourceFile(__FILE__), __LINE__); \
     IJSOCK_Exception *e = new SocketException(exc,msg.str());\
     throw e; }
 #define THROWJSOCKEXCEPTION2(exc) \
   { StringBuffer msg; \
-    msg.appendf("Raised in: %s, line %d",__FILE__, __LINE__); \
+    msg.appendf("Raised in: %s, line %d",sanitizeSourceFile(__FILE__), __LINE__); \
     IJSOCK_Exception *e = new SocketException(exc,msg.str());\
     throw e; }
 #define LOGERR(err,ref,info) LogErr(err,ref,info,__LINE__,NULL)
@@ -826,7 +826,7 @@ int CSocket::pre_connect (bool block)
     if (NULL == hostname || '\0' == (*hostname))
     {
         StringBuffer err;
-        err.appendf("CSocket::pre_connect - Invalid/missing host IP address raised in : %s, line %d",__FILE__, __LINE__);
+        err.appendf("CSocket::pre_connect - Invalid/missing host IP address raised in : %s, line %d",sanitizeSourceFile(__FILE__), __LINE__);
         IJSOCK_Exception *e = new SocketException(JSOCKERR_bad_netaddr,err.str());
         throw e;
     }
@@ -940,7 +940,7 @@ void CSocket::open(int listen_queue_size,bool reuseports)
 ErrPortInUse:
             closesock();
             char msg[1024]; 
-            sprintf(msg,"Target: %s, port = %d, Raised in: %s, line %d",tracename,(int)hostport,__FILE__, __LINE__); 
+            sprintf(msg,"Target: %s, port = %d, Raised in: %s, line %d",tracename,(int)hostport,sanitizeSourceFile(__FILE__), __LINE__);
             IJSOCK_Exception *e = new SocketException(JSOCKERR_port_in_use,msg);
             throw e; 
         }

+ 1 - 1
system/jlib/jsocket.hpp

@@ -419,7 +419,7 @@ interface jlib_thrown_decl IJSOCK_Exception: extends IException
 };
 
 extern jlib_decl IJSOCK_Exception *IPv6NotImplementedException(const char *filename,unsigned lineno);
-#define IPV6_NOT_IMPLEMENTED() throw IPv6NotImplementedException(__FILE__, __LINE__)
+#define IPV6_NOT_IMPLEMENTED() throw IPv6NotImplementedException(sanitizeSourceFile(__FILE__), __LINE__)
 
 
 

+ 1 - 1
system/security/securesocket/securesocket.cpp

@@ -68,7 +68,7 @@ bool accept_selfsigned = false;
 #define CHK_SSL(err) if((err) ==-1){ERR_print_errors_fp(stderr); exit(2);}
 
 #define THROWSECURESOCKETEXCEPTION(err) \
-    throw MakeStringException(-1, "SecureSocket Exception Raised in: %s, line %d - %s", __FILE__, __LINE__, err);
+    throw MakeStringException(-1, "SecureSocket Exception Raised in: %s, line %d - %s", sanitizeSourceFile(__FILE__), __LINE__, err);
 
 
 static int pem_passwd_cb(char* buf, int size, int rwflag, void* password)

+ 1 - 1
testing/unittests/jlibtests.cpp

@@ -124,7 +124,7 @@ protected:
         sem.signal();
         if (!sem.wait(1000))
         {
-            VStringBuffer errMsg("Semaphore stalled (%s:%s)", __FILE__, __LINE__);
+            VStringBuffer errMsg("Semaphore stalled (%s:%s)", sanitizeSourceFile(__FILE__), __LINE__);
             CPPUNIT_FAIL(errMsg.str());
         }
         testTimedElapsed(sem, 5, 1000);