prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  AttributeError: 'NoneType' object has no attribute 'errno'
  ## Long story short
  
  Trying to resolve a domain which is an alias for another one, which does not have an A or CNAME record, raises AttributeError: 'NoneType' object has no attribute 'errno'
  
  ## Expected behaviour
  
  Raise an error correctly, socket.gaierror probably.
  
  ## Actual behaviour
  
  ```Traceback (most recent call last):
    File "xtest.py", line 16, in <module>
      process()
    File "/usr/lib/python3.6/asyncio/base_events.py", line 449, in run_until_complete
      return future.result()
    File "/usr/lib/python3.6/asyncio/tasks.py", line 239, in _step
      result = coro.send(None)
    File "/myenv/lib/python3.6/site-packages/aiohttp/helpers.py", line 72, in send
      return self._coro.send(arg)
    File "/myenv/lib/python3.6/site-packages/aiohttp/client.py", line 233, in _request
      conn = yield from self._connector.connect(req)
    File "/myenv/lib/python3.6/site-packages/aiohttp/connector.py", line 378, in connect
      proto = yield from self._create_connection(req)
    File "/myenv/lib/python3.6/site-packages/aiohttp/connector.py", line 687, in _create_connection
      _, proto = yield from self._create_direct_connection(req)
    File "/myenv/lib/python3.6/site-packages/aiohttp/connector.py", line 735, in _create_direct_connection
      exc.errno,
  AttributeError: 'NoneType' object has no attribute 'errno'
  ```
  
  ## Steps to reproduce
  
  This script will reproduce the error.
  
  ```
  import asyncio
  import aiohttp
  from aiohttp.resolver import AsyncResolver
  
  def process():
      url = 'http://esly.win/'
      resolver = AsyncResolver()
      conn = aiohttp.TCPConnector(resolver=resolver, verify_ssl=False)
      session = aiohttp.ClientSession(connector=conn)
      return session.get(url)
  
  loop = asyncio.get_event_loop()
  loop.run_until_complete(
      process()
  )
  ```
  
  If I use the session without setting the connector it first raises a socket.gaierror but then 
  > During handling of the above exception, another exception occurred...
  
  And the same traceback appears.
  
  ## Your environment
  Python 3.6.0b2
  Ubuntu 10.10
  aiohttp==2.2,5 
  Also happens with aiohttp==2.3.0a0 (installed from git on 29/Aug/2017)
  
  </issue>
  <code>
  [start of aiohttp/resolver.py]
  1 import asyncio
  2 import socket
  3 
  4 from .abc import AbstractResolver
  5 
  6 
  7 __all__ = ('ThreadedResolver', 'AsyncResolver', 'DefaultResolver')
  8 
  9 try:
  10     import aiodns
  11     # aiodns_default = hasattr(aiodns.DNSResolver, 'gethostbyname')
  12 except ImportError:  # pragma: no cover
  13     aiodns = None
  14 
  15 aiodns_default = False
  16 
  17 
  18 class ThreadedResolver(AbstractResolver):
  19     """Use Executor for synchronous getaddrinfo() calls, which defaults to
  20     concurrent.futures.ThreadPoolExecutor.
  21     """
  22 
  23     def __init__(self, loop=None):
  24         if loop is None:
  25             loop = asyncio.get_event_loop()
  26         self._loop = loop
  27 
  28     @asyncio.coroutine
  29     def resolve(self, host, port=0, family=socket.AF_INET):
  30         infos = yield from self._loop.getaddrinfo(
  31             host, port, type=socket.SOCK_STREAM, family=family)
  32 
  33         hosts = []
  34         for family, _, proto, _, address in infos:
  35             hosts.append(
  36                 {'hostname': host,
  37                  'host': address[0], 'port': address[1],
  38                  'family': family, 'proto': proto,
  39                  'flags': socket.AI_NUMERICHOST})
  40 
  41         return hosts
  42 
  43     @asyncio.coroutine
  44     def close(self):
  45         pass
  46 
  47 
  48 class AsyncResolver(AbstractResolver):
  49     """Use the `aiodns` package to make asynchronous DNS lookups"""
  50 
  51     def __init__(self, loop=None, *args, **kwargs):
  52         if loop is None:
  53             loop = asyncio.get_event_loop()
  54 
  55         if aiodns is None:
  56             raise RuntimeError("Resolver requires aiodns library")
  57 
  58         self._loop = loop
  59         self._resolver = aiodns.DNSResolver(*args, loop=loop, **kwargs)
  60 
  61         if not hasattr(self._resolver, 'gethostbyname'):
  62             # aiodns 1.1 is not available, fallback to DNSResolver.query
  63             self.resolve = self.resolve_with_query
  64 
  65     @asyncio.coroutine
  66     def resolve(self, host, port=0, family=socket.AF_INET):
  67         hosts = []
  68         resp = yield from self._resolver.gethostbyname(host, family)
  69 
  70         for address in resp.addresses:
  71             hosts.append(
  72                 {'hostname': host,
  73                  'host': address, 'port': port,
  74                  'family': family, 'proto': 0,
  75                  'flags': socket.AI_NUMERICHOST})
  76         return hosts
  77 
  78     @asyncio.coroutine
  79     def resolve_with_query(self, host, port=0, family=socket.AF_INET):
  80         if family == socket.AF_INET6:
  81             qtype = 'AAAA'
  82         else:
  83             qtype = 'A'
  84 
  85         hosts = []
  86         resp = yield from self._resolver.query(host, qtype)
  87 
  88         for rr in resp:
  89             hosts.append(
  90                 {'hostname': host,
  91                  'host': rr.host, 'port': port,
  92                  'family': family, 'proto': 0,
  93                  'flags': socket.AI_NUMERICHOST})
  94 
  95         return hosts
  96 
  97     @asyncio.coroutine
  98     def close(self):
  99         return self._resolver.cancel()
  100 
  101 
  102 DefaultResolver = AsyncResolver if aiodns_default else ThreadedResolver
  103
  [end of aiohttp/resolver.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/aiohttp/resolver.py b/aiohttp/resolver.py
  --- a/aiohttp/resolver.py
  +++ b/aiohttp/resolver.py
  @@ -60,31 +60,42 @@
   
           if not hasattr(self._resolver, 'gethostbyname'):
               # aiodns 1.1 is not available, fallback to DNSResolver.query
  -            self.resolve = self.resolve_with_query
  +            self.resolve = self._resolve_with_query
   
       @asyncio.coroutine
       def resolve(self, host, port=0, family=socket.AF_INET):
  +        try:
  +            resp = yield from self._resolver.gethostbyname(host, family)
  +        except aiodns.error.DNSError as exc:
  +            msg = exc.args[1] if len(exc.args) >= 1 else "DNS lookup failed"
  +            raise OSError(msg) from exc
           hosts = []
  -        resp = yield from self._resolver.gethostbyname(host, family)
  -
           for address in resp.addresses:
               hosts.append(
                   {'hostname': host,
                    'host': address, 'port': port,
                    'family': family, 'proto': 0,
                    'flags': socket.AI_NUMERICHOST})
  +
  +        if not hosts:
  +            raise OSError("DNS lookup failed")
  +
           return hosts
   
       @asyncio.coroutine
  -    def resolve_with_query(self, host, port=0, family=socket.AF_INET):
  +    def _resolve_with_query(self, host, port=0, family=socket.AF_INET):
           if family == socket.AF_INET6:
               qtype = 'AAAA'
           else:
               qtype = 'A'
   
  -        hosts = []
  -        resp = yield from self._resolver.query(host, qtype)
  +        try:
  +            resp = yield from self._resolver.query(host, qtype)
  +        except aiodns.error.DNSError as exc:
  +            msg = exc.args[1] if len(exc.args) >= 1 else "DNS lookup failed"
  +            raise OSError(msg) from exc
   
  +        hosts = []
           for rr in resp:
               hosts.append(
                   {'hostname': host,
  @@ -92,6 +103,9 @@
                    'family': family, 'proto': 0,
                    'flags': socket.AI_NUMERICHOST})
   
  +        if not hosts:
  +            raise OSError("DNS lookup failed")
  +
           return hosts
   
       @asyncio.coroutine
  
verification_info: {"golden_diff": "diff --git a/aiohttp/resolver.py b/aiohttp/resolver.py\n--- a/aiohttp/resolver.py\n+++ b/aiohttp/resolver.py\n@@ -60,31 +60,42 @@\n \n         if not hasattr(self._resolver, 'gethostbyname'):\n             # aiodns 1.1 is not available, fallback to DNSResolver.query\n-            self.resolve = self.resolve_with_query\n+            self.resolve = self._resolve_with_query\n \n     @asyncio.coroutine\n     def resolve(self, host, port=0, family=socket.AF_INET):\n+        try:\n+            resp = yield from self._resolver.gethostbyname(host, family)\n+        except aiodns.error.DNSError as exc:\n+            msg = exc.args[1] if len(exc.args) >= 1 else \"DNS lookup failed\"\n+            raise OSError(msg) from exc\n         hosts = []\n-        resp = yield from self._resolver.gethostbyname(host, family)\n-\n         for address in resp.addresses:\n             hosts.append(\n                 {'hostname': host,\n                  'host': address, 'port': port,\n                  'family': family, 'proto': 0,\n                  'flags': socket.AI_NUMERICHOST})\n+\n+        if not hosts:\n+            raise OSError(\"DNS lookup failed\")\n+\n         return hosts\n \n     @asyncio.coroutine\n-    def resolve_with_query(self, host, port=0, family=socket.AF_INET):\n+    def _resolve_with_query(self, host, port=0, family=socket.AF_INET):\n         if family == socket.AF_INET6:\n             qtype = 'AAAA'\n         else:\n             qtype = 'A'\n \n-        hosts = []\n-        resp = yield from self._resolver.query(host, qtype)\n+        try:\n+            resp = yield from self._resolver.query(host, qtype)\n+        except aiodns.error.DNSError as exc:\n+            msg = exc.args[1] if len(exc.args) >= 1 else \"DNS lookup failed\"\n+            raise OSError(msg) from exc\n \n+        hosts = []\n         for rr in resp:\n             hosts.append(\n                 {'hostname': host,\n@@ -92,6 +103,9 @@\n                  'family': family, 'proto': 0,\n                  'flags': socket.AI_NUMERICHOST})\n \n+        if not hosts:\n+            raise OSError(\"DNS lookup failed\")\n+\n         return hosts\n \n     @asyncio.coroutine\n", "issue": "AttributeError: 'NoneType' object has no attribute 'errno'\n## Long story short\r\n\r\nTrying to resolve a domain which is an alias for another one, which does not have an A or CNAME record, raises AttributeError: 'NoneType' object has no attribute 'errno'\r\n\r\n## Expected behaviour\r\n\r\nRaise an error correctly, socket.gaierror probably.\r\n\r\n## Actual behaviour\r\n\r\n```Traceback (most recent call last):\r\n  File \"xtest.py\", line 16, in <module>\r\n    process()\r\n  File \"/usr/lib/python3.6/asyncio/base_events.py\", line 449, in run_until_complete\r\n    return future.result()\r\n  File \"/usr/lib/python3.6/asyncio/tasks.py\", line 239, in _step\r\n    result = coro.send(None)\r\n  File \"/myenv/lib/python3.6/site-packages/aiohttp/helpers.py\", line 72, in send\r\n    return self._coro.send(arg)\r\n  File \"/myenv/lib/python3.6/site-packages/aiohttp/client.py\", line 233, in _request\r\n    conn = yield from self._connector.connect(req)\r\n  File \"/myenv/lib/python3.6/site-packages/aiohttp/connector.py\", line 378, in connect\r\n    proto = yield from self._create_connection(req)\r\n  File \"/myenv/lib/python3.6/site-packages/aiohttp/connector.py\", line 687, in _create_connection\r\n    _, proto = yield from self._create_direct_connection(req)\r\n  File \"/myenv/lib/python3.6/site-packages/aiohttp/connector.py\", line 735, in _create_direct_connection\r\n    exc.errno,\r\nAttributeError: 'NoneType' object has no attribute 'errno'\r\n```\r\n\r\n## Steps to reproduce\r\n\r\nThis script will reproduce the error.\r\n\r\n```\r\nimport asyncio\r\nimport aiohttp\r\nfrom aiohttp.resolver import AsyncResolver\r\n\r\ndef process():\r\n    url = 'http://esly.win/'\r\n    resolver = AsyncResolver()\r\n    conn = aiohttp.TCPConnector(resolver=resolver, verify_ssl=False)\r\n    session = aiohttp.ClientSession(connector=conn)\r\n    return session.get(url)\r\n\r\nloop = asyncio.get_event_loop()\r\nloop.run_until_complete(\r\n    process()\r\n)\r\n```\r\n\r\nIf I use the session without setting the connector it first raises a socket.gaierror but then \r\n> During handling of the above exception, another exception occurred...\r\n\r\nAnd the same traceback appears.\r\n\r\n## Your environment\r\nPython 3.6.0b2\r\nUbuntu 10.10\r\naiohttp==2.2,5 \r\nAlso happens with aiohttp==2.3.0a0 (installed from git on 29/Aug/2017)\n", "before_files": [{"content": "import asyncio\nimport socket\n\nfrom .abc import AbstractResolver\n\n\n__all__ = ('ThreadedResolver', 'AsyncResolver', 'DefaultResolver')\n\ntry:\n    import aiodns\n    # aiodns_default = hasattr(aiodns.DNSResolver, 'gethostbyname')\nexcept ImportError:  # pragma: no cover\n    aiodns = None\n\naiodns_default = False\n\n\nclass ThreadedResolver(AbstractResolver):\n    \"\"\"Use Executor for synchronous getaddrinfo() calls, which defaults to\n    concurrent.futures.ThreadPoolExecutor.\n    \"\"\"\n\n    def __init__(self, loop=None):\n        if loop is None:\n            loop = asyncio.get_event_loop()\n        self._loop = loop\n\n    @asyncio.coroutine\n    def resolve(self, host, port=0, family=socket.AF_INET):\n        infos = yield from self._loop.getaddrinfo(\n            host, port, type=socket.SOCK_STREAM, family=family)\n\n        hosts = []\n        for family, _, proto, _, address in infos:\n            hosts.append(\n                {'hostname': host,\n                 'host': address[0], 'port': address[1],\n                 'family': family, 'proto': proto,\n                 'flags': socket.AI_NUMERICHOST})\n\n        return hosts\n\n    @asyncio.coroutine\n    def close(self):\n        pass\n\n\nclass AsyncResolver(AbstractResolver):\n    \"\"\"Use the `aiodns` package to make asynchronous DNS lookups\"\"\"\n\n    def __init__(self, loop=None, *args, **kwargs):\n        if loop is None:\n            loop = asyncio.get_event_loop()\n\n        if aiodns is None:\n            raise RuntimeError(\"Resolver requires aiodns library\")\n\n        self._loop = loop\n        self._resolver = aiodns.DNSResolver(*args, loop=loop, **kwargs)\n\n        if not hasattr(self._resolver, 'gethostbyname'):\n            # aiodns 1.1 is not available, fallback to DNSResolver.query\n            self.resolve = self.resolve_with_query\n\n    @asyncio.coroutine\n    def resolve(self, host, port=0, family=socket.AF_INET):\n        hosts = []\n        resp = yield from self._resolver.gethostbyname(host, family)\n\n        for address in resp.addresses:\n            hosts.append(\n                {'hostname': host,\n                 'host': address, 'port': port,\n                 'family': family, 'proto': 0,\n                 'flags': socket.AI_NUMERICHOST})\n        return hosts\n\n    @asyncio.coroutine\n    def resolve_with_query(self, host, port=0, family=socket.AF_INET):\n        if family == socket.AF_INET6:\n            qtype = 'AAAA'\n        else:\n            qtype = 'A'\n\n        hosts = []\n        resp = yield from self._resolver.query(host, qtype)\n\n        for rr in resp:\n            hosts.append(\n                {'hostname': host,\n                 'host': rr.host, 'port': port,\n                 'family': family, 'proto': 0,\n                 'flags': socket.AI_NUMERICHOST})\n\n        return hosts\n\n    @asyncio.coroutine\n    def close(self):\n        return self._resolver.cancel()\n\n\nDefaultResolver = AsyncResolver if aiodns_default else ThreadedResolver\n", "path": "aiohttp/resolver.py"}]}