error.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. TEST_FAILED = 10
  20. COMPILATION_FAILED = 11
  21. INFRASTRUCTURE_ERROR = 12
  22. NOT_RETRIABLE_ERROR = 13
  23. YT_STORE_FETCH_ERROR = 14
  24. def merge_exit_codes(exit_codes):
  25. return max(e if e >= 0 else 1 for e in exit_codes) if exit_codes else 0
  26. def is_temporary_error(exc):
  27. import logging
  28. logger = logging.getLogger(__name__)
  29. if getattr(exc, 'temporary', False):
  30. logger.debug("Exception has temporary attribute: %s", exc)
  31. return True
  32. import errno
  33. err = getattr(exc, 'errno', None)
  34. if err == errno.ECONNREFUSED or err == errno.ENETUNREACH:
  35. logger.debug("Exception has errno attribute: %s (errno=%s)", exc, err)
  36. return True
  37. import socket
  38. if isinstance(exc, socket.timeout) or isinstance(getattr(exc, 'reason', None), socket.timeout):
  39. logger.debug("Socket timeout exception: %s", exc)
  40. return True
  41. if isinstance(exc, socket.gaierror):
  42. logger.debug("Getaddrinfo exception: %s", exc)
  43. return True
  44. import urllib2
  45. if isinstance(exc, urllib2.HTTPError) and exc.code in (429,):
  46. logger.debug("urllib2.HTTPError: %s", exc)
  47. return True
  48. import httplib
  49. if isinstance(exc, httplib.IncompleteRead):
  50. logger.debug("IncompleteRead exception: %s", exc)
  51. return True
  52. exc_str = str(exc)
  53. for message in TEMPORARY_ERROR_MESSAGES:
  54. if message in exc_str:
  55. logger.debug("Found temporary error pattern (%s): %s", message, exc_str)
  56. return True
  57. return False