error.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # Sync content of this file with devtools/ya/core/error/__init__.py
  2. TEMPORARY_ERROR_MESSAGES = [
  3. 'Connection reset by peer',
  4. 'Connection timed out',
  5. 'Function not implemented',
  6. 'I/O operation on closed file',
  7. 'Internal Server Error',
  8. 'Network connection closed unexpectedly',
  9. 'Network is unreachable',
  10. 'No route to host',
  11. 'No space left on device',
  12. 'Not enough space',
  13. 'Temporary failure in name resolution',
  14. 'The read operation timed out',
  15. 'timeout: timed out',
  16. ]
  17. # Node exit codes
  18. class ExitCodes(object):
  19. GENERIC_ERROR = 1
  20. # 2 is reserved not to be confused with bash's exit code
  21. # For more info see https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
  22. _ = 2
  23. UNHANDLED_EXCEPTION = 3
  24. CONFIGURE_ERROR = 8
  25. NO_TESTS_COLLECTED = 9
  26. TEST_FAILED = 10
  27. INFRASTRUCTURE_ERROR = 12
  28. NOT_RETRIABLE_ERROR = 13
  29. YT_STORE_FETCH_ERROR = 14
  30. def merge_exit_codes(exit_codes):
  31. return max(e if e >= 0 else 1 for e in exit_codes) if exit_codes else 0
  32. def is_temporary_error(exc):
  33. import logging
  34. logger = logging.getLogger(__name__)
  35. if getattr(exc, 'temporary', False):
  36. logger.debug("Exception has temporary attribute: %s", exc)
  37. return True
  38. import errno
  39. err = getattr(exc, 'errno', None)
  40. if err == errno.ECONNREFUSED or err == errno.ENETUNREACH:
  41. logger.debug("Exception has errno attribute: %s (errno=%s)", exc, err)
  42. return True
  43. import socket
  44. if isinstance(exc, socket.timeout) or isinstance(getattr(exc, 'reason', None), socket.timeout):
  45. logger.debug("Socket timeout exception: %s", exc)
  46. return True
  47. if isinstance(exc, socket.gaierror):
  48. logger.debug("Getaddrinfo exception: %s", exc)
  49. return True
  50. import urllib2
  51. if isinstance(exc, urllib2.HTTPError) and exc.code in (429,):
  52. logger.debug("urllib2.HTTPError: %s", exc)
  53. return True
  54. import httplib
  55. if isinstance(exc, httplib.IncompleteRead):
  56. logger.debug("IncompleteRead exception: %s", exc)
  57. return True
  58. exc_str = str(exc)
  59. for message in TEMPORARY_ERROR_MESSAGES:
  60. if message in exc_str:
  61. logger.debug("Found temporary error pattern (%s): %s", message, exc_str)
  62. return True
  63. return False