hqlerror.hpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #ifndef _HQLERROR_HPP_
  14. #define _HQLERROR_HPP_
  15. #include "jhash.hpp"
  16. #include "jexcept.hpp"
  17. #include "hql.hpp"
  18. #define HQLERR_ErrorAlreadyReported 4799 // special case...
  19. enum ErrorSeverity
  20. {
  21. SeverityIgnore,
  22. SeverityInfo,
  23. SeverityWarning,
  24. SeverityError, // a warning treated as an error
  25. SeverityFatal, // a fatal error - can't be mapped to anything else
  26. SeverityUnknown,
  27. };
  28. inline bool isError(ErrorSeverity severity) { return severity >= SeverityError; }
  29. inline bool isFatal(ErrorSeverity severity) { return severity == SeverityFatal; }
  30. //TBD in a separate commit - add support for warnings to be associated with different categories
  31. enum WarnErrorCategory
  32. {
  33. CategoryInformation,// Some kind of information [default severity information]
  34. CategoryCast, // Suspicious casts between types or out of range values
  35. CategoryConfuse, // Likely to cause confusion
  36. CategoryDeprecated, // deprecated features or syntax
  37. CategoryEfficiency, // Something that is likely to be inefficient
  38. CategoryFolding, // Unusual results from constant folding
  39. CategoryFuture, // Likely to cause problems in future versions
  40. CategoryIgnored, // Something that has no effect, or is ignored
  41. CategoryIndex, // Unusual indexing of datasets or strings
  42. CategoryMistake, // Almost certainly a mistake
  43. CategoryLimit, // An operation that should really have some limits to protect data runaway
  44. CategorySyntax, // Invalid syntax which is painless to recover from
  45. CategoryUnusual, // Not strictly speaking an error, but highly unusual and likely to be a mistake
  46. CategoryUnexpected, // Code that could be correct, but has the potential for unexpected behaviour
  47. CategoryError, // Typically severity fatal
  48. CategoryAll,
  49. CategoryUnknown,
  50. CategoryMax,
  51. };
  52. interface HQL_API IECLError: public IException
  53. {
  54. public:
  55. virtual const char* getFilename() const = 0;
  56. virtual WarnErrorCategory getCategory() const = 0;
  57. virtual int getLine() const = 0;
  58. virtual int getColumn() const = 0;
  59. virtual int getPosition() const = 0;
  60. virtual StringBuffer& toString(StringBuffer&) const = 0;
  61. virtual ErrorSeverity getSeverity() const = 0;
  62. virtual IECLError * cloneSetSeverity(ErrorSeverity _severity) const = 0;
  63. };
  64. inline bool isError(IECLError * error) { return isError(error->getSeverity()); }
  65. inline bool isFatal(IECLError * error) { return isFatal(error->getSeverity()); }
  66. interface HQL_API IErrorReceiver : public IInterface
  67. {
  68. virtual void report(IECLError* error) = 0;
  69. virtual IECLError * mapError(IECLError * error) = 0;
  70. virtual size32_t errCount() = 0;
  71. virtual size32_t warnCount() = 0;
  72. //global helper functions
  73. void reportError(int errNo, const char *msg, const char *filename, int lineno, int column, int pos);
  74. void reportWarning(WarnErrorCategory category, int warnNo, const char *msg, const char *filename, int lineno, int column, int pos);
  75. };
  76. typedef IArrayOf<IECLError> IECLErrorArray;
  77. //---------------------------------------------------------------------------------------------------------------------
  78. class HQL_API ErrorReceiverSink : public CInterfaceOf<IErrorReceiver>
  79. {
  80. public:
  81. ErrorReceiverSink() { errs = warns = 0; }
  82. virtual IECLError * mapError(IECLError * error) { return LINK(error); }
  83. virtual void report(IECLError* err);
  84. virtual size32_t errCount() { return errs; }
  85. virtual size32_t warnCount() { return warns; }
  86. private:
  87. unsigned errs;
  88. unsigned warns;
  89. };
  90. //---------------------------------------------------------------------------------------------------------------------
  91. class IndirectErrorReceiver : public CInterfaceOf<IErrorReceiver>
  92. {
  93. public:
  94. IndirectErrorReceiver(IErrorReceiver & _prev) : prevErrorProcessor(&_prev) {}
  95. virtual void report(IECLError* error)
  96. {
  97. prevErrorProcessor->report(error);
  98. }
  99. virtual IECLError * mapError(IECLError * error)
  100. {
  101. return prevErrorProcessor->mapError(error);
  102. }
  103. virtual size32_t errCount()
  104. {
  105. return prevErrorProcessor->errCount();
  106. }
  107. virtual size32_t warnCount()
  108. {
  109. return prevErrorProcessor->warnCount();
  110. }
  111. protected:
  112. Linked<IErrorReceiver> prevErrorProcessor;
  113. };
  114. //---------------------------------------------------------------------------------------------------------------------
  115. class HQL_API MultiErrorReceiver : public ErrorReceiverSink
  116. {
  117. public:
  118. MultiErrorReceiver() {}
  119. virtual void report(IECLError* err);
  120. size32_t length() { return errCount() + warnCount();}
  121. IECLError* item(size32_t index) { return &msgs.item(index); }
  122. IECLError* firstError();
  123. StringBuffer& toString(StringBuffer& out);
  124. void clear() { msgs.kill(); }
  125. private:
  126. IECLErrorArray msgs;
  127. };
  128. //---------------------------------------------------------------------------------------------------------------------
  129. extern HQL_API ErrorSeverity queryDefaultSeverity(WarnErrorCategory category);
  130. extern HQL_API WarnErrorCategory getCategory(const char * category);
  131. extern HQL_API ErrorSeverity getSeverity(IAtom * name);
  132. extern HQL_API ErrorSeverity getCheckSeverity(IAtom * name);
  133. //---------------------------------------------------------------------------------------------------------------------
  134. extern HQL_API IECLError *createECLError(WarnErrorCategory category, ErrorSeverity severity, int errNo, const char *msg, const char *filename, int lineno=0, int column=0, int pos=0);
  135. inline IECLError * createECLError(int errNo, const char *msg, const char *filename, int lineno=0, int column=0, int pos=0)
  136. {
  137. return createECLError(CategoryError, SeverityFatal, errNo, msg, filename, lineno, column, pos);
  138. }
  139. extern HQL_API void reportErrors(IErrorReceiver & receiver, IECLErrorArray & errors);
  140. void HQL_API reportErrorVa(IErrorReceiver * errors, int errNo, const ECLlocation & loc, const char* format, va_list args);
  141. void HQL_API reportError(IErrorReceiver * errors, int errNo, const ECLlocation & loc, const char * format, ...) __attribute__((format(printf, 4, 5)));
  142. extern HQL_API IErrorReceiver * createFileErrorReceiver(FILE *f);
  143. extern HQL_API IErrorReceiver * createNullErrorReceiver();
  144. extern HQL_API IErrorReceiver * createThrowingErrorReceiver();
  145. extern HQL_API IErrorReceiver * createAbortingErrorReceiver(IErrorReceiver & prev);
  146. extern HQL_API IErrorReceiver * createDedupingErrorReceiver(IErrorReceiver & prev);
  147. extern HQL_API void checkEclVersionCompatible(Shared<IErrorReceiver> & errors, const char * eclVersion);
  148. #endif // _HQLERROR_HPP_