nsError.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4. *
  5. * The contents of this file are subject to the Mozilla Public License Version
  6. * 1.1 (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. * http://www.mozilla.org/MPL/
  9. *
  10. * Software distributed under the License is distributed on an "AS IS" basis,
  11. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12. * for the specific language governing rights and limitations under the
  13. * License.
  14. *
  15. * The Original Code is mozilla.org code.
  16. *
  17. * The Initial Developer of the Original Code is
  18. * Netscape Communications Corporation.
  19. * Portions created by the Initial Developer are Copyright (C) 1998
  20. * the Initial Developer. All Rights Reserved.
  21. *
  22. * Contributor(s):
  23. *
  24. * Alternatively, the contents of this file may be used under the terms of
  25. * either of the GNU General Public License Version 2 or later (the "GPL"),
  26. * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27. * in which case the provisions of the GPL or the LGPL are applicable instead
  28. * of those above. If you wish to allow use of your version of this file only
  29. * under the terms of either the GPL or the LGPL, and not to allow others to
  30. * use your version of this file under the terms of the MPL, indicate your
  31. * decision by deleting the provisions above and replace them with the notice
  32. * and other provisions required by the GPL or the LGPL. If you do not delete
  33. * the provisions above, a recipient may use your version of this file under
  34. * the terms of any one of the MPL, the GPL or the LGPL.
  35. *
  36. * ***** END LICENSE BLOCK ***** */
  37. #ifndef nsError_h__
  38. #define nsError_h__
  39. #ifndef nscore_h___
  40. #include "nscore.h" /* needed for nsresult */
  41. #endif
  42. /*
  43. * To add error code to your module, you need to do the following:
  44. *
  45. * 1) Add a module offset code. Add yours to the bottom of the list
  46. * right below this comment, adding 1.
  47. *
  48. * 2) In your module, define a header file which uses one of the
  49. * NE_ERROR_GENERATExxxxxx macros. Some examples below:
  50. *
  51. * #define NS_ERROR_MYMODULE_MYERROR1 NS_ERROR_GENERATE(NS_ERROR_SEVERITY_ERROR,NS_ERROR_MODULE_MYMODULE,1)
  52. * #define NS_ERROR_MYMODULE_MYERROR2 NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_MYMODULE,2)
  53. * #define NS_ERROR_MYMODULE_MYERROR3 NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_MYMODULE,3)
  54. *
  55. */
  56. /**
  57. * @name Standard Module Offset Code. Each Module should identify a unique number
  58. * and then all errors associated with that module become offsets from the
  59. * base associated with that module id. There are 16 bits of code bits for
  60. * each module.
  61. */
  62. #define NS_ERROR_MODULE_XPCOM 1
  63. #define NS_ERROR_MODULE_BASE 2
  64. #define NS_ERROR_MODULE_GFX 3
  65. #define NS_ERROR_MODULE_WIDGET 4
  66. #define NS_ERROR_MODULE_CALENDAR 5
  67. #define NS_ERROR_MODULE_NETWORK 6
  68. #define NS_ERROR_MODULE_PLUGINS 7
  69. #define NS_ERROR_MODULE_LAYOUT 8
  70. #define NS_ERROR_MODULE_HTMLPARSER 9
  71. #define NS_ERROR_MODULE_RDF 10
  72. #define NS_ERROR_MODULE_UCONV 11
  73. #define NS_ERROR_MODULE_REG 12
  74. #define NS_ERROR_MODULE_FILES 13
  75. #define NS_ERROR_MODULE_DOM 14
  76. #define NS_ERROR_MODULE_IMGLIB 15
  77. #define NS_ERROR_MODULE_MAILNEWS 16
  78. #define NS_ERROR_MODULE_EDITOR 17
  79. #define NS_ERROR_MODULE_XPCONNECT 18
  80. #define NS_ERROR_MODULE_PROFILE 19
  81. #define NS_ERROR_MODULE_LDAP 20
  82. #define NS_ERROR_MODULE_SECURITY 21
  83. #define NS_ERROR_MODULE_DOM_XPATH 22
  84. #define NS_ERROR_MODULE_DOM_RANGE 23
  85. #define NS_ERROR_MODULE_URILOADER 24
  86. #define NS_ERROR_MODULE_CONTENT 25
  87. #define NS_ERROR_MODULE_PYXPCOM 26
  88. #define NS_ERROR_MODULE_XSLT 27
  89. #define NS_ERROR_MODULE_IPC 28
  90. #define NS_ERROR_MODULE_SVG 29
  91. #define NS_ERROR_MODULE_STORAGE 30
  92. #define NS_ERROR_MODULE_SCHEMA 31
  93. /* NS_ERROR_MODULE_GENERAL should be used by modules that do not
  94. * care if return code values overlap. Callers of methods that
  95. * return such codes should be aware that they are not
  96. * globally unique. Implementors should be careful about blindly
  97. * returning codes from other modules that might also use
  98. * the generic base.
  99. */
  100. #define NS_ERROR_MODULE_GENERAL 51
  101. /**
  102. * @name Standard Error Handling Macros
  103. */
  104. #define NS_FAILED(_nsresult) (NS_UNLIKELY((_nsresult) & 0x80000000))
  105. #define NS_SUCCEEDED(_nsresult) (NS_LIKELY(!((_nsresult) & 0x80000000)))
  106. /**
  107. * @name Severity Code. This flag identifies the level of warning
  108. */
  109. #define NS_ERROR_SEVERITY_SUCCESS 0
  110. #define NS_ERROR_SEVERITY_ERROR 1
  111. /**
  112. * @name Mozilla Code. This flag separates consumers of mozilla code
  113. * from the native platform
  114. */
  115. #define NS_ERROR_MODULE_BASE_OFFSET 0x45
  116. /**
  117. * @name Standard Error Generating Macros
  118. */
  119. #define NS_ERROR_GENERATE(sev,module,code) \
  120. ((nsresult) (((PRUint32)(sev)<<31) | ((PRUint32)(module+NS_ERROR_MODULE_BASE_OFFSET)<<16) | ((PRUint32)(code))) )
  121. #define NS_ERROR_GENERATE_SUCCESS(module,code) \
  122. ((nsresult) (((PRUint32)(NS_ERROR_SEVERITY_SUCCESS)<<31) | ((PRUint32)(module+NS_ERROR_MODULE_BASE_OFFSET)<<16) | ((PRUint32)(code))) )
  123. #define NS_ERROR_GENERATE_FAILURE(module,code) \
  124. ((nsresult) (((PRUint32)(NS_ERROR_SEVERITY_ERROR)<<31) | ((PRUint32)(module+NS_ERROR_MODULE_BASE_OFFSET)<<16) | ((PRUint32)(code))) )
  125. /**
  126. * @name Standard Macros for retrieving error bits
  127. */
  128. #define NS_ERROR_GET_CODE(err) ((err) & 0xffff)
  129. #define NS_ERROR_GET_MODULE(err) (((((err) >> 16) - NS_ERROR_MODULE_BASE_OFFSET) & 0x1fff))
  130. #define NS_ERROR_GET_SEVERITY(err) (((err) >> 31) & 0x1)
  131. /**
  132. * @name Standard return values
  133. */
  134. /*@{*/
  135. /* Standard "it worked" return value */
  136. #define NS_OK 0
  137. #define NS_ERROR_BASE ((nsresult) 0xC1F30000)
  138. /* Returned when an instance is not initialized */
  139. #define NS_ERROR_NOT_INITIALIZED (NS_ERROR_BASE + 1)
  140. /* Returned when an instance is already initialized */
  141. #define NS_ERROR_ALREADY_INITIALIZED (NS_ERROR_BASE + 2)
  142. /* Returned by a not implemented function */
  143. #define NS_ERROR_NOT_IMPLEMENTED ((nsresult) 0x80004001L)
  144. /* Returned when a given interface is not supported. */
  145. #define NS_NOINTERFACE ((nsresult) 0x80004002L)
  146. #define NS_ERROR_NO_INTERFACE NS_NOINTERFACE
  147. #define NS_ERROR_INVALID_POINTER ((nsresult) 0x80004003L)
  148. #define NS_ERROR_NULL_POINTER NS_ERROR_INVALID_POINTER
  149. /* Returned when a function aborts */
  150. #define NS_ERROR_ABORT ((nsresult) 0x80004004L)
  151. /* Returned when a function fails */
  152. #define NS_ERROR_FAILURE ((nsresult) 0x80004005L)
  153. /* Returned when an unexpected error occurs */
  154. #define NS_ERROR_UNEXPECTED ((nsresult) 0x8000ffffL)
  155. /* Returned when a memory allocation fails */
  156. #define NS_ERROR_OUT_OF_MEMORY ((nsresult) 0x8007000eL)
  157. /* Returned when an illegal value is passed */
  158. #define NS_ERROR_ILLEGAL_VALUE ((nsresult) 0x80070057L)
  159. #define NS_ERROR_INVALID_ARG NS_ERROR_ILLEGAL_VALUE
  160. /* Returned when a class doesn't allow aggregation */
  161. #define NS_ERROR_NO_AGGREGATION ((nsresult) 0x80040110L)
  162. /* Returned when an operation can't complete due to an unavailable resource */
  163. #define NS_ERROR_NOT_AVAILABLE ((nsresult) 0x80040111L)
  164. /* Returned when a class is not registered */
  165. #define NS_ERROR_FACTORY_NOT_REGISTERED ((nsresult) 0x80040154L)
  166. /* Returned when a class cannot be registered, but may be tried again later */
  167. #define NS_ERROR_FACTORY_REGISTER_AGAIN ((nsresult) 0x80040155L)
  168. /* Returned when a dynamically loaded factory couldn't be found */
  169. #define NS_ERROR_FACTORY_NOT_LOADED ((nsresult) 0x800401f8L)
  170. /* Returned when a factory doesn't support signatures */
  171. #define NS_ERROR_FACTORY_NO_SIGNATURE_SUPPORT \
  172. (NS_ERROR_BASE + 0x101)
  173. /* Returned when a factory already is registered */
  174. #define NS_ERROR_FACTORY_EXISTS (NS_ERROR_BASE + 0x100)
  175. /* For COM compatibility reasons, we want to use exact error code numbers
  176. for NS_ERROR_PROXY_INVALID_IN_PARAMETER and NS_ERROR_PROXY_INVALID_OUT_PARAMETER.
  177. The first matches:
  178. #define RPC_E_INVALID_PARAMETER _HRESULT_TYPEDEF_(0x80010010L)
  179. Errors returning this mean that the xpcom proxy code could not create a proxy for
  180. one of the in paramaters.
  181. Because of this, we are ignoring the convention if using a base and offset for
  182. error numbers.
  183. */
  184. /* Returned when a proxy could not be create a proxy for one of the IN parameters
  185. This is returned only when the "real" meathod has NOT been invoked.
  186. */
  187. #define NS_ERROR_PROXY_INVALID_IN_PARAMETER ((nsresult) 0x80010010L)
  188. /* Returned when a proxy could not be create a proxy for one of the OUT parameters
  189. This is returned only when the "real" meathod has ALREADY been invoked.
  190. */
  191. #define NS_ERROR_PROXY_INVALID_OUT_PARAMETER ((nsresult) 0x80010011L)
  192. /*@}*/
  193. /* I/O Errors */
  194. /* Stream closed */
  195. #define NS_BASE_STREAM_CLOSED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_BASE, 2)
  196. /* Error from the operating system */
  197. #define NS_BASE_STREAM_OSERROR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_BASE, 3)
  198. /* Illegal arguments */
  199. #define NS_BASE_STREAM_ILLEGAL_ARGS NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_BASE, 4)
  200. /* For unichar streams */
  201. #define NS_BASE_STREAM_NO_CONVERTER NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_BASE, 5)
  202. /* For unichar streams */
  203. #define NS_BASE_STREAM_BAD_CONVERSION NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_BASE, 6)
  204. #define NS_BASE_STREAM_WOULD_BLOCK NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_BASE, 7)
  205. #define NS_ERROR_FILE_UNRECOGNIZED_PATH NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 1)
  206. #define NS_ERROR_FILE_UNRESOLVABLE_SYMLINK NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 2)
  207. #define NS_ERROR_FILE_EXECUTION_FAILED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 3)
  208. #define NS_ERROR_FILE_UNKNOWN_TYPE NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 4)
  209. #define NS_ERROR_FILE_DESTINATION_NOT_DIR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 5)
  210. #define NS_ERROR_FILE_TARGET_DOES_NOT_EXIST NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 6)
  211. #define NS_ERROR_FILE_COPY_OR_MOVE_FAILED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 7)
  212. #define NS_ERROR_FILE_ALREADY_EXISTS NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 8)
  213. #define NS_ERROR_FILE_INVALID_PATH NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 9)
  214. #define NS_ERROR_FILE_DISK_FULL NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 10)
  215. #define NS_ERROR_FILE_CORRUPTED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 11)
  216. #define NS_ERROR_FILE_NOT_DIRECTORY NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 12)
  217. #define NS_ERROR_FILE_IS_DIRECTORY NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 13)
  218. #define NS_ERROR_FILE_IS_LOCKED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 14)
  219. #define NS_ERROR_FILE_TOO_BIG NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 15)
  220. #define NS_ERROR_FILE_NO_DEVICE_SPACE NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 16)
  221. #define NS_ERROR_FILE_NAME_TOO_LONG NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 17)
  222. #define NS_ERROR_FILE_NOT_FOUND NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 18)
  223. #define NS_ERROR_FILE_READ_ONLY NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 19)
  224. #define NS_ERROR_FILE_DIR_NOT_EMPTY NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 20)
  225. #define NS_ERROR_FILE_ACCESS_DENIED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 21)
  226. #define NS_SUCCESS_FILE_DIRECTORY_EMPTY NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_FILES, 1)
  227. /* Result codes used by nsIDirectoryServiceProvider2 */
  228. #define NS_SUCCESS_AGGREGATE_RESULT NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_FILES, 2)
  229. /* Result codes used by nsIVariant */
  230. #define NS_ERROR_CANNOT_CONVERT_DATA NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_XPCOM, 1)
  231. #define NS_ERROR_OBJECT_IS_IMMUTABLE NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_XPCOM, 2)
  232. #define NS_ERROR_LOSS_OF_SIGNIFICANT_DATA NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_XPCOM, 3)
  233. #define NS_SUCCESS_LOSS_OF_INSIGNIFICANT_DATA NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_XPCOM, 1)
  234. /*
  235. * This will return the nsresult corresponding to the most recent NSPR failure
  236. * returned by PR_GetError.
  237. *
  238. ***********************************************************************
  239. * Do not depend on this function. It will be going away!
  240. ***********************************************************************
  241. */
  242. extern NS_COM nsresult
  243. NS_ErrorAccordingToNSPR();
  244. #ifdef _MSC_VER
  245. #pragma warning(disable: 4251) /* 'nsCOMPtr<class nsIInputStream>' needs to have dll-interface to be used by clients of class 'nsInputStream' */
  246. #pragma warning(disable: 4275) /* non dll-interface class 'nsISupports' used as base for dll-interface class 'nsIRDFNode' */
  247. #endif
  248. #endif