PageRenderTime 39ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/external/windows-pr/lib/windows/error.rb

https://github.com/wyhaines/iowa
Ruby | 313 lines | 261 code | 38 blank | 14 comment | 0 complexity | c36483a5e6df6c35f0a75cff5f9cd007 MD5 | raw file
  1. ############################################################################
  2. # error.rb
  3. #
  4. # Includes all of the error codes in error.h and some from winerror.h.
  5. #
  6. # Adds the following convenience methods:
  7. #
  8. # get_last_error - Returns a human readable string for the error returned
  9. # by the GetLastError() function.
  10. ############################################################################
  11. require 'windows/unicode'
  12. module Windows
  13. module Error
  14. FORMAT_MESSAGE_ALLOCATE_BUFFER = 0x00000100
  15. FORMAT_MESSAGE_IGNORE_INSERTS = 0x00000200
  16. FORMAT_MESSAGE_FROM_STRING = 0x00000400
  17. FORMAT_MESSAGE_FROM_HMODULE = 0x00000800
  18. FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000
  19. FORMAT_MESSAGE_ARGUMENT_ARRAY = 0x00002000
  20. FORMAT_MESSAGE_MAX_WIDTH_MASK = 0x000000FF
  21. SEM_FAILCRITICALERRORS = 0x0001
  22. SEM_NOALIGNMENTFAULTEXCEPT = 0x0004
  23. SEM_NOGPFAULTERRORBOX = 0x0002
  24. SEM_NOOPENFILEERRORBOX = 0x8000
  25. NO_ERROR = 0
  26. ERROR_SUCCESS = 0
  27. ERROR_INVALID_FUNCTION = 1
  28. ERROR_FILE_NOT_FOUND = 2
  29. ERROR_PATH_NOT_FOUND = 3
  30. ERROR_TOO_MANY_OPEN_FILES = 4
  31. ERROR_ACCESS_DENIED = 5
  32. ERROR_INVALID_HANDLE = 6
  33. ERROR_ARENA_TRASHED = 7
  34. ERROR_NOT_ENOUGH_MEMORY = 8
  35. ERROR_INVALID_BLOCK = 9
  36. ERROR_BAD_ENVIRONMENT = 10
  37. ERROR_BAD_FORMAT = 11
  38. ERROR_INVALID_ACCESS = 12
  39. ERROR_INVALID_DATA = 13
  40. ERROR_INVALID_DRIVE = 15
  41. ERROR_CURRENT_DIRECTORY = 16
  42. ERROR_NOT_SAME_DEVICE = 17
  43. ERROR_NO_MORE_FILES = 18
  44. ERROR_WRITE_PROTECT = 19
  45. ERROR_BAD_UNIT = 20
  46. ERROR_NOT_READY = 21
  47. ERROR_BAD_COMMAND = 22
  48. ERROR_CRC = 23
  49. ERROR_BAD_LENGTH = 24
  50. ERROR_SEEK = 25
  51. ERROR_NOT_DOS_DISK = 26
  52. ERROR_SECTOR_NOT_FOUND = 27
  53. ERROR_OUT_OF_PAPER = 28
  54. ERROR_WRITE_FAULT = 29
  55. ERROR_READ_FAULT = 30
  56. ERROR_GEN_FAILURE = 31
  57. ERROR_SHARING_VIOLATION = 32
  58. ERROR_LOCK_VIOLATION = 33
  59. ERROR_WRONG_DISK = 34
  60. ERROR_FCB_UNAVAILABLE = 35
  61. ERROR_SHARING_BUFFER_EXCEEDED = 36
  62. ERROR_NOT_SUPPORTED = 50
  63. ERROR_FILE_EXISTS = 80
  64. ERROR_DUP_FCB = 81
  65. ERROR_CANNOT_MAKE = 82
  66. ERROR_FAIL_I24 = 83
  67. ERROR_OUT_OF_STRUCTURES = 84
  68. ERROR_ALREADY_ASSIGNED = 85
  69. ERROR_INVALID_PASSWORD = 86
  70. ERROR_INVALID_PARAMETER = 87
  71. ERROR_NET_WRITE_FAULT = 88
  72. ERROR_NO_PROC_SLOTS = 89 # no process slots available
  73. ERROR_NOT_FROZEN = 90
  74. ERR_TSTOVFL = 91 # timer service table overflow
  75. ERR_TSTDUP = 92 # timer service table duplicate
  76. ERROR_NO_ITEMS = 93 # There were no items to operate upon
  77. ERROR_INTERRUPT = 95 # interrupted system call
  78. ERROR_TOO_MANY_SEMAPHORES = 100
  79. ERROR_EXCL_SEM_ALREADY_OWNED = 101
  80. ERROR_SEM_IS_SET = 102
  81. ERROR_TOO_MANY_SEM_REQUESTS = 103
  82. ERROR_INVALID_AT_INTERRUPT_TIME = 104
  83. ERROR_SEM_OWNER_DIED = 105 # waitsem found owner died
  84. ERROR_SEM_USER_LIMIT = 106 # too many procs have this sem
  85. ERROR_DISK_CHANGE = 107 # insert disk b into drive a
  86. ERROR_DRIVE_LOCKED = 108 # drive locked by another process
  87. ERROR_BROKEN_PIPE = 109 # write on pipe with no reader
  88. ERROR_OPEN_FAILED = 110 # open/created failed
  89. ERROR_DISK_FULL = 112 # not enough space
  90. ERROR_NO_MORE_SEARCH_HANDLES = 113 # can't allocate
  91. ERROR_INVALID_TARGET_HANDLE = 114 # handle in DOSDUPHANDLE is invalid
  92. ERROR_PROTECTION_VIOLATION = 115 # bad user virtual address
  93. ERROR_VIOKBD_REQUEST = 116
  94. ERROR_INVALID_CATEGORY = 117 # category for DEVIOCTL not defined
  95. ERROR_INVALID_VERIFY_SWITCH = 118 # invalid value
  96. ERROR_BAD_DRIVER_LEVEL = 119 # DosDevIOCTL not level four
  97. ERROR_CALL_NOT_IMPLEMENTED = 120
  98. ERROR_SEM_TIMEOUT = 121 # timeout from semaphore function
  99. ERROR_INSUFFICIENT_BUFFER = 122
  100. ERROR_INVALID_NAME = 123 # illegal char or malformed file system name
  101. ERROR_INVALID_LEVEL = 124 # unimplemented level for info retrieval
  102. ERROR_NO_VOLUME_LABEL = 125 # no volume label found
  103. ERROR_MOD_NOT_FOUND = 126 # w_getprocaddr, w_getmodhandle
  104. ERROR_PROC_NOT_FOUND = 127 # w_getprocaddr
  105. ERROR_WAIT_NO_CHILDREN = 128 # CWait finds to children
  106. ERROR_CHILD_NOT_COMPLETE = 129 # CWait children not dead yet
  107. ERROR_DIRECT_ACCESS_HANDLE = 130 # invalid for direct disk access
  108. ERROR_NEGATIVE_SEEK = 131 # tried to seek negative offset
  109. ERROR_SEEK_ON_DEVICE = 132 # tried to seek on device or pipe
  110. ERROR_IS_JOIN_TARGET = 133
  111. ERROR_IS_JOINED = 134
  112. ERROR_IS_SUBSTED = 135
  113. ERROR_NOT_JOINED = 136
  114. ERROR_NOT_SUBSTED = 137
  115. ERROR_JOIN_TO_JOIN = 138
  116. ERROR_SUBST_TO_SUBST = 139
  117. ERROR_JOIN_TO_SUBST = 140
  118. ERROR_SUBST_TO_JOIN = 141
  119. ERROR_BUSY_DRIVE = 142
  120. ERROR_SAME_DRIVE = 143
  121. ERROR_DIR_NOT_ROOT = 144
  122. ERROR_DIR_NOT_EMPTY = 145
  123. ERROR_IS_SUBST_PATH = 146
  124. ERROR_IS_JOIN_PATH = 147
  125. ERROR_PATH_BUSY = 148
  126. ERROR_IS_SUBST_TARGET = 149
  127. ERROR_SYSTEM_TRACE = 150 # system trace error
  128. ERROR_INVALID_EVENT_COUNT = 151 # DosMuxSemWait errors
  129. ERROR_TOO_MANY_MUXWAITERS = 152
  130. ERROR_INVALID_LIST_FORMAT = 153
  131. ERROR_LABEL_TOO_LONG = 154
  132. ERROR_TOO_MANY_TCBS = 155
  133. ERROR_SIGNAL_REFUSED = 156
  134. ERROR_DISCARDED = 157
  135. ERROR_NOT_LOCKED = 158
  136. ERROR_BAD_THREADID_ADDR = 159
  137. ERROR_BAD_ARGUMENTS = 160
  138. ERROR_BAD_PATHNAME = 161
  139. ERROR_SIGNAL_PENDING = 162
  140. ERROR_UNCERTAIN_MEDIA = 163
  141. ERROR_MAX_THRDS_REACHED = 164
  142. ERROR_MONITORS_NOT_SUPPORTED = 165
  143. ERROR_INVALID_SEGMENT_NUMBER = 180
  144. ERROR_INVALID_CALLGATE = 181
  145. ERROR_INVALID_ORDINAL = 182
  146. ERROR_ALREADY_EXISTS = 183
  147. ERROR_NO_CHILD_PROCESS = 184
  148. ERROR_CHILD_ALIVE_NOWAIT = 185
  149. ERROR_INVALID_FLAG_NUMBER = 186
  150. ERROR_SEM_NOT_FOUND = 187
  151. ERROR_INVALID_STARTING_CODESEG = 188
  152. ERROR_INVALID_STACKSEG = 189
  153. ERROR_INVALID_MODULETYPE = 190
  154. ERROR_INVALID_EXE_SIGNATURE = 191
  155. ERROR_EXE_MARKED_INVALID = 192
  156. ERROR_BAD_EXE_FORMAT = 193
  157. ERROR_ITERATED_DATA_EXCEEDS_64k = 194
  158. ERROR_INVALID_MINALLOCSIZE = 195
  159. ERROR_DYNLINK_FROM_INVALID_RING = 196
  160. ERROR_IOPL_NOT_ENABLED = 197
  161. ERROR_INVALID_SEGDPL = 198
  162. ERROR_AUTODATASEG_EXCEEDS_64k = 199
  163. ERROR_RING2SEG_MUST_BE_MOVABLE = 200
  164. ERROR_RELOC_CHAIN_XEEDS_SEGLIM = 201
  165. ERROR_INFLOOP_IN_RELOC_CHAIN = 202
  166. ERROR_ENVVAR_NOT_FOUND = 203
  167. ERROR_NOT_CURRENT_CTRY = 204
  168. ERROR_NO_SIGNAL_SENT = 205
  169. ERROR_FILENAME_EXCED_RANGE = 206 # if filename > 8.3
  170. ERROR_RING2_STACK_IN_USE = 207 # for FAPI
  171. ERROR_META_EXPANSION_TOO_LONG = 208 # if "*a" > 8.3
  172. ERROR_INVALID_SIGNAL_NUMBER = 209
  173. ERROR_THREAD_1_INACTIVE = 210
  174. ERROR_INFO_NOT_AVAIL = 211 #@@ PTM 5550
  175. ERROR_LOCKED = 212
  176. ERROR_BAD_DYNALINK = 213 #@@ PTM 5760
  177. ERROR_TOO_MANY_MODULES = 214
  178. ERROR_NESTING_NOT_ALLOWED = 215
  179. ERROR_MORE_DATA = 234
  180. ERROR_USER_DEFINED_BASE = 0xF000
  181. ERROR_I24_WRITE_PROTECT = 0
  182. ERROR_I24_BAD_UNIT = 1
  183. ERROR_I24_NOT_READY = 2
  184. ERROR_I24_BAD_COMMAND = 3
  185. ERROR_I24_CRC = 4
  186. ERROR_I24_BAD_LENGTH = 5
  187. ERROR_I24_SEEK = 6
  188. ERROR_I24_NOT_DOS_DISK = 7
  189. ERROR_I24_SECTOR_NOT_FOUND = 8
  190. ERROR_I24_OUT_OF_PAPER = 9
  191. ERROR_I24_WRITE_FAULT = 0x0A
  192. ERROR_I24_READ_FAULT = 0x0B
  193. ERROR_I24_GEN_FAILURE = 0x0C
  194. ERROR_I24_DISK_CHANGE = 0x0D
  195. ERROR_I24_WRONG_DISK = 0x0F
  196. ERROR_I24_UNCERTAIN_MEDIA = 0x10
  197. ERROR_I24_CHAR_CALL_INTERRUPTED = 0x11
  198. ERROR_I24_NO_MONITOR_SUPPORT = 0x12
  199. ERROR_I24_INVALID_PARAMETER = 0x13
  200. ALLOWED_FAIL = 0x0001
  201. ALLOWED_ABORT = 0x0002
  202. ALLOWED_RETRY = 0x0004
  203. ALLOWED_IGNORE = 0x0008
  204. I24_OPERATION = 0x1
  205. I24_AREA = 0x6
  206. I24_CLASS = 0x80
  207. ERRCLASS_OUTRES = 1 # Out of Resource
  208. ERRCLASS_TEMPSIT = 2 # Temporary Situation
  209. ERRCLASS_AUTH = 3 # Permission problem
  210. ERRCLASS_INTRN = 4 # Internal System Error
  211. ERRCLASS_HRDFAIL = 5 # Hardware Failure
  212. ERRCLASS_SYSFAIL = 6 # System Failure
  213. ERRCLASS_APPERR = 7 # Application Error
  214. ERRCLASS_NOTFND = 8 # Not Found
  215. ERRCLASS_BADFMT = 9 # Bad Format
  216. ERRCLASS_LOCKED = 10 # Locked
  217. ERRCLASS_MEDIA = 11 # Media Failure
  218. ERRCLASS_ALREADY = 12 # Collision with Existing Item
  219. ERRCLASS_UNK = 13 # Unknown/other
  220. ERRCLASS_CANT = 14
  221. ERRCLASS_TIME = 15
  222. ERRACT_RETRY = 1 # Retry
  223. ERRACT_DLYRET = 2 # Delay Retry, retry after pause
  224. ERRACT_USER = 3 # Ask user to regive info
  225. ERRACT_ABORT = 4 # abort with clean up
  226. ERRACT_PANIC = 5 # abort immediately
  227. ERRACT_IGNORE = 6 # ignore
  228. ERRACT_INTRET = 7 # Retry after User Intervention
  229. ERRLOC_UNK = 1 # No appropriate value
  230. ERRLOC_DISK = 2 # Random Access Mass Storage
  231. ERRLOC_NET = 3 # Network
  232. ERRLOC_SERDEV = 4 # Serial Device
  233. ERRLOC_MEM = 5 # Memory
  234. TC_NORMAL = 0
  235. TC_HARDERR = 1
  236. TC_GP_TRAP = 2
  237. TC_SIGNAL = 3
  238. # From WinError.h
  239. ERROR_INVALID_FLAGS = 4100 # 1004L
  240. ERROR_NO_UNICODE_TRANSLATION = 4371
  241. GetLastError = Win32API.new('kernel32', 'GetLastError', 'V', 'L')
  242. SetLastError = Win32API.new('kernel32', 'GetLastError', 'L', 'V')
  243. SetLastErrorEx = Win32API.new('kernel32', 'GetLastError', 'LL', 'V')
  244. SetErrorMode = Win32API.new('kernel32', 'SetErrorMode', 'I', 'I')
  245. FormatMessage = Win32API.new('kernel32', 'FormatMessage', 'LLLLPLP', 'L')
  246. FormatMessageW = Win32API.new('kernel32', 'FormatMessageW', 'LLLLPLP', 'L')
  247. def GetLastError
  248. GetLastError.call
  249. end
  250. def SetLastError(error)
  251. SetLastError.call(error)
  252. end
  253. def SetLastErrorEx(error, type=0)
  254. SetLastErrorEx.call(error, type)
  255. end
  256. def SetErrorMode(mode)
  257. SetErrorMode.call(mode)
  258. end
  259. def FormatMessage(flags, src, msg_id, lang_id, buf, size, args)
  260. FormatMessage.call(flags, src, msg_id, lang_id, buf, size, args)
  261. end
  262. def FormatMessageW(flags, src, msg_id, lang_id, buf, size, args)
  263. FormatMessageW.call(flags, src, msg_id, lang_id, buf, size, args)
  264. end
  265. # Convenience method that wraps FormatMessage with some sane defaults and
  266. # returns a human readable string.
  267. #
  268. def get_last_error(err_num = GetLastError.call)
  269. buf = 0.chr * 260
  270. flags = FORMAT_MESSAGE_FROM_SYSTEM + FORMAT_MESSAGE_ARGUMENT_ARRAY
  271. FormatMessage.call(flags, 0, err_num, 0, buf, buf.size, 0)
  272. buf.split(0.chr).first.chomp
  273. end
  274. end
  275. end